Python Scripting Interface (API)¶
Module lmtslr¶
Logging Framework for lmtslr TODO: Simple test cases
Another way¶
- class lmtslr.spec.spec.RoachSpec(obsnum, roach_id, roach_input, nchan, bandwidth, nspec, raw_spec, spec_time, xmap, ymap, azmap, elmap, ramap, decmap, lmap, bmap, pmap, gmap, bufpos)[source]¶
Base class to deal with a single time series of spectra.
Methods
LineStatistics
(parent, v, spectrum, ...[, ...])Class to handle line statistics.
baseline
(spectrum, baseline_list, ...[, ...])Computes a baseline given a spectrum, using a list of channels. Args: spectrum (array): array of spectrum data baseline_list (list): list of channels to use n_baseline_list (int): number of channels baseline_order (int): order of fitting function (default is 0) Returns: (baseline (array), rms (array)): baseline is the array of computed baseline values, rms is the array of root- mean-square error.
compute_main_spectra
()Computes the average main (on) spectrum for each block of on- source observations, which are returned as a list. Args: none Returns: none.
compute_main_spectrum
()Computes the average main spectrum using all main (on) observations. Args: none Returns: none.
compute_median_spectrum
()Computes the median spectrum from ALL spectra in the file. Args: none Returns: none.
compute_reference_spectra
()Computes the average reference spectrum for each block of refs, which are returned as a list. Args: none Returns: none.
compute_reference_spectrum
()Computes the average reference spectrum using all ref observations. Args: none Returns: none.
compute_tsys_spectra
([bdrop, edrop])Computes the TSYS, typically for an otf_cal=1
compute_tsys_spectrum
([bdrop, edrop])Computes a system temperature spectrum and average value of tsys. Args: bdrop (int): number of channels excluded from beginning of spectrum edrop (int): number of channels excluded from end of spectrum Returns: none.
get_nearest_reference
(index[, left])Given a dump index and if it is to the left of ONs (default) or right of ONs returns the correct reference index
get_previous_hot
(index[, nearest])Given a dump index finds the previous HOT and returns the correct hot index
get_ranges
([value])Searches bufpos and finds indices with values corresponding to value. Args: value (int): type of observation for search. 0 is ons ("ON") 1 is refs ("OFF") 2 is sky 3 is hot Returns: (idx (list), ranges (list), len(ranges) (int)): idx is the indices, ranges is the list of (begin,end), len(ranges) is the length of ranges.
integrate_spectra
(channel_list, ...[, ...])Computes the integral of the spectrum over some range of channels (channel_list) with baseline removed using baseline_list. Args: channel_list (list): list of channels to use n_channel_list (int): number of channels to use baseline_list (list): list of baselines to use n_baseline_list (int): number of baselines to use baseline_order (int): order of fitting function (default is 0) type (int): type of integration to use. 0 is YINT and 1 is YMAX. Returns: np.array(spectra) (array): array of integrated spectra data.
integrate_spectrum
(on_list, channel_list, ...)Averages reduced spectra over list of indices (on_list) and then computes the integral of the spectrum over some range of channels (channel_list) with baseline removed using baseline_list. Args: on_list (list): list of indices to use channel_list (list): list of channels to use n_channel_list (int): number of channels to use baseline_list (list): list of baselines to use n_baseline_list (int): number of baselines to use baseline_order (int): order of fitting function (default is 0) type (int): type of integration to use. 0 is YINT and 1 is YMAX. Returns: (baselined_spectrum (array), result (float)): baselined_spectrum is the spectrum with baseline subtracted, result is the integrated spectrum.
reduce_on_spectrum
([calibrate, ...])Creates a ON spectrum returned as self.on_spectrum. Reduction procedure depends on the stype parameter. Args: calibrate (bool): True when we want to calibrate the ps_spectrum (default is False) tsys_spectrum (float): tsys values for the calibration used when calibrate=True (default is 0) tsys_no_cal (float): tsys value for the calibration used when calibrate=False (default is 1).
reduce_ps_spectrum
([stype, normal_ps, ...])Creates a PS spectrum returned as self.ps_spectrum. Reduction procedure depends on the stype parameter. Args: stype (int): type of reduction to run (default is 2) 0: not defined 1: compute average of all refs and mains and take the difference 2: compute individual on's and off's in blocks; difference each pair and average differences normal_ps (bool): True for (Main-Ref)/Ref False for (Ref-Main)/Main (beam switch) (default is True) calibrate (bool): option to calibrate ps_spectrum (default is False) tsys_spectrum (array): spectrum of tsys values for calibration when calibrate=True tsys_no_cal (array): spectrum of tsys values for calibration when calibrate=False Returns: none.
reduce_spectra
([stype, calibrate, ...])Creates a list of all the "on" spectra in the file. The on spectra are reduced according to the value of "type". Args: stype (int): type of reduction to run (default is 0) 0: use the median spectrum for the whole thing 1: use a single reference spectra which is average of all refs 2: use the average of refs which bracket the ons 3: use weighted average of refs which bracket the ons calibrate (bool): option to calibrate ps_spectrum (default is False) tsys_spectrum (float): tsys value for calibration when calibrate=True tsys_no_cal (float): tsys value for calibration when calibrate=False use_otf_cal (bool): option to use in-scan hot and sky to derive cals (default is False) Returns: none.
- class lmtslr.spec.spec.SpecBank(roach_files, ifproc_data, pixel_list=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], time_offset=[-0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03], bank=0, restfreq=-1, save_tsys=False)[source]¶
Base class for dealing with a complete “bank” of spectra.
Methods
c2v
(c)Converts a channel number into a velocity. Args: c (int or array): channel number(s) Returns: v (float or array): velocity(ies) corresponding to channel in units of .
create_velocity_scale
()Computes the velocity scale corresponding to the channels in the spectrum. Args: none Returns: self.c2v(range(self.nchan)) (array): velocity scale corresponding to channels.
find_map_pixel_index
(ipixel)Looks up the index in our map of spectra corresponding to a specific pixel. Args: ipixel (int): index of pixel Returns: (int(index[0]) (int)) if len(index[0]) else 0: index of pixel in map. If not found, returns 0.
find_pixel_index
(ipixel)Looks up the index in our array of spectra corresponding to a specific pixel. Args: ipixel (int): index of pixel Returns: (int(index[0]) (int)) if len(index[0]) else 0: index of pixel in spectra. If not found, returns 0.
make_channel_list
(regions)Creates a list of channels given a list of lists of intervals to be processed. for example: regions = [[1,3],[5,8]] creates [1,2,3,5,6,7,8] Args: regions (list): list of lists of intervals to be processed Returns: (channel_list (list), nchannels (int)): channel_list is the list of channels, nchannels is the number of channels.
make_pixel_id_list
(roach_files, pixel_list)Creates a list of pixel id numbers corresponding to list of roach spectra that is created. Args: roach files (list): list of files for ROACH boards (nominally 4) pixel_list (list): list of pixels to process Returns: np.array(l (list)): l is the list of pixel ids.
make_velocity_list
(velocity_regions[, id])Creates a channel list from a set of velocity intervals. Args: velocity_regions (list): set of velocity intervals. id (str): type of line 'line' designates line (default) 'baseline' designates baseline Returns: (channel_list (list), nchannels (int)): channel_list is the list of channels, nchannels is the number of channels.
read_roach
(filename, roach_id, pixel_list[, ...])Reads a roach file and creates spectrum (roach class) for each input. Args: filename (str): name of the roach file roach_id (int): number of the roach. e.g. roach0 would be 0 pixel_list (list): list of pixels we want to process as_float (bool): if True, uses float instead of double. [data before 2021/22 was in double, but we convert to float to save memory. Starting in 2021 raw data was saved in float as well].
v2c
(v)Converts velocity into channel number. Args: v (float): velocity in units of Returns: c (array): array of channel numbers corresponding to velocity.
- class lmtslr.spec.spec.SpecBankData(roach_files, ifproc_data, pixel_list=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], time_offset=[-0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03], bank=0, restfreq=-1, save_tsys=False)[source]¶
Base class to deal with a complete “bank” of spectra.
Methods
c2v
(c)Converts a channel number into a velocity. Args: c (int or array): channel number(s) Returns: v (float or array): velocity(ies) corresponding to channel in units of .
create_grid
()Creates the map grid from map parameters. Args: none Returns: none.
create_map_data
(channel_list, ...[, ...])Processes a list of pixel ids to make a set of integrated spectra for mapping (and fitting). Args: channel_list (list): list of channels to use n_channel_list (int): number of channels to use baseline_list (list): list of baselines to use n_baseline_list (int): number of baselines to use baseline_order (int): order of fitting function (default is 0) pixel_list (list): list of pixels to process (default is all) type (int): type of integration to use. 0 is YINT and 1 is YMAX. Returns: none.
create_map_grid_bufpos_from_grid
(xgrid, ...)Processes a list of pixel ids to make a set of bufpos grids for mapping (and fitting). Args: xgrid (array): ygrid (array): tole (): channel_list (list): list of channels to use n_channel_list (int): number of channels to use baseline_list (list): list of baselines to use n_baseline_list (int): number of baselines to use baseline_order (int): order of fitting function (default is 0) pixel_list (list): list of pixels to process (default is all) type (int): type of integration to use. 0 is YINT and 1 is YMAX. Returns: none.
create_map_grid_data
(channel_list, ...[, ...])Processes a list of pixel ids to make a set of grid data for mapping (and fitting). Args: channel_list (list): list of channels to use n_channel_list (int): number of channels to use baseline_list (list): list of baselines to use n_baseline_list (int): number of baselines to use baseline_order (int): order of fitting function (default is 0) pixel_list (list): list of pixels to process (default is all) type (int): type of integration to use. 0 is YINT and 1 is YMAX. Returns: none.
create_map_grid_data_from_grid
(xgrid, ygrid, ...)Processes a list of pixel ids to make a set of grid data for mapping (and fitting). Args: xgrid (array): ygrid (array): tole (): channel_list (list): list of channels to use n_channel_list (int): number of channels to use baseline_list (list): list of baselines to use n_baseline_list (int): number of baselines to use baseline_order (int): order of fitting function (default is 0) pixel_list (list): list of pixels to process (default is all) type (int): type of integration to use. 0 is YINT and 1 is YMAX. Returns: none.
create_velocity_scale
()Computes the velocity scale corresponding to the channels in the spectrum. Args: none Returns: self.c2v(range(self.nchan)) (array): velocity scale corresponding to channels.
find_grid_location
(ix, iy)Returns grid location of grid point ix, iy. Args: ix (int): x index iy (int): y index Returns: self.xgrid[ix] (): x location self.ygrid[iy] (): y location.
find_grid_point_id
(ix, iy)Returns bufpos number of grid point ix, iy. Args: ix (int): x index iy (int): y index Returns: index (float) + 100: index is the bufpos number before offset is added.
find_map_pixel_index
(ipixel)Looks up the index in our map of spectra corresponding to a specific pixel. Args: ipixel (int): index of pixel Returns: (int(index[0]) (int)) if len(index[0]) else 0: index of pixel in map. If not found, returns 0.
find_pixel_index
(ipixel)Looks up the index in our array of spectra corresponding to a specific pixel. Args: ipixel (int): index of pixel Returns: (int(index[0]) (int)) if len(index[0]) else 0: index of pixel in spectra. If not found, returns 0.
make_channel_list
(regions)Creates a list of channels given a list of lists of intervals to be processed. for example: regions = [[1,3],[5,8]] creates [1,2,3,5,6,7,8] Args: regions (list): list of lists of intervals to be processed Returns: (channel_list (list), nchannels (int)): channel_list is the list of channels, nchannels is the number of channels.
make_pixel_id_list
(roach_files, pixel_list)Creates a list of pixel id numbers corresponding to list of roach spectra that is created. Args: roach files (list): list of files for ROACH boards (nominally 4) pixel_list (list): list of pixels to process Returns: np.array(l (list)): l is the list of pixel ids.
make_velocity_list
(velocity_regions[, id])Creates a channel list from a set of velocity intervals. Args: velocity_regions (list): set of velocity intervals. id (str): type of line 'line' designates line (default) 'baseline' designates baseline Returns: (channel_list (list), nchannels (int)): channel_list is the list of channels, nchannels is the number of channels.
read_roach
(filename, roach_id, pixel_list[, ...])Reads a roach file and creates spectrum (roach class) for each input. Args: filename (str): name of the roach file roach_id (int): number of the roach. e.g. roach0 would be 0 pixel_list (list): list of pixels we want to process as_float (bool): if True, uses float instead of double. [data before 2021/22 was in double, but we convert to float to save memory. Starting in 2021 raw data was saved in float as well].
v2c
(v)Converts velocity into channel number. Args: v (float): velocity in units of Returns: c (array): array of channel numbers corresponding to velocity.