Data tool modules

Filterbank Reader

class arts_localisation.data_tools.filterbank_reader.ARTSFilterbankReader(fname, cb, ntab=12, median_filter=True)

Bases: object

Filterbank reader for ARTS data, one file per TAB

Parameters:
  • fname (str) – path to filterbank files, with {cb:02d} and {tab:02d} for CB and TAB indices

  • cb (int) – CB index

  • ntab (int) – Number of TABs (Default: NTAB from constants)

  • median_filter (bool) – Enable median removal (Default: True)

get_fil_params(tab=0)

Read filterbank parameters

Parameters:

tab (int) – TAB index (Default: 0)

Returns:

nfreq (int), freqs (array), nsamp (int), tsamp (float)

get_sb(sb)

Construct an SB. TAB data must be read before calling this method

Parameters:

sb (int) – SB index

Returns:

Spectra object with SB data

load_single_sb(sb, startbin, chunksize)

Convenience tool to read only a single SB and its associated TABs. Note: Any internal TAB data is cleared after calling this method

Parameters:
  • sb (int) – SB index

  • startbin (int) – Index of first time sample to read

  • chunksize (int) – Number of time samples to read

Returns:

Spectra object with SB data

read_filterbank(tab, startbin, chunksize)

Read a chunk of filterbank data

Parameters:
  • tab (int) – TAB index

  • startbin (int) – Index of first time sample to read

  • chunksize (int) – Number of time samples to read

Returns:

chunk of data with shape (nfreq, chunksize)

read_tabs(startbin, chunksize, tabs=None)

Read TAB data

Parameters:
  • startbin (int) – Index of first time sample to read

  • chunksize (int) – Number of time samples to read

  • tabs (list) – which TABs to read (Default: all)

exception arts_localisation.data_tools.filterbank_reader.ARTSFilterbankReaderError

Bases: Exception

S/N calculation

arts_localisation.data_tools.snr_tools.calc_snr_amber(data, thresh=3)

Calculate peak S/N using the same method as AMBER: Outliers are removed four times before calculating the S/N as peak - median / sigma The result is scaled by 1.048 to account for the removed values

Parameters:
  • data (array) – timeseries data

  • thresh (float) – sigma threshold for outliers (Default: 3)

Returns:

peak S/N

arts_localisation.data_tools.snr_tools.calc_snr_matched_filter(data, widths=None)

Calculate S/N using several matched filter widths, then pick the highest S/N

Parameters:
  • data (array) – timeseries data

  • widths (list) – matched filters widhts to try (Default: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500])

Returns:

highest S/N (float), corresponding matched filter width (int)

Spectra

class arts_localisation.data_tools.spectra.Spectra(freqs, dt, data, starttime=0, dm=0)

Bases: object

A class to store spectra. This is mainly to provide reusable functionality.

Spectra constructor

Parameters:
  • freqs (list) – Observing frequencies for each channel.

  • dt (float) – Sampling time (seconds)

  • data (array) – A 2D numpy array containing pulsar data. Axis 0 should contain channels. (e.g. data[0,:]) Axis 1 should contain spectra. (e.g. data[:,0])

  • starttime (float) – Start time (in seconds) of the spectra with respect to the start of the observation. (Default: 0).

  • dm (float) – Dispersion measure (in pc/cm^3). (Default: 0)

Returns:

Spectra object

dedisperse(dm=0, padval=0)

Shift channels according to the delays predicted by the given DM. * Dedispersion happens in place *

Parameters:
  • dm (float) – The DM (in pc/cm^3) to use.

  • padval (float/str) – The padding value to use when shifting channels during dedispersion. See documentation of Spectra.shift_channels. (Default: 0)

downsample(factor=1, trim=True)

Downsample the spectra by co-adding ‘factor’ adjacent bins. * Downsampling is done in place *

Parameters:
  • factor (int) – Reduce the number of spectra by this factor. Must be a factor of the number of spectra if ‘trim’ is False.

  • trim (bool) – Trim off excess bins.

get_chan(channum)
get_spectrum(specnum)
masked(mask, maskval='median-mid80')

Replace masked data with ‘maskval’. Returns a masked copy of the Spectra object.

Parameters:
  • mask (array) – An array of boolean values of the same size and shape as self.data. True represents an entry to be masked.

  • maskval (str) –

    Value to use when masking. This can be a numeric value, ‘median’, ‘mean’, or ‘median-mid80’.

    The values ‘median’ and ‘mean’ refer to the median and mean of the channel, respectively. The value ‘median-mid80’ refers to the median of the channel after the top and bottom 10% of the sorted channel is removed. (Default: ‘median-mid80’)

Returns:

maskedspec: A masked version of the Spectra object.

scaled(indep=False)

Return a scaled version of the Spectra object. When scaling subtract the median from each channel, and divide by global std deviation (if indep==False), or divide by std deviation of each row (if indep==True).

Parameters:

indep (bool) – If True, scale each row independently (Default: False).

Returns:

scaled_spectra: A scaled version of the Spectra object.

scaled2(indep=False)

Return a scaled version of the Spectra object. When scaling subtract the min from each channel, and divide by global max (if indep==False), or divide by max of each row (if indep==True).

Parameters:

indep (bool) – If True, scale each row independently (Default: False).

Returns:

scaled_spectra: A scaled version of the Spectra object.

shift_channels(bins, padval=0)

Shift each channel to the left by the corresponding value in bins, an array. * Shifting happens in-place *

Parameters:
  • bins (array) – An array containing the number of bins to shift each channel by.

  • padval (float/str) –

    Value to use when shifting near the edge of a channel. This can be a numeric value, ‘median’, ‘mean’, or ‘rotate’.

    The values ‘median’ and ‘mean’ refer to the median and mean of the channel. The value ‘rotate’ takes values from one end of the channel and shifts them to the other.

smooth(width=1, padval=0)

Smooth each channel by convolving with a top hat of given width. The height of the top had is chosen shuch that RMS=1 after smoothing. Overlap values are determined by ‘padval’. This bit of code is taken from Scott Ransom’s PRESTO’s single_pulse_search.py (line ~ 423). * Smoothing is done in place. *

Parameters:
  • width (int) – Number of bins to smooth by (Default: no smoothing)

  • padval (float/str) – Padding value to use. Possible values are float-value, ‘mean’, ‘median’, ‘wrap’. (Default: 0).

subband(nsub, subdm=None, padval=0)

Reduce the number of channels to ‘nsub’ by subbanding. The channels within a subband are combined using the DM ‘subdm’. ‘padval’ is passed to the call to ‘Spectra.shift_channels’. * Subbanding happens in-place *

Parameters:
  • nsub (int) – Number of subbands. Must be a factor of the number of channels.

  • subdm (float) – The DM with which to combine channels within each subband (Default: don’t shift channels within each subband)

  • padval (float/str) – The padding value to use when shifting channels during dedispersion. See documentation of Spectra.shift_channels. (Default: 0)

trim(bins=0)

Trim the end of the data by ‘bins’ spectra. * Trimming is done in place *

Parameters:

bins (int) – Number of spectra to trim off the end of the observation. If bins is negative trim spectra off the beginning of the observation.

arts_localisation.data_tools.spectra.delay_from_DM(DM, freq_emitted)

Return the delay in seconds caused by dispersion, given a Dispersion Measure in cm-3 pc, and the emitted frequency of the pulsar in MHz.

Parameters:
  • DM (float) – dispersion measure

  • freq_emitted (float) – frequency

arts_localisation.data_tools.spectra.rotate(arr, bins)

Return an array rotated by ‘bins’ places to the left

Parameters:
  • arr (list) – Input data

  • bins (int) – Number of bins to rotate by