pyspecProcScripts package

Submodules

pyspecProcScripts.CPMG_phasing module

pyspecProcScripts.CPMG_phasing.center_echo(s, echo_center, axis='t2', fl=None)

Centers data around echo center given, and applies a zeroth order phase correction.

Will generate an error if the echo appears to be extremely lopsided.

Parameters:
  • echo_center (float) – center of echo

  • axis (str) – axis along which the echo is being centered

pyspecProcScripts.CPMG_phasing.minimize_CPMG_imag(s, axis='t2', fl=None)

optimize the first and second order phase of a CPMG pulse sequence by minimizing the energy of its imaginary component

pyspecProcScripts.DCCT_func module

pyspecProcScripts.DCCT_func.DCCT(this_nddata, this_fig_obj, custom_scaling=False, grid_bottom=0.0, bottom_pad=0.15, grid_top=1.0, top_pad=0.1, total_spacing=0.055, label_spacing_multiplier=50, allow_for_text_default=10, allow_for_ticks_default=70, text_height=40, LHS_pad=0.01, RHS_pad=0.05, shareaxis=False, cmap=None, pass_frq_slice=False, just_2D=False, scaling_factor=1, max_coh_jump={'ph1': 2, 'ph2': 1}, direct='t2', plot_title='DCCT', **kwargs)

DCCT plot

Parameters:
  • this_nddata (psd.nddata) – data being plotted

  • thi_fig_obj (figure) – size/type of figure to be plotted on

  • custom_scaling (boolean) – allows user to scale the intensity of data presented

  • grid_bottom (float) – coordinate for bottom of DCCT plot

  • bottom_pad (float) – distance between bottom of grid and bottom of figure

  • grid_top (float) – coordinate top of grid in figure

  • top_pad (float) – distance between top of figure and top of grid

  • total_spacing (float) – affects spacing between phase cycle dimensions

  • label_spacing_multiplier (int) – spacing between axes labels

  • allow_for_text_default (int) – adjusts distance between tick labels and ticks

  • allow_for_ticks_default (int) – adjusts distance between ticks

  • text_height (int) – adjusts sizing of axis labels and tick labels

  • LHS_pad (float) – adjusts padding on left hand side of DCCT plot

  • RHS_pad (float) – adjusts padding on right hand side of DCCT plot

  • shareaxis (boolean) – subplots scale together, but currently, this means there must be tick labels on both top and bottom

  • cmap (str) – string for color mapping if specified

  • pass_frq_slice (boolean) – if true will show the frequency sliced out with hatching

  • just_2D (boolean) – If true will only return axis coordinates/shape NOT ax_list

  • scaling_factor (float) – If using custom scaling this allows user to set the scaling factor

  • max_coh_jump (dict) – maximum allowed transitions for each phase cycle

  • direct (str) – name of direct axis

  • plot_title (str) – title for DCCT plot

pyspecProcScripts.Utility module

These are simple utility functions

pyspecProcScripts.Utility.Vpp2power(Vpp, Z=50.0)

convert peak to peak voltage to power

pyspecProcScripts.Utility.dBm2power(dBm)

convert from dBm to W

pyspecProcScripts.Utility.power2dBm(power)

convert from W to dBm

pyspecProcScripts.apod_matched_filter module

pyspecProcScripts.apod_matched_filter.apod_matched_filter(s, axis='t2', convolve_method='gaussian', ret_width=False, fl=None)

Apodization Matched Filter

This function finds a Gaussian or Lorentzian lineshape whose linewidth matches that of the data, then multiplies the data by this matched-width lineshape, ultimately returning an apodized version of the input data .

axis: str

find matched filter along axisname

convolve_method: str

specify as one of the following 2 options: * Option 1 - ‘gaussian’ finds a matched-filter Gaussian to the input data * Option 2 - ‘lorentzian’ finds a matched-filter Lorentzian to the input data

ret_width: float

returns the linewidth found for the matched filter, typically not necessary

fl: None or figlist_var()

to show diagnostic plots, set fl to the figure list; set fl to None in order not to see any diagnostic plots

pyspecProcScripts.baseline module

pyspecProcScripts.baseline.calc_baseline(this_d, ph1lim, npts=5, guess=None, fl=None)

Calculate the baseline for an FID-like spectrum.

Parameters:
  • this_d (nddata) – complex data that needs baseline

  • ph1lim (range of ph1 dimension used) –

  • npts (integer for shape of array) –

  • guess (guessed baseline array or None) – if None will fill array shape given with zeroes. If guess then will fill shape given with guess.

  • show_plots (True or False) – If the plots are wanted set to True. This will add a plot called “try baseline correction” for before and after the baseline correction

Returns:

  • phcorr0 (zeroth order phase correction)

  • phcorr1 (first order phase correction)

  • baseline (generated baseline in form of array)

pyspecProcScripts.clock_correct module

pyspecProcScripts.clock_correct.clock_correct(s, fl=None, indirect='vd')

Do clock correction.

On spincore, the Tx carrier (clock) and Rx carrier do not seem to be exactly the same. This can be proven with a simple experiment that involves changing the time between phase reset and the start of the pulses. It is subtle, so it only affects things with longer delays, like T₁ measurements.

Parameters:
  • s (nddata) – The data to be corrected.

  • indirect (str) – The dimension along which to clock correct.

  • fl (figlist) –

Returns:

s – modified in-place

Return type:

nddata

pyspecProcScripts.convert_to_power module

pyspecProcScripts.convert_to_power.convert_to_power(s, filename, exp_type, fl=None, node_name='log', directional_coupler_dB=22)

Generate power axis for ODNP/E(p)/FIR experiments, converts instrument power log to useable axis

Parameters:
  • s (nddata) – This is an nddata whose “indirect” axis is a structured array. This structured array gives the start_times and stop_times (as fields) for each datapoint along the indirect axis.

  • filename (str) – Name of the hdf file that contains the power log.

  • exp_type (str) – The “experiment type” used to search for the file. directional_coupler_dB : float The ratio (in dB) of the power that leaves the main port of the directional coupler vs. the power that arrives at the power detector. This is measured, and the value here is a previously measured value for our system.

  • fl (figlist_var()) –

Returns:

  • values (numpy.array)

  • s (nddata) – (modified in-place) When we’re done, the axis coordinates for “indirect” are a (not structured) array containing the average power recorded on the log between each start_time and stop_time. The axis coordinate errors are the standard deviations of the same.

pyspecProcScripts.correlation_alignment module

pyspecProcScripts.correlation_alignment.correl_align(s_orig, tol=0.0001, indirect_dim='indirect', fig_title='correlation alignment', signal_pathway={'ph1': 0, 'ph2': 1}, avg_dim=None, max_shift=100.0, sigma=20.0, direct='t2', fl=None)

Align transients collected with chunked phase cycling dimensions along an indirect dimension based on maximizing the correlation across all the transients and repeat alignment until the calculated signal energy remains constant to within a given tolerance level.

This implements Eq 29 in the DCCT paper (Beaton et al JCP 2022), remembering that the FT of the cross-correlation is the product of the two functions, with the first on complex conjugate.

Parameters:
  • s_orig (psd.nddata) – A psd.nddata object which contains phase cycle dimensions and an indirect dimension. This data is not modified.

  • tol (float) – Sets the tolerance limit for the alignment procedure.

  • indirect_dim (str) – Name of the indirect dimension along which you seek to align the transients.

  • fig_title (str) – Title for the figures generated.

  • signal_pathway (dict) – Dictionary containing the signal pathway.

  • avg_dim (str) – Dimension along which the data is being averaged.

  • max_shift (float) – Specifies the upper and lower bounds to the range over which f_shift will be taken from the correlation function. Shift_bounds must be True. If it’s set to None, then no bounds are applied.

  • sigma (int) – Sigma value for the Gaussian mask. Related to the line width of the given data.

  • fl (boolean) – fl=fl to show the plots and figures produced by this function otherwise, fl=None.

Returns:

  • f_shift (np.array) – The optimized frequency shifts for each transient which will maximize their correlation amongst each other, thereby aligning them.

  • sigma (float) – The width of the Gaussian function used to frequency filter the data in the calculation of the correlation function.

pyspecProcScripts.envelope module

pyspecProcScripts.envelope.L2G(lambda_L, criterion='energy')
pyspecProcScripts.envelope.fit_envelope(s, min_l=10, threshold=0.1, full_width=8.434, direct='t2', plot_name='envelope', show_expanding_envelope=False, fl=None)

pyspecProcScripts.fitting module

pyspecProcScripts.fitting.decay(s, f_range, direct='t2', indirect='indirect', guess=None)

Take phased data, slice and integrate it in order to fit a T2 decay curve

Parameters:
  • direct (str) – name of the direct dimension

  • indirect (str) – name of the indirect dimension, along which the recovery is measured

Returns:

  • f (fitdata) – the full fitdata object with all info about the fit curve

  • T1 (float) – just the T1 relaxation time

pyspecProcScripts.fitting.recovery(s, f_range, direct='t2', indirect='indirect', guess=None)

Take phased data, slice and integrate it in order to fit an inversion recovery curve

Parameters:
  • direct (str) – name of the direct dimension

  • indirect (str) – name of the indirect dimension, along which the recovery is measured

Returns:

  • f (fitdata) – the full fitdata object with all info about the fit curve

  • T1 (float) – just the T1 relaxation time

  • save_guess (nddata) – returned only if the guess argument is set. Give an nddata with all parameters set to the guess value.

pyspecProcScripts.fwhm_calculate module

pyspecProcScripts.fwhm_calculate.fwhm_calculator(self, axis='t2', fl=None)

pyspecProcScripts.generate_integrals module

pyspecProcScripts.generate_integrals.generate_integrals(s, searchstr='', signal_pathway={'ph1': 0, 'ph2': 1}, excluded_pathways=[(0, 0)], f_range=(None, None), direct='t2', indirect='indirect', alias_slop=3, clock_correction=True, error_bars=True, correlate=True, fl=None)

Applies appropriate phase corrections, along with DC offset corrections, alignment, and integrates the data to transform 2D datasets into a table of integrals.

Parameters:
  • searchstr (str) – string for the title of the plots produced.

  • signal_pathway (dict) – Dictionary of the path of the desired signal.

  • excluded_pathways (dict) – Dictionary of all coherence pathways that are not the signal pathway.

  • f_range (tuple) – Frequency range over which the signal resides.

  • direct (str) – Direct dimension of the signal

  • indirect (str) – Indirect dimension of the signal. Usually ‘power’ or ‘nScans’ for example.

  • alias_slop (int) – Aliasing_slop used in the hermitian function.

  • clock_correction (bool) – If true, will apply a clock correction. Is needed for IR but not enhancement data.

  • error_bars (bool) – Option to apply integration with error bars.

  • correlate (bool) – Option to apply correlation alignment to data.

Returns:

  • s (psd.nddata) – Data with applied corrections but not integrated

  • s_int (psd.nddata) – Integrated and corrected data

pyspecProcScripts.integral_w_error module

pyspecProcScripts.integral_w_error.active_propagation(s, signal_path, indirect='vd', direct='t2', fl=None, offset=500.0)

propagate error from the region offset to the right of the peak (where we assume there is only noise), in the signal pathway signal_path, which we assume is the active coherence pathway. Include only the real part of the signal.

Parameters:
  • signal_path (dict) – Dictionary givin the active CT pathway

  • indirect (str) – Name of the indirect dimension – used to check that you don’t have directions that are not direct, indirect, or phase cycling.

  • direct (str) – Name of the direct dimension

  • offset (float) – Distance (in Hz) between the auto-chosen integration bounds from integrate_limits() and the start of the “noise region.”

Returns:

retval – just a data object with the error that this method predicts

Return type:

nddata

pyspecProcScripts.integral_w_error.integral_w_errors(s, sig_path, error_path, cutoff=0.1, convolve_method='Gaussian', indirect='vd', direct='t2', fl=None, return_frq_slice=False)

Calculates the propagation of error for the given signal and returns signal with the error associated.

Before declaring the error_path, look at an examples such as integration_w_error.py to see how to decide which excluded pathways to take the error over.

Parameters:
  • sig_path (dict) – Dictionary of the path of the desired signal.

  • error_path (dict) –

    Dictionary of all coherence pathways that are not the signal pathway.

    Before declaring the error_path, look at an examples such as integration_w_error.py to see how to decide which excluded pathways to take the error over.

  • convolve_method (str) – method of convolution used in integrating limits passed on to integrate_limits()

  • indirect (str) – Indirect axis.

  • direct (str) – Direct axis.

Returns:

s – Data with error associated with coherence pathways not included in the signal pathway.

Return type:

nddata

pyspecProcScripts.integrate_limits module

pyspecProcScripts.integrate_limits.integrate_limits(s, axis='t2', convolve_method='gaussian', cutoff=0.25, fl=None)

This function takes data in the frequency domain and finds the corresponding frequency limits of the signal for integration.

Limits are found by applying a matched filter (choice of Lorentzian or Gaussian convolve_method) to the frequency domain data, which it then uses to determine the integration limits based on a cutoff amplitude based as a fraction of the maximum signal intensity.

Parameters:
  • axis (str) – apply convolution along axisname

  • convolve_method (str) – specify as one of the following 3 options: * Option 1 - ‘gaussian’ to calculate the matched-filter via Gaussian convolution of the frequency domain signal. * Option 2 - ‘lorentzian’ to calculate the matched-filter via Lorentzian convolution of the frequency domain signal.

  • cutoff (float) – set the integration limit to the points where the convolved signal crosses this fraction of its maximum. (e.g. cutoff=0.5 would give integration limits that correspond to the frequencies marking the full width half maximum of the convolution of the signal and its matched filter)

  • fl (None or figlist_var()) – to show diagnostic plots, set fl to the figure list; set fl to None in order not to see any diagnostic plots

pyspecProcScripts.load_data module

Postproc dict and functions

Used to preprocess data based on type of experiment performed. Returns all data FTed into the frequency domain with the phase cycles also FTed (coherence domain). Data is not sliced or manipulated in any other way that would reduce information content.

pyspecProcScripts.load_data.hack_field_sweep_v4(s, fl=None)
pyspecProcScripts.load_data.hack_spincore_IR_v3(s, fl=None)

v3 has an incorrectly stored coherence pathway

pyspecProcScripts.load_data.proc_DOSY_CPMG(s, fl=None)
pyspecProcScripts.load_data.proc_ESR(s)
pyspecProcScripts.load_data.proc_FID_v1(s, fl=None)
pyspecProcScripts.load_data.proc_Hahn_echoph(s, fl=None)
pyspecProcScripts.load_data.proc_bruker_CPMG_v1(s, fl=None)
pyspecProcScripts.load_data.proc_bruker_T1CPMG_v1(s, fl=None)
pyspecProcScripts.load_data.proc_bruker_deut_IR_mancyc(s, fl=None)
pyspecProcScripts.load_data.proc_bruker_deut_IR_withecho_mancyc(s, fl=None)
pyspecProcScripts.load_data.proc_capture(s)
pyspecProcScripts.load_data.proc_field_sweep_v1(s)
pyspecProcScripts.load_data.proc_field_sweep_v2(s)
pyspecProcScripts.load_data.proc_nutation(s, fl=None)
pyspecProcScripts.load_data.proc_nutation_amp(s, fl=None)
pyspecProcScripts.load_data.proc_nutation_chunked(s, fl=None)
pyspecProcScripts.load_data.proc_nutation_v2(s, fl=None)
pyspecProcScripts.load_data.proc_nutation_v4(s, fl=None)

nutation curve

note that v4 are assumed to have an indirect axis labeled in SI units. Note that data acquired on 6/25 or before might have really messed up axis coordinates (some are multiplied by 1e12!)

pyspecProcScripts.load_data.proc_spincore_CPMG_v1(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_IR(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_IR_v2(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_ODNP_v1(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_ODNP_v2(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_ODNP_v3(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_ODNP_v4(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_SE_v1(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_diffph_SE_v1(s, fl=None)
pyspecProcScripts.load_data.proc_spincore_diffph_SE_v2(s, fl=None)

this one uses a phase cycle where the overall phase and 90-180 phase difference are cycled in a nested way – see the DCCT paper to understand this!

pyspecProcScripts.load_data.proc_spincore_echo_v1(s, fl=None)

old-fashioned (not properly shaped before storage) echo data

pyspecProcScripts.load_data.proc_spincore_generalproc_v1(s, direct='t2', include_tau_sub=True, fl=None)
pyspecProcScripts.load_data.proc_var_tau(s, fl=None)

pyspecProcScripts.phasing module

This module includes routines for phasing NMR spectra.

pyspecProcScripts.phasing.det_devisor(fl)
pyspecProcScripts.phasing.determine_sign(s, signal_freq_range, direct='t2', signal_pathway=None, fl=None)

Determines the sign of the signal based on the difference between the signal with the zeroth order phase correction applied to the entire data set vs applying the zeroth order phase correction to each individual indirect index. The sign can be used, so that when multiplied by the signal the data has a uniform sign along the indirect axis.

Parameters:
  • s (nddata) – Data with a single (dominant) peak, where you want to return the sign of the integral over all the data.

  • signal_freq_range (tuple) – Narrow slice range where signal resides.

  • direct (str (default "t2")) – Name of the direct dimension.

  • signal_pathway (dict (default None)) – If None, the function will go into the properties of the data looking for the “coherence_pathway” property. If that doesn’t exist the user needs to feed a dictionary containing the coherence transfer pathway where the signal resides.

Returns:

mysign – A dataset with all +1 or -1 (giving the sign of the original signal). Does not include the direct dimension.

Return type:

nddata

pyspecProcScripts.phasing.fid_from_echo(d, signal_pathway, fl=None, add_rising=False, direct='t2', exclude_rising=3, slice_multiplier=20, peak_lower_thresh=0.1, show_hermitian_sign_flipped=False, show_shifted_residuals=False, frq_center=None, frq_half=None)
Parameters:
  • signal_pathway (dict) – coherence transfer pathway that correspond to the signal

  • fl (figlist or None (default)) – If you want the diagnostic plots (showing the distribution of the data in the complex plane), set this to your figlist object.

  • add_rising (boolean) – Take the first part of the echo (that which rises to the maximum) and add the decaying (FID like) part. This increases the SNR of the early points of the signal.

  • direct (string) – Name of the direct dimension

  • exclude_rising (int) – In general it is assumed that the first few points of signal might be messed up due to dead time or other issues (assuming a tau of 0). This option allows us to add a rising edge to the echo and exclude the first few points of the signal. Note, to use this, add_rising must be True.

  • slice_multiplier (int) – The calculated frequency slice is calculated by taking the center frequency and extending out to values that are included in the peak times this multiplier. Therefore the larger this value the larger the frequency slice. Increasing this value might serve useful in the case of noisy spectra.

  • peak_lower_thresh (float) – Fraction of the signal intensity used in calculating the frequency slice. The smaller the value, the wider the slice.

  • show_hermitian_sign_flipped (boolean) – Diagnostic in checking the sign of the signal prior to the hermitian phase correction

  • show_shifted_residuals (boolean) – Diagnostic in analyzing the residuals after the hermitian phase correction.

  • frq_center (float (default None)) – The center of the peak. This only exists so that we don’t end up calling find_peakrange redundantly, and it should come from a previous call to find_peakrange if it’s used.

  • frq_half (float (default None)) – The half-width of the peak. This only exists so that we don’t end up calling find_peakrange redundantly, and it should come from a previous call to find_peakrange if it’s used.

Returns:

d – FID of properly sliced and phased signal

Return type:

nddata

pyspecProcScripts.phasing.find_peakrange(d, direct='t2', peak_lower_thresh=0.1, fl=None)

find the range of frequencies over which the signal occurs, so that we can autoslice

Parameters:
  • d (nddata) – Data in the frequency domain – will not be altered.

  • direct (str (default "t2")) – The name of the direct dimension

  • peak_lower_thresh (float) – Fraction of the signal intensity used in calculating the frequency slice. The smaller the value, the wider the slice.

  • fl (figlist (default None)) – If you want to see diagnostic plots, feed the figure list.

Returns:

  • frq_center (float) – The midpoint of the frequency slice.

  • frq_half (float) – Half the width of the frequency slice. Given in this way, so you can easily do >>> newslice = r_[-expansino,expansion]*frq_half+frq_center

pyspecProcScripts.phasing.hermitian_function_test(s, direct='t2', aliasing_slop=3, amp_threshold=0.05, fl=None, basename=None, show_extended=False, upsampling=40, energy_threshold=0.98, energy_threshold_lower=0.1, enable_refinement=False)

Determine the center of the echo via hermitian symmetry of the time domain.

Note the following issues/feature:

  • Data must start at t=0 (due to the way that we calculate the energy term in the expression)

  • Data typically has a rising edge, which can lead to ringing. Therefore, we apply a Tukey filter to the data. Because this suppresses the edges in frequency space, you will likely want to slice a slightly wider bandwidth than you are interested in.

  • If you have an initial portion of signal that has very low SNR (i.e. if your echo time is long relative to \(T_2^*\)), that will affect the SNR of the cost function. Trailing noise will not affect the SNR of the cost function, only lead to slightly longer calculation times.

Parameters:
  • direct (str) – Axis of data (i.e., direct dimension).

  • energy_threshold (float) – To avoid picking a minimum that’s based off of very little data, only recognize the cost function over an interval where the normalized energy function is equal to energy_threshold of its max value.

  • aliasing_slop (int (default 3)) – The signal typically has an initial rising portion where – even due to FIR or instrumental filters in the raw data, the signal has some kind of Gibbs ringing in the transition between signal an zero. This portion of the signal will not mirror the signal on the other side of the echo, and should not even be included in the cost function! We believe the most consistent way to specify the amount of signal that should be excluded as an number of datapoints, hence why we ask for an integer here.

  • enable_refinement (boolean) – Do not use – an attempt to correct for cases where we don’t get the lowest residual out of the Fourier technique. The idea was that this was based on the fact that the correlation function is calculated between the two upsampled (sinc interpolated) functions, and so we should explicitly calculate the residual in the original resolution. But, there appears to be an error that would need to be debugged – fails some of the basic tests, and the residual does not always appear to be the lowest.

  • todo:: (..) – AG fix docstring + cite coherence paper

pyspecProcScripts.phasing.ph1_real_Abs(s, dw, ph1_sel=0, ph2_sel=1, fl=None)

Performs first order phase correction with cost function by taking the sum of the absolute value of the real [DeBrouwer2009].

Todo

update with sphinxcontrib-bibtex.

Parameters:

s (nddata) – Complex data whose first order phase you want to find.

Returns:

  • retval

  • .. rubric (References)

  • .. [DeBrouwer2009] de Brouwer, H. (2009). Evaluation of algorithms for – automated phase correction of NMR spectra. Journal of Magnetic Resonance (San Diego, Calif. : 1997), 201(2), 230–238. https://doi.org/10.1016/j.jmr.2009.09.017

pyspecProcScripts.phasing.zeroth_order_ph(d, fl=None)

determine the moment of inertial of the datapoints in complex plane, and use to phase the zeroth-order even if the data is both negative and positive.

Parameters:
  • d (nddata) – Complex data whose zeroth order phase you want to find.

  • fl (figlist or None (default)) – If you want the diagnostic plots (showing the distribution of the data in the complex plane), set this to your figlist object. It will add a plot called “check covariance test”

Returns:

retval – The zeroth order phase of the data, as a complex number with magnitude 1. To correct the zeroth order phase of the data, divide by retval.

Return type:

complex128

pyspecProcScripts.plotting module

pyspecProcScripts.plotting.draw_limits(thisrange, s)

determines the range of the t2 axis and pairs it with the range given returns the x axis limits for plotting

Parameters:
  • thisrange (tuple of 2 floats) – slice range you are interested in extending

  • s (nddata) – the data you are planning on slicing

Return type:

the limits for the t2 axis for plotting purposes

pyspecProcScripts.plotting.expand_limits(thisrange, s, axis='t2')

“ Used to expand limits of a range (typically used for slicing) by 3X

Parameters:
  • thisrange (tuple of 2 floats) – slice range you are interested in extending

  • s (nddata) – the data you are planning on slicing

  • axis (str) – name of the axis along which the slice range will be applied

Returns:

retval – the expanded range

Return type:

tuple of 2 floats

class pyspecProcScripts.plotting.fl_mod(*arg, **kwargs)

Bases: figlist

Extends figlist_var with various new convenience functions.

complex_plot(d, label='', show_phase=False, show_real=True, alpha=0.5, linestyle=None, linewidth=3, color='k')
next(*arg, **kwargs)

Switch to the figure given by input_name, which is used not only as a string-based name for the figure, but also as a default title and as a base name for resulting figure files.

In the future, we actually want this to track the appropriate axis object!

Parameters:
  • legend (bool) – If this is set, a legend is created outside the figure.

  • twinx ({0,1}) –

    1:

    plots on an overlayed axis (the matplotlib twinx) whose y axis is labeled on the right when you set this for the first time, you can also set a color kwarg that controls the coloring of the right axis.

    0:

    used to switch back to the left (default) axis

  • boundariesneed to add description

  • kwargs (dict) – Any other keyword arguments are passed to the matplotlib (mayavi) figure() function that’s used to switch (create) figures.

plot_curve(f, name, guess=None)

Plot the data with fit curve and fit equation.

Parameters:
  • f (fitdata) – data (a fitting instance), on which f.fit() has already been run

  • guess (None or nddata) – The result of s.settoguess();s.eval(100) where 100 can be any integer. Used to display the guess on the plot as well.

  • name (str) – the name of the plot

real_imag(plotname, s)
side_by_side(plotname, s, thisrange)

a bit of a hack to get the two subplots into the figure list – also a good test for objective figure list – for each slice out 3x thisrange, and then show the lines for thisrange

pyspecProcScripts.simple_functions module

First order functions for very simple (a few lines) data manipulation

pyspecProcScripts.simple_functions.find_apparent_anal_freq(s)

A function to identify the position of analytic signal as acquired on the oscilloscope. Importantly this function takes into account the effects of aliasing in identifying the frequency of the resulting signal.

Parameters:

s (nddata) – data with a single (dominant) peak, where you want to identify the frequency.

Returns:

  • s (nddata) – The original data that was initially fed to the function

  • nu_a (float) – The apparent frequency of the signal

  • isflipped (boolean) – If aliased from a negative frequency, this notes whether the phase of the final time domain signal will be flipped

class pyspecProcScripts.simple_functions.logobj(array_len=1000)

Bases: object

classmethod from_group(h5group)

initialize a new log object with data loaded from the h5py group h5group (factory method

property total_log

the log is stored internally as a list of arrays – here return a single array for the whole log

pyspecProcScripts.simple_functions.select_pathway(*args, **kwargs)

select a particular CT pathway from the signal s

Arguments are either pathway – a dict of key/value pairs indicating the pathway or the same set of key/value pairs, just passed as a dict.

Parameters:
  • s (nddata) – the data whose coherence pathway you would like to select

  • pathway (dict) – keys are the names of the coherence transfer dimensions (conj. of phase cycling dimensions) and values are the pathway you want to select

pyspecProcScripts.slice_FID_from_echo module

pyspecProcScripts.slice_FID_from_echo.slice_FID_from_echo(s, max_t=None, signal_pathway={'ph1': 1, 'ph2': -2}, fl=None)

Automatically slices the FID out of an echo.

Determines the proper position for \(t=0\) from hermitian function test. This is followed by zeroth order phase correcting and slicing from the center of the echo (\(t=0\) onward to the t_range defined

Parameters:
  • max_t (int) – where the slice ends in the time domain.

  • ph1 (int) – the selection of ph1 in the coherence pathway

  • ph2 (int) – selection of ph2 in coherence pathway

Returns:

s

Return type:

phase corrected and sliced data

pyspecProcScripts.version module

Module contents

pyspecProcScripts.DCCT(this_nddata, this_fig_obj, custom_scaling=False, grid_bottom=0.0, bottom_pad=0.15, grid_top=1.0, top_pad=0.1, total_spacing=0.055, label_spacing_multiplier=50, allow_for_text_default=10, allow_for_ticks_default=70, text_height=40, LHS_pad=0.01, RHS_pad=0.05, shareaxis=False, cmap=None, pass_frq_slice=False, just_2D=False, scaling_factor=1, max_coh_jump={'ph1': 2, 'ph2': 1}, direct='t2', plot_title='DCCT', **kwargs)

DCCT plot

Parameters:
  • this_nddata (psd.nddata) – data being plotted

  • thi_fig_obj (figure) – size/type of figure to be plotted on

  • custom_scaling (boolean) – allows user to scale the intensity of data presented

  • grid_bottom (float) – coordinate for bottom of DCCT plot

  • bottom_pad (float) – distance between bottom of grid and bottom of figure

  • grid_top (float) – coordinate top of grid in figure

  • top_pad (float) – distance between top of figure and top of grid

  • total_spacing (float) – affects spacing between phase cycle dimensions

  • label_spacing_multiplier (int) – spacing between axes labels

  • allow_for_text_default (int) – adjusts distance between tick labels and ticks

  • allow_for_ticks_default (int) – adjusts distance between ticks

  • text_height (int) – adjusts sizing of axis labels and tick labels

  • LHS_pad (float) – adjusts padding on left hand side of DCCT plot

  • RHS_pad (float) – adjusts padding on right hand side of DCCT plot

  • shareaxis (boolean) – subplots scale together, but currently, this means there must be tick labels on both top and bottom

  • cmap (str) – string for color mapping if specified

  • pass_frq_slice (boolean) – if true will show the frequency sliced out with hatching

  • just_2D (boolean) – If true will only return axis coordinates/shape NOT ax_list

  • scaling_factor (float) – If using custom scaling this allows user to set the scaling factor

  • max_coh_jump (dict) – maximum allowed transitions for each phase cycle

  • direct (str) – name of direct axis

  • plot_title (str) – title for DCCT plot

pyspecProcScripts.L2G(lambda_L, criterion='energy')
pyspecProcScripts.QESR(data_or_filename, label, pushout=0.5, threshold=0.05, pickle_file=None, background=None, exp_type=None, calibration_name=None, diameter_name=None, color=None, plot_derivative=False, fl=None)

Converts a raw ESR spectra to the double integral and calculates the appropriate concentration of spins present.

If a background spectra is provided, background subtraction is applied to the loaded ESR spectra. The double integral is finally rescaled and multiplied by a proportionality constant associated with the matching value in your pyspecdata config file. The resulting plot shows the double integral with the calculated concentration in micromolar in the legend.

Parameters:
  • data_or_filename (nddata or string) – Either the data or the filename.

  • pushout (float) – Adjusts the “generous limits” factor which is added to the integration area surrounding the peaks

  • threshold (float) – Used in defining the integration limits (threshold*max)

  • pickle_file (str) – Name of pickle file you want to append the concentration to. (Concentration is stored in μM)

  • background (nddata) – The background spectrum that should already be loaded

  • exp_type (str) – Where the file of interest is

  • calibration_name (str) – Name of the value in your pyspecdata config file that points to the proportionality constant

  • diameter_name (str) – Name of the value in your pyspecdata config file that points to the diameter of the capillary being used

  • color (str) – String of the desired color for the plot. This is especially useful when trying to coordinate color matching with other plots

  • plot_derivative (boolean (default False)) – If you want to see the (rescaled, background subtracted) spectrum.

  • fl (figure list) – required!

pyspecProcScripts.QESR_apply_scalefactor(d)

Divide the ESR spectrum by this number so that the double integral should be equal to concentration in μM.

We specifically calculate \(d^{2} G_{R} C_{t} \sqrt{P} B_{m} Q n_{B} S (S + 1) / c_{propfactor}\) (the denominator of equation 2-17 in the E500 manual with \(d^2\) (diameter squared) added in, so that after dividing by this term, we get a concentration of spins rather than the total number of spins).

The constant \(c_{propfactor}\) is determined by the calibration name. Note that a larger \(c_{propfactor}\) corresponds to a higher concentration for the same recorded spectrum.

See the QESR.py example for currently recommended settings for the example data.

Parameters:

d (nddata) –

has these properties:

calibration_name: str

The key corresponding to the appropriate proportionality constant in your pyspecdata config file. Typically this is one value that doesn’t need changing

diameter_name: str

The key corresponding to the diameter of the capillary tube used in the ESR experiment. This enables us to calculate a reliable concentration regardless of which capillary was used.

Returns:

  • Denominator of equation 2-17 divided by the proportionality constant.

  • Also includes a factor of 1e-6 to convert Molar to micromolar.

pyspecProcScripts.QESR_scalefactor(d, **kwargs)
pyspecProcScripts.Vpp2power(Vpp, Z=50.0)

convert peak to peak voltage to power

pyspecProcScripts.active_propagation(s, signal_path, indirect='vd', direct='t2', fl=None, offset=500.0)

propagate error from the region offset to the right of the peak (where we assume there is only noise), in the signal pathway signal_path, which we assume is the active coherence pathway. Include only the real part of the signal.

Parameters:
  • signal_path (dict) – Dictionary givin the active CT pathway

  • indirect (str) – Name of the indirect dimension – used to check that you don’t have directions that are not direct, indirect, or phase cycling.

  • direct (str) – Name of the direct dimension

  • offset (float) – Distance (in Hz) between the auto-chosen integration bounds from integrate_limits() and the start of the “noise region.”

Returns:

retval – just a data object with the error that this method predicts

Return type:

nddata

pyspecProcScripts.align_esr(data_dict, correlation_slice=None, on_crossing=False, fl=None)

open and correlation align ESR spectra. Store the shifts and scalefactors as properties of the nddata, which are returned as a dictionary of nddata.

Details

While we can align by microwave frequency and normalize according to peak-to-peak amplitude, it scan still be hard to identify subtle differences between ESR spectra, and small imperfections – such as free MTSL – can play an outsized role.

Therefore, here, we use correlation to align the spectra and then use “dot-product scaling” to normalize them. By “dot-product scaling” we mean scaling the amplitude of one vector (here a spectrum, \(\mathbf{b}\)) relative to a reference (here \(\mathbf{a}\)) to minimize the residual between the two – i.e. we minimize the expression

\[|\mathbf{a}-c\mathbf{b}|^2\]

by varying the scaling constant \(c\). The solution to this is

\[c = \frac{\Re[\mathbf{a}\cdot \mathbf{b}]}{||\mathbf{b}||^2}\]

In order to do all this, we need a common x-axis that we can use for correlation, etc. Here, we look for the fields that are furthest left and furthest right, and for the smallest spacing between field samples – we use these values to construct a (therefore all-inclusive) x axis.

Also, for the purposes of dot-product scaling, it is better to scale the less noisy spectrum (\(\mathbf{b}\) above) relative to the noisier spectrum (\(\mathbf{a}\) above) – i.e. above, we want \(\mathbf{b}\) to be less noisy. Here, we simply find the largest spectrum in the group (assuming it is least noisy) and use it as \(\mathbf{b}\).

param correlation_slice:

This should ONLY be needed for VERY different spectra – e.g. pure MTSL vs. a protein – where without it, the different hyperfines show up out of register. You can look at the correlation plot, and select a range of shifts for it to find a max over.

type correlation_slice:

tuple default None

pyspecProcScripts.apod_matched_filter(s, axis='t2', convolve_method='gaussian', ret_width=False, fl=None)

Apodization Matched Filter

This function finds a Gaussian or Lorentzian lineshape whose linewidth matches that of the data, then multiplies the data by this matched-width lineshape, ultimately returning an apodized version of the input data .

axis: str

find matched filter along axisname

convolve_method: str

specify as one of the following 2 options: * Option 1 - ‘gaussian’ finds a matched-filter Gaussian to the input data * Option 2 - ‘lorentzian’ finds a matched-filter Lorentzian to the input data

ret_width: float

returns the linewidth found for the matched filter, typically not necessary

fl: None or figlist_var()

to show diagnostic plots, set fl to the figure list; set fl to None in order not to see any diagnostic plots

pyspecProcScripts.calc_baseline(this_d, ph1lim, npts=5, guess=None, fl=None)

Calculate the baseline for an FID-like spectrum.

Parameters:
  • this_d (nddata) – complex data that needs baseline

  • ph1lim (range of ph1 dimension used) –

  • npts (integer for shape of array) –

  • guess (guessed baseline array or None) – if None will fill array shape given with zeroes. If guess then will fill shape given with guess.

  • show_plots (True or False) – If the plots are wanted set to True. This will add a plot called “try baseline correction” for before and after the baseline correction

Returns:

  • phcorr0 (zeroth order phase correction)

  • phcorr1 (first order phase correction)

  • baseline (generated baseline in form of array)

pyspecProcScripts.center_echo(s, echo_center, axis='t2', fl=None)

Centers data around echo center given, and applies a zeroth order phase correction.

Will generate an error if the echo appears to be extremely lopsided.

Parameters:
  • echo_center (float) – center of echo

  • axis (str) – axis along which the echo is being centered

pyspecProcScripts.clock_correct(s, fl=None, indirect='vd')

Do clock correction.

On spincore, the Tx carrier (clock) and Rx carrier do not seem to be exactly the same. This can be proven with a simple experiment that involves changing the time between phase reset and the start of the pulses. It is subtle, so it only affects things with longer delays, like T₁ measurements.

Parameters:
  • s (nddata) – The data to be corrected.

  • indirect (str) – The dimension along which to clock correct.

  • fl (figlist) –

Returns:

s – modified in-place

Return type:

nddata

pyspecProcScripts.convert_to_power(s, filename, exp_type, fl=None, node_name='log', directional_coupler_dB=22)

Generate power axis for ODNP/E(p)/FIR experiments, converts instrument power log to useable axis

Parameters:
  • s (nddata) – This is an nddata whose “indirect” axis is a structured array. This structured array gives the start_times and stop_times (as fields) for each datapoint along the indirect axis.

  • filename (str) – Name of the hdf file that contains the power log.

  • exp_type (str) – The “experiment type” used to search for the file. directional_coupler_dB : float The ratio (in dB) of the power that leaves the main port of the directional coupler vs. the power that arrives at the power detector. This is measured, and the value here is a previously measured value for our system.

  • fl (figlist_var()) –

Returns:

  • values (numpy.array)

  • s (nddata) – (modified in-place) When we’re done, the axis coordinates for “indirect” are a (not structured) array containing the average power recorded on the log between each start_time and stop_time. The axis coordinate errors are the standard deviations of the same.

pyspecProcScripts.correl_align(s_orig, tol=0.0001, indirect_dim='indirect', fig_title='correlation alignment', signal_pathway={'ph1': 0, 'ph2': 1}, avg_dim=None, max_shift=100.0, sigma=20.0, direct='t2', fl=None)

Align transients collected with chunked phase cycling dimensions along an indirect dimension based on maximizing the correlation across all the transients and repeat alignment until the calculated signal energy remains constant to within a given tolerance level.

This implements Eq 29 in the DCCT paper (Beaton et al JCP 2022), remembering that the FT of the cross-correlation is the product of the two functions, with the first on complex conjugate.

Parameters:
  • s_orig (psd.nddata) – A psd.nddata object which contains phase cycle dimensions and an indirect dimension. This data is not modified.

  • tol (float) – Sets the tolerance limit for the alignment procedure.

  • indirect_dim (str) – Name of the indirect dimension along which you seek to align the transients.

  • fig_title (str) – Title for the figures generated.

  • signal_pathway (dict) – Dictionary containing the signal pathway.

  • avg_dim (str) – Dimension along which the data is being averaged.

  • max_shift (float) – Specifies the upper and lower bounds to the range over which f_shift will be taken from the correlation function. Shift_bounds must be True. If it’s set to None, then no bounds are applied.

  • sigma (int) – Sigma value for the Gaussian mask. Related to the line width of the given data.

  • fl (boolean) – fl=fl to show the plots and figures produced by this function otherwise, fl=None.

Returns:

  • f_shift (np.array) – The optimized frequency shifts for each transient which will maximize their correlation amongst each other, thereby aligning them.

  • sigma (float) – The width of the Gaussian function used to frequency filter the data in the calculation of the correlation function.

pyspecProcScripts.dBm2power(dBm)

convert from dBm to W

pyspecProcScripts.decay(s, f_range, direct='t2', indirect='indirect', guess=None)

Take phased data, slice and integrate it in order to fit a T2 decay curve

Parameters:
  • direct (str) – name of the direct dimension

  • indirect (str) – name of the indirect dimension, along which the recovery is measured

Returns:

  • f (fitdata) – the full fitdata object with all info about the fit curve

  • T1 (float) – just the T1 relaxation time

pyspecProcScripts.determine_sign(s, signal_freq_range, direct='t2', signal_pathway=None, fl=None)

Determines the sign of the signal based on the difference between the signal with the zeroth order phase correction applied to the entire data set vs applying the zeroth order phase correction to each individual indirect index. The sign can be used, so that when multiplied by the signal the data has a uniform sign along the indirect axis.

Parameters:
  • s (nddata) – Data with a single (dominant) peak, where you want to return the sign of the integral over all the data.

  • signal_freq_range (tuple) – Narrow slice range where signal resides.

  • direct (str (default "t2")) – Name of the direct dimension.

  • signal_pathway (dict (default None)) – If None, the function will go into the properties of the data looking for the “coherence_pathway” property. If that doesn’t exist the user needs to feed a dictionary containing the coherence transfer pathway where the signal resides.

Returns:

mysign – A dataset with all +1 or -1 (giving the sign of the original signal). Does not include the direct dimension.

Return type:

nddata

pyspecProcScripts.draw_limits(thisrange, s)

determines the range of the t2 axis and pairs it with the range given returns the x axis limits for plotting

Parameters:
  • thisrange (tuple of 2 floats) – slice range you are interested in extending

  • s (nddata) – the data you are planning on slicing

Return type:

the limits for the t2 axis for plotting purposes

pyspecProcScripts.expand_limits(thisrange, s, axis='t2')

“ Used to expand limits of a range (typically used for slicing) by 3X

Parameters:
  • thisrange (tuple of 2 floats) – slice range you are interested in extending

  • s (nddata) – the data you are planning on slicing

  • axis (str) – name of the axis along which the slice range will be applied

Returns:

retval – the expanded range

Return type:

tuple of 2 floats

pyspecProcScripts.fid_from_echo(d, signal_pathway, fl=None, add_rising=False, direct='t2', exclude_rising=3, slice_multiplier=20, peak_lower_thresh=0.1, show_hermitian_sign_flipped=False, show_shifted_residuals=False, frq_center=None, frq_half=None)
Parameters:
  • signal_pathway (dict) – coherence transfer pathway that correspond to the signal

  • fl (figlist or None (default)) – If you want the diagnostic plots (showing the distribution of the data in the complex plane), set this to your figlist object.

  • add_rising (boolean) – Take the first part of the echo (that which rises to the maximum) and add the decaying (FID like) part. This increases the SNR of the early points of the signal.

  • direct (string) – Name of the direct dimension

  • exclude_rising (int) – In general it is assumed that the first few points of signal might be messed up due to dead time or other issues (assuming a tau of 0). This option allows us to add a rising edge to the echo and exclude the first few points of the signal. Note, to use this, add_rising must be True.

  • slice_multiplier (int) – The calculated frequency slice is calculated by taking the center frequency and extending out to values that are included in the peak times this multiplier. Therefore the larger this value the larger the frequency slice. Increasing this value might serve useful in the case of noisy spectra.

  • peak_lower_thresh (float) – Fraction of the signal intensity used in calculating the frequency slice. The smaller the value, the wider the slice.

  • show_hermitian_sign_flipped (boolean) – Diagnostic in checking the sign of the signal prior to the hermitian phase correction

  • show_shifted_residuals (boolean) – Diagnostic in analyzing the residuals after the hermitian phase correction.

  • frq_center (float (default None)) – The center of the peak. This only exists so that we don’t end up calling find_peakrange redundantly, and it should come from a previous call to find_peakrange if it’s used.

  • frq_half (float (default None)) – The half-width of the peak. This only exists so that we don’t end up calling find_peakrange redundantly, and it should come from a previous call to find_peakrange if it’s used.

Returns:

d – FID of properly sliced and phased signal

Return type:

nddata

pyspecProcScripts.find_apparent_anal_freq(s)

A function to identify the position of analytic signal as acquired on the oscilloscope. Importantly this function takes into account the effects of aliasing in identifying the frequency of the resulting signal.

Parameters:

s (nddata) – data with a single (dominant) peak, where you want to identify the frequency.

Returns:

  • s (nddata) – The original data that was initially fed to the function

  • nu_a (float) – The apparent frequency of the signal

  • isflipped (boolean) – If aliased from a negative frequency, this notes whether the phase of the final time domain signal will be flipped

pyspecProcScripts.find_peakrange(d, direct='t2', peak_lower_thresh=0.1, fl=None)

find the range of frequencies over which the signal occurs, so that we can autoslice

Parameters:
  • d (nddata) – Data in the frequency domain – will not be altered.

  • direct (str (default "t2")) – The name of the direct dimension

  • peak_lower_thresh (float) – Fraction of the signal intensity used in calculating the frequency slice. The smaller the value, the wider the slice.

  • fl (figlist (default None)) – If you want to see diagnostic plots, feed the figure list.

Returns:

  • frq_center (float) – The midpoint of the frequency slice.

  • frq_half (float) – Half the width of the frequency slice. Given in this way, so you can easily do >>> newslice = r_[-expansino,expansion]*frq_half+frq_center

pyspecProcScripts.fit_envelope(s, min_l=10, threshold=0.1, full_width=8.434, direct='t2', plot_name='envelope', show_expanding_envelope=False, fl=None)
class pyspecProcScripts.fl_mod(*arg, **kwargs)

Bases: figlist

Extends figlist_var with various new convenience functions.

complex_plot(d, label='', show_phase=False, show_real=True, alpha=0.5, linestyle=None, linewidth=3, color='k')
next(*arg, **kwargs)

Switch to the figure given by input_name, which is used not only as a string-based name for the figure, but also as a default title and as a base name for resulting figure files.

In the future, we actually want this to track the appropriate axis object!

Parameters:
  • legend (bool) – If this is set, a legend is created outside the figure.

  • twinx ({0,1}) –

    1:

    plots on an overlayed axis (the matplotlib twinx) whose y axis is labeled on the right when you set this for the first time, you can also set a color kwarg that controls the coloring of the right axis.

    0:

    used to switch back to the left (default) axis

  • boundariesneed to add description

  • kwargs (dict) – Any other keyword arguments are passed to the matplotlib (mayavi) figure() function that’s used to switch (create) figures.

plot_curve(f, name, guess=None)

Plot the data with fit curve and fit equation.

Parameters:
  • f (fitdata) – data (a fitting instance), on which f.fit() has already been run

  • guess (None or nddata) – The result of s.settoguess();s.eval(100) where 100 can be any integer. Used to display the guess on the plot as well.

  • name (str) – the name of the plot

real_imag(plotname, s)
side_by_side(plotname, s, thisrange)

a bit of a hack to get the two subplots into the figure list – also a good test for objective figure list – for each slice out 3x thisrange, and then show the lines for thisrange

pyspecProcScripts.fwhm_calculator(self, axis='t2', fl=None)
pyspecProcScripts.generate_integrals(s, searchstr='', signal_pathway={'ph1': 0, 'ph2': 1}, excluded_pathways=[(0, 0)], f_range=(None, None), direct='t2', indirect='indirect', alias_slop=3, clock_correction=True, error_bars=True, correlate=True, fl=None)

Applies appropriate phase corrections, along with DC offset corrections, alignment, and integrates the data to transform 2D datasets into a table of integrals.

Parameters:
  • searchstr (str) – string for the title of the plots produced.

  • signal_pathway (dict) – Dictionary of the path of the desired signal.

  • excluded_pathways (dict) – Dictionary of all coherence pathways that are not the signal pathway.

  • f_range (tuple) – Frequency range over which the signal resides.

  • direct (str) – Direct dimension of the signal

  • indirect (str) – Indirect dimension of the signal. Usually ‘power’ or ‘nScans’ for example.

  • alias_slop (int) – Aliasing_slop used in the hermitian function.

  • clock_correction (bool) – If true, will apply a clock correction. Is needed for IR but not enhancement data.

  • error_bars (bool) – Option to apply integration with error bars.

  • correlate (bool) – Option to apply correlation alignment to data.

Returns:

  • s (psd.nddata) – Data with applied corrections but not integrated

  • s_int (psd.nddata) – Integrated and corrected data

pyspecProcScripts.hermitian_function_test(s, direct='t2', aliasing_slop=3, amp_threshold=0.05, fl=None, basename=None, show_extended=False, upsampling=40, energy_threshold=0.98, energy_threshold_lower=0.1, enable_refinement=False)

Determine the center of the echo via hermitian symmetry of the time domain.

Note the following issues/feature:

  • Data must start at t=0 (due to the way that we calculate the energy term in the expression)

  • Data typically has a rising edge, which can lead to ringing. Therefore, we apply a Tukey filter to the data. Because this suppresses the edges in frequency space, you will likely want to slice a slightly wider bandwidth than you are interested in.

  • If you have an initial portion of signal that has very low SNR (i.e. if your echo time is long relative to \(T_2^*\)), that will affect the SNR of the cost function. Trailing noise will not affect the SNR of the cost function, only lead to slightly longer calculation times.

Parameters:
  • direct (str) – Axis of data (i.e., direct dimension).

  • energy_threshold (float) – To avoid picking a minimum that’s based off of very little data, only recognize the cost function over an interval where the normalized energy function is equal to energy_threshold of its max value.

  • aliasing_slop (int (default 3)) – The signal typically has an initial rising portion where – even due to FIR or instrumental filters in the raw data, the signal has some kind of Gibbs ringing in the transition between signal an zero. This portion of the signal will not mirror the signal on the other side of the echo, and should not even be included in the cost function! We believe the most consistent way to specify the amount of signal that should be excluded as an number of datapoints, hence why we ask for an integer here.

  • enable_refinement (boolean) – Do not use – an attempt to correct for cases where we don’t get the lowest residual out of the Fourier technique. The idea was that this was based on the fact that the correlation function is calculated between the two upsampled (sinc interpolated) functions, and so we should explicitly calculate the residual in the original resolution. But, there appears to be an error that would need to be debugged – fails some of the basic tests, and the residual does not always appear to be the lowest.

  • todo:: (..) – AG fix docstring + cite coherence paper

pyspecProcScripts.integral_w_errors(s, sig_path, error_path, cutoff=0.1, convolve_method='Gaussian', indirect='vd', direct='t2', fl=None, return_frq_slice=False)

Calculates the propagation of error for the given signal and returns signal with the error associated.

Before declaring the error_path, look at an examples such as integration_w_error.py to see how to decide which excluded pathways to take the error over.

Parameters:
  • sig_path (dict) – Dictionary of the path of the desired signal.

  • error_path (dict) –

    Dictionary of all coherence pathways that are not the signal pathway.

    Before declaring the error_path, look at an examples such as integration_w_error.py to see how to decide which excluded pathways to take the error over.

  • convolve_method (str) – method of convolution used in integrating limits passed on to integrate_limits()

  • indirect (str) – Indirect axis.

  • direct (str) – Direct axis.

Returns:

s – Data with error associated with coherence pathways not included in the signal pathway.

Return type:

nddata

pyspecProcScripts.integrate_limits(s, axis='t2', convolve_method='gaussian', cutoff=0.25, fl=None)

This function takes data in the frequency domain and finds the corresponding frequency limits of the signal for integration.

Limits are found by applying a matched filter (choice of Lorentzian or Gaussian convolve_method) to the frequency domain data, which it then uses to determine the integration limits based on a cutoff amplitude based as a fraction of the maximum signal intensity.

Parameters:
  • axis (str) – apply convolution along axisname

  • convolve_method (str) – specify as one of the following 3 options: * Option 1 - ‘gaussian’ to calculate the matched-filter via Gaussian convolution of the frequency domain signal. * Option 2 - ‘lorentzian’ to calculate the matched-filter via Lorentzian convolution of the frequency domain signal.

  • cutoff (float) – set the integration limit to the points where the convolved signal crosses this fraction of its maximum. (e.g. cutoff=0.5 would give integration limits that correspond to the frequencies marking the full width half maximum of the convolution of the signal and its matched filter)

  • fl (None or figlist_var()) – to show diagnostic plots, set fl to the figure list; set fl to None in order not to see any diagnostic plots

class pyspecProcScripts.logobj(array_len=1000)

Bases: object

classmethod from_group(h5group)

initialize a new log object with data loaded from the h5py group h5group (factory method

property total_log

the log is stored internally as a list of arrays – here return a single array for the whole log

pyspecProcScripts.ph1_real_Abs(s, dw, ph1_sel=0, ph2_sel=1, fl=None)

Performs first order phase correction with cost function by taking the sum of the absolute value of the real [DeBrouwer2009].

Todo

update with sphinxcontrib-bibtex.

Parameters:

s (nddata) – Complex data whose first order phase you want to find.

Returns:

  • retval

  • .. rubric (References)

  • .. [DeBrouwer2009] de Brouwer, H. (2009). Evaluation of algorithms for – automated phase correction of NMR spectra. Journal of Magnetic Resonance (San Diego, Calif. : 1997), 201(2), 230–238. https://doi.org/10.1016/j.jmr.2009.09.017

pyspecProcScripts.power2dBm(power)

convert from W to dBm

pyspecProcScripts.recovery(s, f_range, direct='t2', indirect='indirect', guess=None)

Take phased data, slice and integrate it in order to fit an inversion recovery curve

Parameters:
  • direct (str) – name of the direct dimension

  • indirect (str) – name of the indirect dimension, along which the recovery is measured

Returns:

  • f (fitdata) – the full fitdata object with all info about the fit curve

  • T1 (float) – just the T1 relaxation time

  • save_guess (nddata) – returned only if the guess argument is set. Give an nddata with all parameters set to the guess value.

pyspecProcScripts.rough_table_of_integrals(s, signal_range=None, signal_pathway=None, fl=None, echo_like=True, title='', direct='t2', expansion=2, peak_lower_thresh=0.1, inc_plot_color=True)

manipulate s to generate a table of integrals (with only rough alignment)

Parameters:
  • s (nddata) – Data with a single (dominant) peak, where you want to return the sign of the integral over all the data.

  • signal_range (tuple (default None)) –

    Narrow slice range where signal resides. You probably want to get this from find_peakrange rather than trying to specify manually! (And expand the range that it gives you slightly)

    If this is set to the string ‘peakrange’, it assumes a previous call to find_peakrange has set the ‘peakrange’ property, and it uses that.

    If this is set to None, then it assume you want to call find_peakrange

  • signal_pathway (dict (default None)) – If None, the function will go into the properties of the data looking for the “coherence_pathway” property. If that doesn’t exist the user needs to feed a dictionary containing the coherence transfer pathway where the signal resides. If the signal has already been sliced along the coherence dimensions, you can feed an empty dictionary (note the very different behavior vs None)

  • echo_like (boolean) – If the signal has an echo the fid_from_echo function will be applied prior to integration to apply the FID slice as well as proper phasing and peak selection.

  • title (str) – Title for the returned figure.

  • direct (str (default "t2")) – Name of direct dimension.

  • expansion (float (default 2)) – Expand peakrange about its center by this much.

  • peak_lower_thresh (float) – passed to find_peakrange()

  • inc_plot_color (boolean) – assume that we are processing multiple datasets, and want to increment the color counter with every run of this function.

Returns:

  • s (nddata) – The table of integrals (collapse the direct dimension into a single number). Processing is done in place.

  • ax4 (Axes) – Return the axis with the table of integrals (plotted as “o”), in case you want to add a fit!

pyspecProcScripts.select_pathway(*args, **kwargs)

select a particular CT pathway from the signal s

Arguments are either pathway – a dict of key/value pairs indicating the pathway or the same set of key/value pairs, just passed as a dict.

Parameters:
  • s (nddata) – the data whose coherence pathway you would like to select

  • pathway (dict) – keys are the names of the coherence transfer dimensions (conj. of phase cycling dimensions) and values are the pathway you want to select

pyspecProcScripts.show_pickle_table(pickle_file)

show a pickle file with scalar variables in a latex table

Useful function when comparing multiple data sets and takes advantage of the capability of QESR() function to output pickle files. A latex table is generated pulling from the pickle file called.

pyspecProcScripts.slice_FID_from_echo(s, max_t=None, signal_pathway={'ph1': 1, 'ph2': -2}, fl=None)

Automatically slices the FID out of an echo.

Determines the proper position for \(t=0\) from hermitian function test. This is followed by zeroth order phase correcting and slicing from the center of the echo (\(t=0\) onward to the t_range defined

Parameters:
  • max_t (int) – where the slice ends in the time domain.

  • ph1 (int) – the selection of ph1 in the coherence pathway

  • ph2 (int) – selection of ph2 in coherence pathway

Returns:

s

Return type:

phase corrected and sliced data

pyspecProcScripts.zeroth_order_ph(d, fl=None)

determine the moment of inertial of the datapoints in complex plane, and use to phase the zeroth-order even if the data is both negative and positive.

Parameters:
  • d (nddata) – Complex data whose zeroth order phase you want to find.

  • fl (figlist or None (default)) – If you want the diagnostic plots (showing the distribution of the data in the complex plane), set this to your figlist object. It will add a plot called “check covariance test”

Returns:

retval – The zeroth order phase of the data, as a complex number with magnitude 1. To correct the zeroth order phase of the data, divide by retval.

Return type:

complex128