pysprint.core.methods package¶
Submodules¶
pysprint.core.methods.cosfit module¶

class
CosFitMethod
(*args, **kwargs)¶ Bases:
pysprint.core.bases.dataset.Dataset
Basic interface for the Cosine Function Fit Method.

__init__
(*args, **kwargs)¶ Base constructor for Dataset.
Parameters:  x (np.ndarray) – The x values.
 y (np.ndarray) – The y values.
 ref (np.ndarray, optional) – The reference arm’s spectra.
 sam (np.ndarray, optional) – The sample arm’s spectra.
 meta (dictlike) – The dictionary containing further information about the dataset. Can be extended, or set to be any valid ~collections.abc.Mapping.
 errors (str, optional) – Whether to raise on missmatching sized data. Must be “raise” or “force”. If “force” then truncate to the shortest size. Default is “raise”.
 callback (callable, optional) – The function that notifies parent objects about SPP related changes. In most cases the user should leave this empty. The default callback is only initialized if this object is constructed by the pysprint.SPPMethod object.
 parent (any class, optional) – The object which handles the callback function. In most cases the user should leave this empty.
 kwargs (dict, optional) – The window class to use in WFTMethod. Has no effect while using other methods. Must be a subclass of pysprint.core.windows.WindowBase.
Note
To load in data by files, see the other constructor parse_raw.

set_max_tries
(value)¶ Overwrite the default scipy maximum try setting to fit the curve.

adjust_offset
(value)¶ Initial guess for offset.

adjust_amplitude
(value)¶ Initial guess for amplitude.

guess_GD
(value)¶ Initial guess for GD in fs.

guess_GDD
(value)¶ Initial guess for GDD in fs^2.

guess_TOD
(value)¶ Initial guess for TOD in fs^3.

guess_FOD
(value)¶ Initial guess for FOD in fs^4.

guess_QOD
(value)¶ Initial guess for QOD in fs^5.

guess_SOD
(value)¶ Initial guess for SOD in fs^6.

set_max_order
(order)¶ Sets the maximum order of dispersion to look for. Should be called after guessing the initial parameters.
Parameters: order (int) – Maximum order of dispersion to look for. Must be in [1, 6].

calculate
(reference_point)¶ Cosine fit’s calculate function.
Parameters: reference_point (float) – Reference point on x axis. Returns:  dispersion (arraylike) – [GD, GDD, TOD, FOD, QOD, SOD]
 dispersion_std (arraylike) – Standard deviations due to uncertainty of the fit. They are only calculated if lmfit is installed. [GD_std, GDD_std, TOD_std, FOD_std, QOD_std, SOD_std]
 fit_report (str) – Not implemented yet. It returns an empty string for the time being.
Note
Decorated with pprint_disp, so the results are immediately printed without explicitly saying so.

plot_result
()¶ If the curve fitting is done, draws the fitted curve on the original dataset. Also prints the coeffitient of determination of the fit (a.k.a. r^2).

optimizer
(reference_point, order=3, initial_region_ratio=0.1, extend_by=0.1, coef_threshold=0.3, max_tries=5000, show_endpoint=True)¶ Cosine fit optimizer. It’s based on adding new terms to fit function successively until we reach the maximum order.
Parameters:  reference_point (float) – The reference point on the x axis.
 order (int, optional) – Polynomial (and maximum dispersion) order to fit. Must be in [1, 6]. Default is 3.
 initial_region_ratio (float, optional) – The initial region in portion of the length of the dataset (0.1 will mean 10%, and so on..). Note that the bigger resolution the interferogram is, the lower it should be set. Default is 0.1. It should not be set too low, because too small initial region can result in failure.
 extend_by (float, optional) – The coefficient determining how quickly the region of fit is growing. The bigger resolution the interferogram is (or in general the higher the dispersion is), the lower it should be set. Default is 0.1.
 coef_threshold (float, optional) – The desired R^2 threshold which determines when to expand the region of fitting. It’s often enough to leave it as is, however if you decide to change it, it is highly advised not to set a higher value than 0.7. Default is 0.3.
 max_tries (int, optional) – The maximum number of tries to fit a curve before failing. Default is 5000.
 show_endpoint (bool, optional) – If True show the fitting results when finished. Default is True.
Note
If the fit fails some parameters must be tweaked in order to achieve results. There is a list below with issues, its suspected reasons and solutions.
SciPy raises OptimizeWarning and the affected area is small or not showing any fit
Reasons: Completely wrong initial GD guess (or lack of guessing). Too broad initial region, so that the optimizer cannot find a suitable fit.
This usually happens when the used data is large, or the spectral resolution is high.
Solution: Provide better initial guess for GD. Lower the initial_region_ratio.
SciPy raises OptimizeWarning and the affected area is bigger
Reasons: When the optimizer steps up with order it also extends the region of fit.
This error usually present when the region of fit is too quickly growing.
Solution: Lower extend_by argument.
The optimizer is finished, but wrong fit is produced.
Reasons: We measure the goodness of fit with r^2 value. To allow this optimizer to smoothly find appropriate fits even for noisy datasets it’s a good practice to keep the r^2 a lower value, such as the default 0.3. The way it works is we step up in order of fit (until max order) and extend region every time when a fit reaches the specified r^2 threshold value. This can be controlled via the coef_threshold argument.
Solution: Adjust the coef_threshold value. Note that it’s highly recommended not to set a higher value than 0.6.

pysprint.core.methods.fftmethod module¶

class
FFTMethod
(*args, **kwargs)¶ Bases:
pysprint.core.bases.dataset.Dataset
Basic interface for the Fourier transform method.

__init__
(*args, **kwargs)¶ Base constructor for Dataset.
Parameters:  x (np.ndarray) – The x values.
 y (np.ndarray) – The y values.
 ref (np.ndarray, optional) – The reference arm’s spectra.
 sam (np.ndarray, optional) – The sample arm’s spectra.
 meta (dictlike) – The dictionary containing further information about the dataset. Can be extended, or set to be any valid ~collections.abc.Mapping.
 errors (str, optional) – Whether to raise on missmatching sized data. Must be “raise” or “force”. If “force” then truncate to the shortest size. Default is “raise”.
 callback (callable, optional) – The function that notifies parent objects about SPP related changes. In most cases the user should leave this empty. The default callback is only initialized if this object is constructed by the pysprint.SPPMethod object.
 parent (any class, optional) – The object which handles the callback function. In most cases the user should leave this empty.
 kwargs (dict, optional) – The window class to use in WFTMethod. Has no effect while using other methods. Must be a subclass of pysprint.core.windows.WindowBase.
Note
To load in data by files, see the other constructor parse_raw.

shift
(axis='x')¶ Equivalent to scipy.fftpack.fftshift, but it’s easier to use this function instead, because we don’t need to explicitly call the class’ x and y attribute.
Parameters:  axis (str) – Must be ‘x’, ‘y’, ‘both’, ‘xy’ or ‘yx’.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

ifft
(interpolate=True, usenifft=False, eps=1e12, exponent='positive')¶ Applies inverse Fast Fourier Transfrom to the dataset.
Parameters:  interpolate (bool, default is True  WILL BE REMOVED) – Whether to apply linear interpolation on the dataset before transforming.
 usenifft (bool, optional) – Whether to use non uniform fft. It uses the algorithm described in the references. This means the interferogram will not be linearly interpolated. Default is False.
 eps (float, optional) – The desired approximate error for the non uniform FFT result. Must be in range 1E33 < eps < 1E1, though be aware that the errors are only well calibrated near the range 1E12 ~ 1E6. Default is 1E12.
 exponent (str, optional) – if ‘negative’, compute the transform with a negative exponent. if ‘positive’, compute the transform with a positive exponent. Default is positive.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.
Note
The basic scheme is ifft > windowing > fft, so you should call these functions in this order. Otherwise the transforms may be inconsistent.
If numba is not installed the non uniform FTT is approximately 5x times slower, but still remains comparable to np.fft.ifft.
References
 [1] Dutt A., Rokhlin V. : Fast Fourier Transforms for Nonequispaced Data II,
 Applied and Computational Harmonic Analysis Volume 2, Issue 1, January 1995, Pages 85100 (1995)
 [2] Greengard, Leslie & Lee, JuneYub.: Accelerating the
 Nonuniform Fast Fourier Transform, Society for Industrial and Applied Mathematics. 46. 443454. 10.1137/S003614450343200X. (2004)

fft
()¶ Applies fft to the dataset. If ifft was not called first, inaccurate results might happen.
Parameters: inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

window
(at, fwhm, window_order=6, plot=True)¶ Draws a gaussian window on the plot with the desired parameters. The maximum value is adjusted for the dataset’s maximum value, mostly for visibility.
Parameters:  at (float) – The maximum of the gaussian curve.
 fwhm (float) – Full width at half maximum of the gaussian
 window_order (int, optional) – Order of the gaussian curve. If not even, it’s incremented by 1. Default is 6.
 plot (bool, optional) – Whether to immediately show the window with the data. Default is True.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

apply_window
()¶ If window function is set, applies window on the dataset.
Parameters: inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

build_phase
()¶ Retrieve only the phase after the transforms. This will unwrap the angles and constructs a ~pysprint.core.phase.Phase object.
Returns: phase – The phase object. See its docstring for more info. Return type: pysprint.core.phase.Phase

calculate
(reference_point, order, show_graph=False)¶ FFTMethod’s calculate function. It will unwrap the phase by changing deltas _between values to 2*pi complement. After that, fit a curve to determine dispersion coefficients.
Parameters:  reference_point (float) – The reference point on the x axis.
 order (int) – Polynomial (and maximum dispersion) order to fit. Must be in [1, 5].
 show_graph (bool, optional) – Shows a the final graph of the spectral phase and fitted curve. Default is False.
Returns:  dispersion (arraylike) – The dispersion coefficients in the form of: [GD, GDD, TOD, FOD, QOD, SOD]
 dispersion_std (arraylike) – Standard deviations due to uncertainty of the fit. It is only calculated if lmfit is installed. The form is: [GD_std, GDD_std, TOD_std, FOD_std, QOD_std, SOD_std]
 fit_report (str) – If lmfit is available returns the fit report, else returns an empty string.
Note
Decorated with pprint_disp, so the results are immediately printed without explicitly saying so.

autorun
(reference_point=None, order=None, *, enable_printing=False, skip_domain_check=False, only_phase=False, show_graph=True, usenifft=False)¶ Automatically run the Fourier Transfrom based evaluation on the dataset. It’s not as reliable as I want it to be, so use it carefully. I’m working on making it as competent and useful as possible.
Parameters:  reference_point (float, optional) – The reference point on the x axis. If not given, only_phase mode will be activated. Default is None.
 order (int, optional) – Polynomial (and maximum dispersion) order to fit. Must be in [1, 6]. If not given, only_phase mode will be activated. Default is None.
 only_phase (bool, optional) – If True, activate the only_phase mode, which will retrieve the phase without fitting a curve, and return a pysprint.core.Phase.phase object. Default is False (also not giving enough information for curve fitting will automatically activate it).
 enable_printing (bool, optional) – If True enable printing the detailed results. Default is False.
 skip_domain_check (bool, optional) – If True skip the interferogram domain check and force the algorithm to perform actions without changing domain. If False, check for potential wrong domains and change for an appropriate one. Default is False.
 show_graph (bool, optional) – If True show the graph with the phase and the fitted curve, if there is any. Default is True.
 usenifft (bool, optional) – If True use the Non Uniform Fast Fourier Transform algorithm. For more details see help(pysprint.FFTMethod.ifft). Default is False.
References
 [1] Dutt A., Rokhlin V. : Fast Fourier Transforms for Nonequispaced Data II,
 Applied and Computational Harmonic Analysis Volume 2, Issue 1, January 1995, Pages 85100 (1995)
 [2] Greengard, Leslie & Lee, JuneYub.: Accelerating the
 Nonuniform Fast Fourier Transform, Society for Industrial and Applied Mathematics. 46. 443454. 10.1137/S003614450343200X. (2004)

get_pulse_shape_from_array
(x_sample, y_sample, truncate=True, tol=None)¶ Find out the shape of the pulse in the time domain I(t).
Parameters:  x_sample (np.ndarray) – The x values of the sample arm.
 y_sample (np.ndarray) – The y values of the sample arm.
 truncate (bool, optional) – Whether to truncate the phase and sample spectra to the longest_common_subsequence (imeplemented at pysprint.core.bases.algorithms). Default is True.
 tol (float or None, optional) – The tolerance which determines how big difference is allowed _between x values to interpret them as the same datapoint.

get_pulse_shape_from_file
(filename, truncate=True, tol=None, **kwargs)¶ Find out the shape of the pulse in the time domain I(t). The sample arm’s spectra is loaded from file.
Parameters:  filename (str) – The file containing the sample arm’s spectra.
 truncate (bool, optional) – Whether to truncate the phase and sample spectra to the longest_common_subsequence (imeplemented at pysprint.core.bases.algorithms). Default is True.
 tol (float or None, optional) – The tolerance which determines how big difference is allowed _between x values to interpret them as the same datapoint.
 kwargs (dict, optional) – The additional keyword arguments for parsing. Same as pysprint.Dataset.parse_raw. If chdomain=True, then change the domain after loading.

errorplot
(*args, **kwargs)¶ Plot the errors of fitting.
Parameters:  ax (matplotlib.axes.Axes, optional) – An axis to draw the plot on. If not given, it will plot of the last used axis.
 percent (bool, optional) – Whether to plot percentage difference. Default is False.
 title (str, optional) – The title of the plot. Default is “Errors”.
 kwargs (dict, optional) – Additional keyword arguments to pass to plot function.

get_phase
¶ Return the phase if it is already calculated.

errors
¶ Return the fitting errors as np.ndarray.

resample
(N, kind='linear', **kwds)¶ Resample the interferogram to have N datapoints.
Parameters:  N (int) – The number of datapoints required.
 kind (str, optional) – The type of interpolation to use. Default is linear.
 kwds (optional) – Additional keyword argument to pass to scipy.interpolate.interp1d.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.
Raises: PySprintWarning, if trying to subsample to lower N datapoints than original.

pysprint.core.methods.generator module¶

class
Generator
(start, stop, center, delay=0, GD=0, GDD=0, TOD=0, FOD=0, QOD=0, SOD=0, resolution=0.1, pulse_width=10, normalize=False, chirp=0)¶ Bases:
object
Basic dataset generator.

__init__
(start, stop, center, delay=0, GD=0, GDD=0, TOD=0, FOD=0, QOD=0, SOD=0, resolution=0.1, pulse_width=10, normalize=False, chirp=0)¶ Initialize self. See help(type(self)) for accurate signature.

generate
(force_wavelength=False)¶ Intelligently (kind of) decide what domain we generate the dataset on.

generate_freq
()¶ Use this to generate the spectrogram in ang. frequency domain.

generate_wave
()¶ Use this to generate the spectrogram in wavelength domain.

GD_lookup
()¶

show
()¶ Draws the plot of the generated data.

save
(name, path=None)¶ Saves the generated dataset with numpy.savetxt.
Parameters:  name (string) – Name of the output file. You shouldn’t include the .txt at the end.
 path (string, default is None) – You can also specify the save path. e.g path=’C:/examplefolder’

phase_graph
()¶ Plots the spectrogram along with the spectral phase.

data
¶ Unpacks the generated data. If arms are given it returns x, y, reference_y, sample_y Else returns x, y

pysprint.core.methods.minmax module¶

class
MinMaxMethod
(*args, **kwargs)¶ Bases:
pysprint.core.bases.dataset.Dataset
Interface for MinimumMaximum Method.

__init__
(*args, **kwargs)¶ Base constructor for Dataset.
Parameters:  x (np.ndarray) – The x values.
 y (np.ndarray) – The y values.
 ref (np.ndarray, optional) – The reference arm’s spectra.
 sam (np.ndarray, optional) – The sample arm’s spectra.
 meta (dictlike) – The dictionary containing further information about the dataset. Can be extended, or set to be any valid ~collections.abc.Mapping.
 errors (str, optional) – Whether to raise on missmatching sized data. Must be “raise” or “force”. If “force” then truncate to the shortest size. Default is “raise”.
 callback (callable, optional) – The function that notifies parent objects about SPP related changes. In most cases the user should leave this empty. The default callback is only initialized if this object is constructed by the pysprint.SPPMethod object.
 parent (any class, optional) – The object which handles the callback function. In most cases the user should leave this empty.
 kwargs (dict, optional) – The window class to use in WFTMethod. Has no effect while using other methods. Must be a subclass of pysprint.core.windows.WindowBase.
Note
To load in data by files, see the other constructor parse_raw.

init_edit_session
(engine='normal', **kwargs)¶ Function to initialize peak editing on a plot. Right clicks (d key later) will delete the closest point, left clicks(i key later) will add a new point. Just close the window when finished. Must be called with interactive backend. The best practice is to call this function inside ~pysprint.interactive context manager.
Parameters:  engine (str, optional) – Must be ‘cwt’, ‘normal’ or ‘slope’. Peak detection algorithm to use. Default is normal.
 kwargs (dict, optional) – pmax, pmin, threshold, except_around, width

calculate
(reference_point, order, SPP_callbacks=None, show_graph=False, scan=False, onesided=False)¶ MinMaxMethod’s calculate function.
Parameters:  reference_point (float) – reference point on x axis
 order (int) – Polynomial (and maximum dispersion) order to fit. Must be in [1, 5].
 SPP_callbacks (number, or numeric listlike) – The positions of SPP’s on the interferogram. If not given it will check if there’s any SPP position set on the object.
 show_graph (bool, optional) – Shows a the final graph of the spectral phase and fitted curve. Default is False.
 onesided (bool) – Use only minimums or maximums to build the phase. It also works for one characteristic point per oscillation period (e.g. zerocrossings). Default is False.
Returns:  dispersion (arraylike) – [GD, GDD, TOD, FOD, QOD, SOD]
 dispersion_std (arraylike) – Standard deviations due to uncertainty of the fit. They are only calculated if lmfit is installed. [GD_std, GDD_std, TOD_std, FOD_std, QOD_std, SOD_std]
 fit_report (str) – lmfit report if installed, else empty string.
Note
Decorated with pprint_disp, so the results are immediately printed without explicitly saying so.

build_phase
(reference_point, SPP_callbacks=None, onesided=False)¶ Build only the phase using reference point and SPP positions.
Parameters:  reference_point (float) – The reference point from where the phase building starts.
 SPP_callbacks (number, or numeric listlike) – The positions of SPP’s on the interferogram. If not given it will check if there’s any SPP position set on the object.
 onesided (bool) – If True, use only the minimums or maximums to build the phase. It also works for one characteristic point per oscillation period (e.g. zerocrossings). Default is False.
Returns: phase – The phase object. See its docstring for more info.
Return type: pysprint.core.phase.Phase

pysprint.core.methods.spp_interface module¶

class
SPPMethod
(ifg_names, sam_names=None, ref_names=None, errors='raise', implements=None, **kwargs)¶ Bases:
object
Interface for Stationary Phase Point Method.

__init__
(ifg_names, sam_names=None, ref_names=None, errors='raise', implements=None, **kwargs)¶ SPPMethod constructor.
Parameters:  ifg_names (list) – The list containing the filenames of the interferograms.
 sam_names (list, optional) – The list containing the filenames of the sample arm’s spectra.
 ref_names (list, optinal) – The list containing the filenames of the reference arm’s spectra.
 errors (str, optional) – Whether to raise errors or silently pass. Default is “raise”.
 implements (object, optional) – The method class that each interferogram implements. Must be a subclass of pysprint.Dataset.
 kwargs – Additional keyword arguments to pass to parse_raw function.

classmethod
from_pattern
(pattern, mod=None, **kwargs)¶ Load all files matching a pattern, then optinally sort them by modulo 3 if there are arms’ spectra.
Parameters:  pattern (str) – The pattern to match. For example to load all txt files in the current directory, use “*.txt”.
 mod (int, optional) – The modulus to sort files by. Set this option to 3 if you have consecutive measurements, which contain arms’ spectra. The option mod = 1 will group by modulo 3, but it will only include every third file.
 kwargs – Additional keyword arguments for the original constructor, for example loading options.

classmethod
from_log
(logfile, **kwargs)¶ Restore a checkpoint from logfile. It creates MimickedDataset objects, which has no xy values set, only contains delay and SPP position values. These values can be set without restrictions.
Parameters:  logfile (str) – The logfile created by pysprint with verbosity level 1 or greater.
 kwargs (optional) – Additional keyword arguments to pass to MimickedDataset (for example callback might be important).

transform_delay
(func, *args, **kwargs)¶ Transform the delay values of the evaluation.
Parameters: func (callable) – The function which maps old delay to new delay values. It’s first argument must be x.

append
(newifg, newsam=None, newref=None)¶ Append a new interferogram to the object.

static
calculate_from_ifg
(ifg_list, reference_point, order, show_graph=False)¶ Collect SPP data from a list of pysprint.Dataset or child objects and evaluate them.
Parameters:  ifg_list (list) – The list containing the interferograms. All member should be pysprint.Dataset or child class type, otherwise TypeError is raised.
 reference_point (float) – The reference point on the x axis.
 order (int) – Maximum dispersion order to look for. Must be in [2, 6].
 show_graph (bool, optional) – Shows a the final graph of the spectral phase and fitted curve. Default is False.
Returns:  dispersion (arraylike) – The dispersion coefficients in the form of: [GD, GDD, TOD, FOD, QOD, SOD]
 dispersion_std (arraylike) – Standard deviations due to uncertainty of the fit. It is only calculated if lmfit is installed. The form is: [GD_std, GDD_std, TOD_std, FOD_std, QOD_std, SOD_std]
 fit_report (str) – If lmfit is available returns the fit report, else returns an empty string.

flush
()¶ Reset the state of recorded delays and positions, even on active objects that have been constructed on the runtime.

save_data
(filename)¶ Save the currectly stored SPP data.
Parameters: filename (str) – The filename to save as. If not ends with “.txt” it’s appended by default.

static
calculate_from_raw
(omegas, delays, reference_point, order, show_graph=False)¶ Calculate the dispersion from matching pairs of delays and SPP positions.
Parameters:  omegas (np.ndarray) – The SPP positions.
 delays (np.ndarray) – The delay values in fs.
 reference_point (float) – The reference point on the x axis.
 order (int) – Maximum dispersion order to look for. Must be in [2, 6].
 show_graph (bool, optional) – Whether to show the fitting.
Returns:  dispersion (arraylike) – The dispersion coefficients in the form of: [GD, GDD, TOD, FOD, QOD, SOD]
 dispersion_std (arraylike) – Standard deviations due to uncertainty of the fit. It is only calculated if lmfit is installed. The form is: [GD_std, GDD_std, TOD_std, FOD_std, QOD_std, SOD_std]
 fit_report (str) – If lmfit is available returns the fit report, else returns an empty string.

build_GD
()¶ Build the GD and return it. It will rebuild every time this function is called.

calculate
(reference_point, order, show_graph=False)¶ This function should be used after setting the SPP data in the interactive matplotlib editor or other way.
Parameters:  reference_point (float) – The reference point on the x axis.
 order (int, optional) – Maximum dispersion order to look for. Must be in [2, 6].
 show_graph (bool, optional) – Shows a the final graph of the spectral phase and fitted curve. Default is False.
Returns:  dispersion (arraylike) – The dispersion coefficients in the form of: [GD, GDD, TOD, FOD, QOD, SOD]
 dispersion_std (arraylike) – Standard deviations due to uncertainty of the fit. It is only calculated if lmfit is installed. The form is: [GD_std, GDD_std, TOD_std, FOD_std, QOD_std, SOD_std]
 fit_report (str) – If lmfit is available returns the fit report, else returns an empty string.

info
¶ Return how many interferograms were processed.

is_eager
¶ Returns if eager execution is enabled.

pysprint.core.methods.wft module¶

delayed
(func=None, *args, **kwargs)¶

class
WFTMethod
(*args, **kwargs)¶ Bases:
pysprint.core.methods.fftmethod.FFTMethod
Basic interface for Windowed Fourier Transform Method. The window_class attribute can be set up for custom windowing.

__init__
(*args, **kwargs)¶ Base constructor for Dataset.
Parameters:  x (np.ndarray) – The x values.
 y (np.ndarray) – The y values.
 ref (np.ndarray, optional) – The reference arm’s spectra.
 sam (np.ndarray, optional) – The sample arm’s spectra.
 meta (dictlike) – The dictionary containing further information about the dataset. Can be extended, or set to be any valid ~collections.abc.Mapping.
 errors (str, optional) – Whether to raise on missmatching sized data. Must be “raise” or “force”. If “force” then truncate to the shortest size. Default is “raise”.
 callback (callable, optional) – The function that notifies parent objects about SPP related changes. In most cases the user should leave this empty. The default callback is only initialized if this object is constructed by the pysprint.SPPMethod object.
 parent (any class, optional) – The object which handles the callback function. In most cases the user should leave this empty.
 kwargs (dict, optional) – The window class to use in WFTMethod. Has no effect while using other methods. Must be a subclass of pysprint.core.windows.WindowBase.
Note
To load in data by files, see the other constructor parse_raw.

add_window
(center, **kwargs)¶ Add a Gaussian window to the interferogram.
Parameters:  center (float) – The center of the Gaussian window.
 kwargs (dict) – Keyword arguments to pass to the window_class.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

windows
¶

centers
¶

add_window_generic
(array, **kwargs)¶ Build a window sequence of given parameters with centers specified with
array
argument.Parameters:  array (list, np.ndarray) – The array containing the centers of windows.
 kwargs (dict) – Keyword arguments to pass to the window_class.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

add_window_arange
(start, stop, step, **kwargs)¶ Build a window sequence of given parameters to apply on ifg. Works similar to numpy.arange.
Parameters:  start (float) – The start of the centers.
 stop (float) – The end value of the center
 step (float) – The step value to increment center.
 kwargs (dict) – Keyword arguments to pass to the window_class.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

add_window_linspace
(start, stop, num, **kwargs)¶ Build a window sequence of given parameters to apply on ifg. Works similar to numpy.linspace.
Parameters:  start (float) – The start of the centers.
 stop (float) – The end value of the center
 num (float) – The number of Gaussian windows.
 kwargs (dict) – Keyword arguments to pass to the window_class.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

add_window_geomspace
(start, stop, num, **kwargs)¶ Build a window sequence of given parameters to apply on ifg. Works similar to numpy.geomspace.
Parameters:  start (float) – The start of the centers.
 stop (float) – The end value of the center
 num (float) – The number of Gaussian windows.
 kwargs (dict) – Keyword arguments to pass to the window_class.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

view_windows
(ax=None, maxsize=80, **kwargs)¶ Gives a rough view of the different windows along with the ifg.
Parameters:  ax (matplotlib.axes.Axes, optional) – An axis to draw the plot on. If not given, it will plot of the last used axis.
 maxsize (int, optional) – The maximum number of Gaussian windows to display on plot. Default is 80, but be aware that setting a high value can drastically reduce performance.
 kwargs (dict, optional) – Additional keyword arguments to pass to plot function.

remove_all_windows
()¶ Remove all the Gaussian windows.
Parameters: inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

reset_state
()¶ Reset the object’s state fully: delete all the calculated GD, caches, heatmaps and window sequences.
Parameters: inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

remove_window_at
(center)¶ Removes a window at center.
Parameters:  center (float) – The center of the window to remove. Raises ValueError if there is not such window.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

remove_window_interval
(start, stop)¶ Remove window interval inclusively.
Parameters:  start (float) – The start value of the interval.
 stop (float) – The stop value of the interval.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

cover
(N, **kwargs)¶ Cover the whole domain with N number of windows uniformly built with the given parameters.
Parameters:  N (float) – The number of Gaussian windows.
 kwargs (dict) – Keyword arguments to pass to the window_class.
 inplace (bool, optional) – Whether to apply the operation on the dataset in an “inplace” manner. This means if inplace is True it will apply the changes directly on the current dataset and returns None. If inplace is False, it will leave the current object untouched, but returns a copy of it, and the operation will be performed on the copy. It’s useful when chaining operations on a dataset.

calculate
(reference_point, order, show_graph=False, silent=False, force_recalculate=False, fastmath=True, usenifft=False, parallel=False, ransac=False, errors='ignore', **kwds)¶ Calculates the dispersion.
Parameters:  reference_point (float) – The reference point.
 order (int) – The dispersion order to look for. Must be in [2, 6].
 show_graph (bool, optional) – Whether to show the GD graph on complete. Default is False.
 silent (bool, optional) – Whether to print progressbar. By default it will print.
 force_recalculate (bool, optional) – Force to recalculate the GD graph not only the curve fitting. Default is False.
 fastmath (bool, optional) – Whether to build additional arrays to display heatmap. Default is True.
 usenifft (bool, optional) – Whether to use Nonunifrom FFT when calculating GD. Default is False. Not stable.
 parallel (bool, optional) – Whether to use parallel computation. Only availabe if Dask is installed. The speedup is about 5070%. Default is False.
 ransac (bool, optional) – Whether to use RANSAC filtering on the detected peaks. Default is False.
 errors (str, optional) – Whether to raise an error is the algorithm couldn’t find the center of the peak. Default is “ignore”.
 kwds (optional) – Other keyword arguments to pass to RANSAC filter.
Raises:  ValueError, if no window sequence is added to the interferogram.
 ValueError, if order is 1.
 ModuleNotFoundError, if Dask is not available when using parallel=True.

build_GD
(silent=False, fastmath=True, usenifft=False, parallel=False, errors='ignore')¶ Build the GD.
Parameters:  silent (bool, optional) – Whether to print progressbar. By default it will print.
 fastmath (bool, optional) – Whether to build additional arrays to display heatmap. Default is True.
 usenifft (bool, optional) – Whether to use Nonunifrom FFT when calculating GD. Default is False. Not stable.
 parallel (bool, optional) – Whether to use parallel computation. Only availabe if Dask is installed. The speedup is about 5070%. Default is False.
 errors (str, optional) – Whether to raise an error is the algorithm couldn’t find the center of the peak.
Returns: GD – The phase object with GD_mode=True. See its docstring for more info.
Return type: pysprint.core.phase.Phase

build_phase
()¶ Retrieve only the phase after the transforms. This will unwrap the angles and constructs a ~pysprint.core.phase.Phase object.
Returns: phase – The phase object. See its docstring for more info. Return type: pysprint.core.phase.Phase

errorplot
(*args, **kwargs)¶ Plot the errors of fitting.
Parameters:  ax (matplotlib.axes.Axes, optional) – An axis to draw the plot on. If not given, it will plot of the last used axis.
 percent (bool, optional) – Whether to plot percentage difference. Default is False.
 title (str, optional) – The title of the plot. Default is “Errors”.
 kwargs (dict, optional) – Additional keyword arguments to pass to plot function.

get_GD
¶ Return the GD if it is already calculated.

errors
¶ Return the fitting errors as np.ndarray.

heatmap
(ax=None, levels=None, cmap='viridis', include_ridge=True)¶ Plot the heatmap.
Parameters:  ax (matplotlib.axes.Axes, optional) – An axis to draw the plot on. If not given, it will plot of the last used axis.
 levels (np.ndarray, optional) – The levels to use for plotting.
 cmap (str, optional) – The colormap to use.
 include_ridge (bool, optional) – Whether to mark the detected ridge of the plot. Default is True.

get_heatmap_data
()¶ Return the data which was used to create the heatmap.
Returns:  X_cont (np.ndarray) – The window centers with shape (n,).
 Y_cont (np.ndarray) – The time axis calculated from the IFFT of the dataset with shape (m,).
 Z_cont (np.ndarray) – 2D array with shape (m, n) containing the depth information.
