pyspectools.mmw package

Submodules

pyspectools.mmw.fft_routines module

pyspectools.mmw.fft_routines.butter_filter(data, cutoff, fs, filter_type, order=5)[source]
pyspectools.mmw.fft_routines.fft_filter(ydata, window_function=None, cutoff=[50, 690], sample_rate=None)[source]

Fourier filter implementation.

Takes signal data in the frequency domain, and transforms into the time domain where slices are taken off.

Various window functions can be applied, including stock and custom filters that I have implemented. One in particular is the house filter, which is considered the “gold standard”.

pyspectools.mmw.fft_routines.gen_butter_filter(cutoff: numpy.ndarray, filter_type, order=5)[source]

[summary]

Parameters
  • cutoff ([type]) – [description]

  • fs ([type]) – [description]

  • filter_type ([type]) – [description]

  • order (int, optional) – [description], by default 5

Returns

[description]

Return type

[type]

pyspectools.mmw.fft_routines.house_filter(size, low, high)[source]

Function that returns the “gold standard” filter.

This window is designed to produce low sidelobes for Fourier filters.

In essence it resembles a sigmoid function that smoothly goes between zero and one, from short to long time.

pyspectools.mmw.interpolation module

pyspectools.mmw.interpolation.calc_shep_interp(dataframes, xnew, col='Intensity', xrange=10.0, p=4.0, threshold=1.0, npoints=15)[source]

Main function for calculating the Shepard interpolation for a given set of existing data, and an array corresponding to the new set of x data.

dataframes - a list comprising pandas DataFrames, containing x/y data with column names [“Frequency”, “Intensity”] xnew - the new x values to interpolate into. Use np.arange/np.linspace to generate. xrange - the frequency radius (in units of whatever frequency units are in data) to search for neighbours. Also defines the rate at which the neighbourlist is updated. p - the decay rate of the inverse distance weighting; should be even values. threshold - minimum weight value to be considered in the interpolation npoints - the maximum number of data points to use in the interpolation; smaller numbers mean crappy interpolation, larger means expensive.

Returns the new y values

pyspectools.mmw.interpolation.find_nearest(dataframes, x, npoints=5)[source]

Function that will take a list of dataframes, and return slices of the dataframes containing a specified number of closest points.

pyspectools.mmw.interpolation.find_nearest_nieu(dataframes, x, xrange=3.0, npoints=5)[source]

New function that will return only data that is within a specified range, and within that the closest values.

pyspectools.mmw.interpolation.idw(x, xn, p=6, threshold=1.0)[source]

Inverse-distance weighting function For a given value of x with known data, and the interpolating x (xn), return the weighting value.

pyspectools.mmw.interpolation.shep_interp(dataframes, xn, col='Intensity', p=6, threshold=1.0)[source]

Calculate the Shepard interpolation of a point

pyspectools.mmw.interpolation.vidw(x, xn, p=6, threshold=1.0)[source]

Vectorized form of the inverse-distance weighting function

pyspectools.mmw.mmw_analysis module

pyspectools.mmw.mmw_analysis.batch_interpolate(files, datapoints=50000, zeeman_on=None, window_function=None, pass_filter=None)[source]

Function for batch processing multiple scan files, and concetanates them together to generate a single, interactive spectrum.

Takes input argument files as a list of filepaths corresponding to scans that are (generally) without Zeeman. The optional argument, zeeman_on, is a list of filepaths corresponding to scans with Zeeman on.

All of the scans will be processed with the same window functions and cut offs, so be sure to optimize them before batch processing.

Returns a dataframe with up to three columns: Zeeman off/on, and off - on.

pyspectools.mmw.mmw_analysis.batch_plot(files, window_function=None, pass_filter=None)[source]
pyspectools.mmw.mmw_analysis.batch_shepard(files, stepsize=0.1, xrange=10.0, p=4.0, threshold=0.1, npoints=15, window_function=None, pass_filter=None)[source]

Routine for performing mass interpolation using Shepard’s interpolation method on mmw data. Input is a list of files, and parameters used to interpolate and to filter the data.

Stepsize is given in units of MHz.

pyspectools.mmw.mmw_analysis.cross_correlate_lorentzian(signal: numpy.ndarray, window_size=25, **kwargs)[source]

Calculate the cross-correlation spectrum between an input signal and the second derivative lineshape of a Lorentzian function. This is a matched filter analysis to extract optimal signal to noise for millimeter-wave data.

Parameters
  • signal (np.ndarray) – NumPy 1D array containing the raw signal.

  • window_size (int) – Size of the window function.

Returns

NumPy 1D array containing the cross-correlation spectrum.

Return type

corr_signal

pyspectools.mmw.mmw_analysis.fit_lines(dataframe, frequencies, name, window_length=10.0, ycol='Field off', off_dataframe=None)[source]

Wrapper for the fit_chunk function, for when you want to try and fit many lines in a catalog.

The input arguments are the survey dataframe, a list of center frequencies you want to try and fit, the name of the species. Optional argument is the name of column you want to use for the intensities.

The function will iterate through each center frequency and try to fit it.

pyspectools.mmw.mmw_analysis.fit_spectrum_chunk(dataframe: pandas.core.frame.DataFrame, freq_range: List[float], frequencies: numpy.ndarray, **kwargs)[source]

Automates the fitting of multiple frequencies to a single spectrum.

Parameters
  • dataframe (pd.DataFrame) – Pandas DataFrame containing the millimeter-wave spectrum.

  • freq_range (2-tuple) – Iterable with two floats, corresponding to the limits of the spectrum (in frequency) we want to consider for the fit.

  • frequencies (np.ndarray) – NumPy 1D array containing center frequencies to fit.

Returns

[description]

Return type

[type]

pyspectools.mmw.mmw_analysis.interp_mmw(files, nelements=10000, window_function=None, cutoff=None)[source]

Function that will process archival millimeter-wave data by providing a list of filepaths.

The function will parse the data out of each file, and produce a plot that is stitched together.

The first step is to read in all the data, and append the parsed data into full_freq and full_int, corresponding to the experimental frequency and intensities. This is used to then determine the limits to the x axis for plotting.

pyspectools.mmw.mmw_analysis.open_mmw(filepath, **kwargs)[source]

Function for opening and processing a single millimeter wave data file.

Returns a pandas dataframe containing Frequency and Intensity information.

pyspectools.mmw.mmw_analysis.parse_data(filepath)[source]

Function for parsing data from a millimeter-wave data file.

pyspectools.mmw.mmw_analysis.sec_deriv_peak_detection(df_group, threshold=5, window_size=25, magnet_thres=0.5, **kwargs)[source]

Function designed to take advantage of split-combine-apply techniques to analyze concatenated spectra, or a single spectrum. The spectrum is cross-correlated with a window corresponding to a second-derivative Lorentzian line shape, with the parameters corresponding to the actual downward facing peak such that the cross-correlation is upwards facing for a match.

This X-correlation analysis is only done for the Field OFF data; every peak should appear in the Field OFF, and should disappear under the presence of a magnetic field. If the Field ON spectrum is non-zero, the peak finding is followed up by calculating the ratio of the intensity at the same position for ON/OFF; if the ratio is below a threshold, we consider it a magnetic line.

Parameters
  • df_group (pandas DataFrame) – Dataframe containing the millimeter-wave spectra.

  • threshold (int, optional) – Absolute intensity units threshold for peak detection. This value corresponds to the value used in the X-correlation spectrum, by default 5

  • window_size (int, optional) – Size of the second derivative Lorentizan window function, by default 25

  • magnet_thres (float, optional) – Threshold for determining if a peak is magnetic, given as the ratio of ON/OFF. A value of 1 means the line is nominally unaffected by a magnetic field, and less than 1 corresponds to larger responses to magnetic fields. By default 0.5

Returns

DataFrame holding the detected peaks and their associated magnet tests, if applicable.

Return type

pandas DataFrame

pyspectools.mmw.mmw_analysis.test_filtering(path: str, **kwargs)[source]

Convenience function to open a legacy data file and process it; kwargs are passed to the fft_filter function call. The function then returns a Matplotlib figure and axis object, showing the FFT filtered spectrum and the time-domain signal chunk that it corresponds to.

Parameters

path (str) – Filepath to the data file.

Returns

Matplotlib figure/axis objects.

Return type

fig, ax

pyspectools.mmw.plotting_func module

pyspectools.mmw.plotting_func.id_survey(frequency, intensity, catdict)[source]

Function for plotting predicted lines as stick spectra on top of a broadband survey spectrum.

Frequency and intensity are 1D arrays of the spectrum frequency and intensity.

catdict is a dictionary with keys corresponding to the name of the molecule, and values corresponding to dataframes of the parsed .cat file.

pyspectools.mmw.plotting_func.plot_spectrum(dataframe)[source]

Function used to plot a dataframe using Plotly.

Uses colorlover to generate palettes.

Args: dataframe - pandas dataframe containing a frequency column. Every other column is treated as an intensity column

pyspectools.mmw.plotting_func.save_plot(fig, filename)[source]
pyspectools.mmw.plotting_func.static_comparison(frequencies, sample_on_df, sample_off_df, window_size=0.0001)[source]

Method for plotting the sample on-off spectra side-by-side. Takes a list of frequencies, which will be

Module contents