mass.core package¶
Submodules¶
mass.core.analysis_algorithms module¶
mass.core.analysis_algorithms - main algorithms used in data analysis
Designed to abstract certain key algorithms out of the class MicrocalDataSet and be able to run them fast.
Created on Jun 9, 2014
@author: fowlerj
- class mass.core.analysis_algorithms.FilterTimeCorrection(trainingPulses, promptness, energy, linearFilter, nPresamples, typicalResolution=None, labels=None, maxorder=6, verbose=0)¶
Bases:
object
Represent the phase-dependent correction to a filter, based on running model pulses through the filter. Developed November 2013 to June 2014.
Unlike a phase-appropriate filter approach, the idea here is that all pulses will be passed through the same filter. This object studies the systematics that results and attempts to find a good correction for them
WARNING: This seems to work great on calibronium data (4 to 8 keV with lines) on the Tupac system, but it didn’t do so well on Mn fluorescence in Dixie’s 2011 snout with best-ever TDM-8. This is a work in progress.
- copy()¶
Return a new object with all the properties of this
- plot_corrections(center_x=True, scale_x=True)¶
- class mass.core.analysis_algorithms.HistogramSmoother(smooth_sigma, limits)¶
Bases:
object
Object that can repeatedly smooth histograms with the same bin count and width to the same Gaussian width. By pre-computing the smoothing kernel for that histogram, we can smooth multiple histograms with the same geometry.
- mass.core.analysis_algorithms.compute_max_deriv(pulse_data, ignore_leading, spike_reject=True, kernel=None)¶
Computes the maximum derivative in timeseries <pulse_data>. <pulse_data> can be a 2D array where each row is a different pulse record, in which case the return value will be an array last long as the number of rows in <pulse_data>.
- Args:
pulse_data: ignore_leading: spike_reject: (default True) kernel: the linear filter against which the signals will be convolved
(CONVOLED, not correlated, so reverse the filter as needed). If None, then the default kernel of [+.2 +.1 0 -.1 -.2] will be used. If “SG”, then the cubic 5-point Savitzky-Golay filter will be used (see below). Otherwise, kernel needs to be a (short) array which will be converted to a 1xN 2-dimensional np.ndarray. (default None)
- Returns:
An np.ndarray, dimension 1: the value of the maximum derivative (units of <pulse_data units> per sample).
When kernel==”SG”, then we estimate the derivative by Savitzky-Golay filtering (with 1 point before/3 points after the point in question and fitting polynomial of order 3). Find the right general area by first doing a simple difference.
- mass.core.analysis_algorithms.correct_flux_jumps(vals, g, flux_quant)¶
Remove ‘flux’ jumps’ from pretrigger mean.
When using umux readout, if a pulse is recorded that has a very fast rising edge (e.g. a cosmic ray), the readout system will “slip” an integer number of flux quanta. This means that the baseline level returned to after the pulse will different from the pretrigger value by an integer number of flux quanta. This causes that pretrigger mean summary quantity to jump around in a way that causes trouble for the rest of MASS. This function attempts to correct these jumps.
Arguments: vals – array of values to correct g – mask indentifying “good” pulses flux_quant – size of 1 flux quanta
Returns: Array with values corrected
- mass.core.analysis_algorithms.drift_correct(indicator, uncorrected, limit=None)¶
Compute a drift correction that minimizes the spectral entropy.
- Args:
indicator: The “x-axis”, which indicates the size of the correction. uncorrected: A filtered pulse height vector. Same length as indicator.
Assumed to have some gain that is linearly related to indicator.
- limit: The upper limit of uncorrected values over which entropy is
computed (default None).
Generally indicator will be the pretrigger mean of the pulses, but you can experiment with other choices.
The entropy will be computed on corrected values only in the range [0, limit], so limit should be set to a characteristic large value of uncorrected. If limit is None (the default), then in will be compute as 25% larger than the 99%ile point of uncorrected.
The model is that the filtered pulse height PH should be scaled by (1 + a*PTM) where a is an arbitrary parameter computed here, and PTM is the difference between each record’s pretrigger mean and the median value of all pretrigger means. (Or replace “pretrigger mean” with whatever quantity you passed in as <indicator>.)
- mass.core.analysis_algorithms.estimateRiseTime(pulse_data, timebase, nPretrig)¶
Computes the rise time of timeseries <pulse_data>, where the time steps are <timebase>. <pulse_data> can be a 2D array where each row is a different pulse record, in which case the return value will be an array last long as the number of rows in <pulse_data>.
If nPretrig >= 4, then the samples pulse_data[:nPretrig] are averaged to estimate the baseline. Otherwise, the minimum of pulse_data is assumed to be the baseline.
Specifically, take the first and last of the rising points in the range of 10% to 90% of the peak value, interpolate a line between the two, and use its slope to find the time to rise from 0 to the peak.
See also mass.nonstandard.deprecated.fitExponentialRiseTime for a more traditional (and computationally expensive) definition.
- Args:
- pulse_data: An np.ndarray of dimension 1 (a single pulse record) or 2 (an
array with each row being a pulse record).
timebase: The sampling time. nPretrig: The number of samples that are recorded before the trigger.
- Returns:
An ndarray of dimension 1, giving the rise times.
- mass.core.analysis_algorithms.filter_data_5lag_cython(const unsigned short[:, :] rawdata, double[:] filter_values, int pulses_per_seg=0)¶
Filter the complete data file one chunk at a time.
- mass.core.analysis_algorithms.filter_signal_lowpass(sig, fs, fcut)¶
Tophat lowpass filter using an FFT
- Args:
sig - the signal to be filtered fs - the sampling frequency of the signal fcut - the frequency at which to cutoff the signal
- Returns:
the filtered signal
- mass.core.analysis_algorithms.make_smooth_histogram(values, smooth_sigma, limit, upper_limit=None)¶
Convert a vector of arbitrary <values> info a smoothed histogram by histogramming it and smoothing.
This is a convenience function using the HistogramSmoother class.
- Args:
values: The vector of data to be histogrammed. smooth_sigma: The smoothing Gaussian’s width (FWHM) limit, upper_limit: The histogram limits are [limit,upper_limit] or
[0,limit] if upper_limit is None.
- Returns:
The smoothed histogram as an array.
- mass.core.analysis_algorithms.nearest_arrivals(long long[:] pulse_timestamps, long long[:] external_trigger_timestamps)¶
Find the external trigger time immediately before and after each pulse timestamp
- Args:
- pulse_timestamps - 1d array of pulse timestamps whose nearest neighbors
need to be found.
external_trigger_timestamps - 1d array of possible nearest neighbors.
- Returns:
(before_times, after_times)
before_times is an ndarray of the same size as pulse_timestamps. before_times[i] contains the difference between the closest lesser time contained in external_trigger_timestamps and pulse_timestamps[i] or inf if there was no earlier time in other_times Note that before_times is always a positive number even though the time difference it represents is negative.
after_times is an ndarray of the same size as pulse_timestamps. after_times[i] contains the difference between pulse_timestamps[i] and the closest greater time contained in other_times or a inf number if there was no later time in external_trigger_timestamps.
- mass.core.analysis_algorithms.python_compute_max_deriv(pulse_data, ignore_leading, spike_reject=True, kernel=None)¶
Equivalent to compute_max_deriv(…)
- mass.core.analysis_algorithms.python_nearest_arrivals(reference_times, other_times)¶
Identical to nearest_arrivals(…).
mass.core.channel module¶
Single-channel classes:
NoiseRecords: encapsulate a file with noise records
PulseRecords: encapsulate a file with pulse records
MicrocalDataSet: encapsulate basically everything about 1 channel’s pulses and noise
- class mass.core.channel.GroupLooper[source]¶
Bases:
object
A mixin class to allow TESGroup objects to hold methods that loop over their constituent channels. (Has to be a mixin, in order to break the import cycle that would otherwise occur.)
- apply_cuts(*args, **kwargs)¶
Loop over self, calling the apply_cuts(…) method for each channel.
apply_cuts(self, controls, clear=False, forceNew=True) docstring reads: Apply the cuts.
- Args:
controls (AnalysisControl): contains the cuts to apply. clear (bool): Whether to clear previous cuts first (default False). forceNew (bool): whether to recompute if it already exists (default False).
- assume_white_noise(*args, **kwargs)¶
Loop over self, calling the assume_white_noise(…) method for each channel.
assume_white_noise(self, noise_variance=1.0, forceNew=False) docstring reads: Set the noise variance to noise_variance and the spectrum to be white.
This is appropriate when no noise files were taken. Though you may set noise_variance to a value other than 1, this will affect only the predicted resolution, and will not change the optimal filters that get computed/used.
- Args:
noise_variance(number): what to set as the lag-0 noise autocorrelation. forceNew (bool): whether to update the noise autocorrelation if it’s already
been set (default False).
- auto_cuts(*args, **kwargs)¶
Loop over self, calling the auto_cuts(…) method for each channel.
auto_cuts(self, nsigma_pt_rms=8.0, nsigma_max_deriv=8.0, pretrig_rms_percentile=None, forceNew=False, clearCuts=True) docstring reads: Compute and apply an appropriate set of automatically generated cuts.
The peak time and rise time come from the measured most-common peak time. The pulse RMS and postpeak-derivative cuts are based on what’s observed in the (presumably) pulse-free noise file associated with this data file.
- Args:
- nsigma_pt_rms (float): How big an excursion is allowed in pretrig RMS
(default 8.0).
- nsigma_max_deriv (float): How big an excursion is allowed in max
post-peak derivative (default 8.0).
- pretrig_rms_percentile (float): Make upper limit for pretrig_rms at
least as large as this percentile of the data. I.e., if you pass in 99, then the upper limit for pretrig_rms will exclude no more than the 1 % largest values. This number is a percentage, not a fraction. This should not be routinely used - it is intended to help auto_cuts work even if there is a problem during a data acquisition that causes large drifts in noise properties.
forceNew (bool): Whether to perform auto-cuts even if cuts already exist. clearCuts (bool): Whether to clear any existing cuts first (default
True).
The two excursion limits are given in units of equivalent sigma from the noise file. “Equivalent” meaning that the noise file was assessed not for RMS but for median absolute deviation, normalized to Gaussian distributions.
- Returns:
The cut object that was applied.
- avg_pulses_auto_masks(*args, **kwargs)¶
Loop over self, calling the avg_pulses_auto_masks(…) method for each channel.
avg_pulses_auto_masks(self, max_pulses_to_use=7000, subtract_mean=True, forceNew=False) docstring reads: Compute an average pulse.
Compute average pulse using an automatically generated mask of +- 5%% around the median pulse_average value.
- Args:
- max_pulses_to_use (int): Use no more than
the first this many good pulses (default 7000).
forceNew (bool): whether to re-compute if results already exist (default False)
- calibrate(*args, **kwargs)¶
Loop over self, calling the calibrate(…) method for each channel.
calibrate(self, attr, line_names, name_ext=’’, size_related_to_energy_resolution=10, fit_range_ev=200, excl=(), plot_on_fail=False, bin_size_ev=2.0, category={}, forceNew=False, maxacc=0.015, nextra=3, param_adjust_closure=None, curvetype=’gain’, approximate=False, diagnose=False) has no docstring
- clear_cuts(*args, **kwargs)¶
Loop over self, calling the clear_cuts(…) method for each channel.
clear_cuts(self) docstring reads: Clear all cuts.
- compute_5lag_filter(*args, **kwargs)¶
Loop over self, calling the compute_5lag_filter(…) method for each channel.
compute_5lag_filter(self, fmax=None, f_3db=None, cut_pre=0, cut_post=0, category={}, forceNew=False) docstring reads: Requires that compute_noise has been run and that average pulse has been computed
- compute_ats_filter(*args, **kwargs)¶
Loop over self, calling the compute_ats_filter(…) method for each channel.
compute_ats_filter(self, fmax=None, f_3db=None, transform=None, cut_pre=0, cut_post=0, category={}, shift1=True, forceNew=False, minimum_n_pulses=20, maximum_n_pulses=4000, optimize_dp_dt=True) docstring reads: Compute a arrival-time-safe filter to model the pulse and its time-derivative.
Requires that compute_noise has been run.
- Args:
- fmax: if not None, the hard cutoff in frequency space, above which
the DFT of the filter will be set to zero (default None)
- f_3db: if not None, the 3 dB rolloff point in frequency space, above which
the DFT of the filter will rolled off with a 1-pole filter (default None)
- transform: a callable object that will be called on all data records
before filtering (default None)
- optimize_dp_dt: bool, try a more elaborate approach to dp_dt than just the finite
difference (works well for x-ray, bad for gamma rays)
cut_pre: Cut this many samples from the start of the filter, giving them 0 weight. cut_post: Cut this many samples from the end of the filter, giving them 0 weight. shift1: Potentially shift each pulse by one sample based on ds.shift1 value, resulting filter is one sample shorter than pulse records. If you used a zero threshold trigger (eg dastard egdeMulti you can likely use shift1=False)
- Returns:
the filter (an ndarray)
Modified in April 2017 to make the model for the rising edge and the rest of the pulse differently. For the rising edge, we use entropy minimization to understand the pulse shape dependence on arrival-time. For the rest of the pulse, it is less noisy and in fact more robust to rely on the finite-difference of the pulse average to get the arrival-time dependence.
- compute_noise(*args, **kwargs)¶
Loop over self, calling the compute_noise(…) method for each channel.
compute_noise(self, max_excursion=1000, forceNew=False) docstring reads: Compute the noise autocorrelation and power spectrum of this channel.
- Args:
- max_excursion (number): the biggest excursion from the median allowed
in each data segment, or else it will be ignored (default 1000).
- n_lags: if not None, the number of lags in each noise spectrum and the max lag
for the autocorrelation. If None, the record length is used (default None).
forceNew (bool): whether to recompute if it already exists (default False).
- compute_noise_nlags(*args, **kwargs)¶
Loop over self, calling the compute_noise_nlags(…) method for each channel.
compute_noise_nlags(self, n_lags, max_excursion=1000, plot=False) docstring reads: Compute the noise autocorrelation and power spectrum of this channel using records of length nlags.
Treats data in separate noise traces as continuous.
- Args:
- max_excursion (number): the biggest excursion from the median allowed
in each data segment, or else it will be ignored (default 1000).
- n_lags: if not None, the number of lags in each noise spectrum and the max lag
for the autocorrelation. If None, the record length is used (default None).
forceNew (bool): whether to recompute if it already exists (default False).
- compute_noise_spectra(*args, **kwargs)¶
Loop over self, calling the compute_noise_spectra(…) method for each channel.
compute_noise_spectra(self, max_excursion=1000, n_lags=None, forceNew=False) docstring reads: Replaced by the equivalent compute_noise(…)
Deprecated since version 0.7.9: Use compute_noise(), which is equivalent but better named
- convert_to_energy(*args, **kwargs)¶
Loop over self, calling the convert_to_energy(…) method for each channel.
convert_to_energy(self, attr, calname=None) has no docstring
- drift_correct(*args, **kwargs)¶
Loop over self, calling the drift_correct(…) method for each channel.
drift_correct(self, attr=’p_filt_value’, forceNew=False, category={}) docstring reads: Drift correct using the standard entropy-minimizing algorithm
- filter_data(*args, **kwargs)¶
Loop over self, calling the filter_data(…) method for each channel.
filter_data(self, filter_name=’filt_noconst’, transform=None, forceNew=False, use_cython=None) docstring reads: Filter the complete data file one chunk at a time.
- Args:
- filter_name: the object under self.filter to use for filtering the
data records (default ‘filt_noconst’)
- transform: a callable object that will be called on all data records
before filtering (default None)
forceNew: Whether to recompute when already exists (default False)
- flag_crosstalking_pulses(*args, **kwargs)¶
Loop over self, calling the flag_crosstalking_pulses(…) method for each channel.
- flag_crosstalking_pulses(self, priorTime, postTime, combineCategories=True, nearestNeighborsDistances=1, crosstalk_key=’is_crosstalking’, forceNew=False) docstring reads:
- Uses a list of nearest neighbor channels to flag pulses in current channel based
on arrival times of pulses in neighboring channels
Args: priorTime (float): amount of time to check, in ms, before the pulse arrival time postTime (float): amount of time to check, in ms, after the pulse arrival time combineChannels (bool): whether to combine all neighboring channel pulses for flagging crosstalk nearestNeighborDistances (int or int array): nearest neighbor distances to use for flagging,
i.e. 1 = 1st nearest neighbors, 2 = 2nd nearest neighbors, etc.
forceNew (bool): whether to re-compute the crosstalk cuts (default False)
- phase_correct(*args, **kwargs)¶
Loop over self, calling the phase_correct(…) method for each channel.
phase_correct(self, attr=’p_filt_value_dc’, forceNew=False, category={}, ph_peaks=None, method2017=True, kernel_width=None, save_to_hdf5=True) docstring reads: Apply the 2017 or 2015 phase correction method.
- Args:
forceNew (bool): whether to recompute if it already exists (default False). category (dict): if not None, then a dict giving a category name and the
required category label.
ph_peaks: Peaks to use for alignment. If None, then use _find_peaks_heuristic() kernel_width: Width (in PH units) of the kernel-smearing function. If None, use a heuristic.
- phase_correct2014(*args, **kwargs)¶
Loop over self, calling the phase_correct2014(…) method for each channel.
phase_correct2014(self, typical_resolution, maximum_num_records=50000, plot=False, forceNew=False, category={}) docstring reads: Apply the phase correction that worked for calibronium-like data as of June 2014.
For more notes, do help(mass.core.analysis_algorithms.FilterTimeCorrection)
- Args:
- typical_resolution (number): should be an estimated energy resolution in UNITS OF
self.p_pulse_rms. This helps the peak-finding (clustering) algorithm decide which pulses go together into a single peak. Be careful to use a semi-reasonable quantity here.
- maximum_num_records (int): don’t use more than this many records to learn
the correction (default 50000).
plot (bool): whether to make a relevant plot forceNew (bool): whether to recompute if it already exists (default False). category (dict): if not None, then a dict giving a category name and the
required category label.
- set_nearest_neighbors_list(*args, **kwargs)¶
Loop over self, calling the set_nearest_neighbors_list(…) method for each channel.
- set_nearest_neighbors_list(self, mapFilename, nearestNeighborCategory=’physical’, distanceType=’cartesian’, forceNew=False) docstring reads:
Finds the nearest neighbors in a given space for all channels in a data set
Args: mapFilename (str): Location of map file in the following format
Column 0 - list of channel numbers. Remaining column(s) - coordinates that define a particular column in a given space.
For example, can be the row and column number in a physical space or the frequency order number in a frequency space (umux readout).
- nearestNeighborCategory (str): name used to categorize the type of nearest neighbor.
This will be the name given to the subgroup of the hdf5 file under the nearest_neighbor group. This will also be a key for dictionary nearest_neighbors_dictionary
distanceType (str): Type of distance to measure between nearest neighbors, i.e. cartesian forceNew (bool): whether to re-compute nearest neighbors list if it exists (default False)
- smart_cuts(*args, **kwargs)¶
Loop over self, calling the smart_cuts(…) method for each channel.
smart_cuts(self, threshold=10.0, n_trainings=10000, forceNew=False) docstring reads: Young! Why is there no doc string here??
- time_drift_correct(*args, **kwargs)¶
Loop over self, calling the time_drift_correct(…) method for each channel.
time_drift_correct(self, attr=’p_filt_value_phc’, sec_per_degree=2000, pulses_per_degree=2000, max_degrees=20, forceNew=False, category={}) docstring reads: Drift correct over long times with an entropy-minimizing algorithm.
Here we correct as a low-ish-order Legendre polynomial in time.
- attr: the attribute of self that is to be corrected. (The result
will be stored in self.p_filt_value_tdc[:]).
sec_per_degree: assign as many as one polynomial degree per this many seconds pulses_per_degree: assign as many as one polynomial degree per this many pulses max_degrees: never use more than this many degrees of Legendre polynomial.
forceNew: whether to do this step, if it appears already to have been done. category: choices for categorical cuts
- class mass.core.channel.MicrocalDataSet(pulserec_dict, tes_group=None, hdf5_group=None)[source]¶
Bases:
object
Represent a single microcalorimeter’s PROCESSED data.
- HDF5_CHUNK_SIZE = 256¶
- apply_cuts(controls, clear=False, forceNew=True)[source]¶
Apply the cuts.
- Args:
controls (AnalysisControl): contains the cuts to apply. clear (bool): Whether to clear previous cuts first (default False). forceNew (bool): whether to recompute if it already exists (default False).
- assume_white_noise(noise_variance=1.0, forceNew=False)[source]¶
Set the noise variance to noise_variance and the spectrum to be white.
This is appropriate when no noise files were taken. Though you may set noise_variance to a value other than 1, this will affect only the predicted resolution, and will not change the optimal filters that get computed/used.
- Args:
noise_variance(number): what to set as the lag-0 noise autocorrelation. forceNew (bool): whether to update the noise autocorrelation if it’s already
been set (default False).
- auto_cuts(nsigma_pt_rms=8.0, nsigma_max_deriv=8.0, pretrig_rms_percentile=None, forceNew=False, clearCuts=True)[source]¶
Compute and apply an appropriate set of automatically generated cuts.
The peak time and rise time come from the measured most-common peak time. The pulse RMS and postpeak-derivative cuts are based on what’s observed in the (presumably) pulse-free noise file associated with this data file.
- Args:
- nsigma_pt_rms (float): How big an excursion is allowed in pretrig RMS
(default 8.0).
- nsigma_max_deriv (float): How big an excursion is allowed in max
post-peak derivative (default 8.0).
- pretrig_rms_percentile (float): Make upper limit for pretrig_rms at
least as large as this percentile of the data. I.e., if you pass in 99, then the upper limit for pretrig_rms will exclude no more than the 1 % largest values. This number is a percentage, not a fraction. This should not be routinely used - it is intended to help auto_cuts work even if there is a problem during a data acquisition that causes large drifts in noise properties.
forceNew (bool): Whether to perform auto-cuts even if cuts already exist. clearCuts (bool): Whether to clear any existing cuts first (default
True).
The two excursion limits are given in units of equivalent sigma from the noise file. “Equivalent” meaning that the noise file was assessed not for RMS but for median absolute deviation, normalized to Gaussian distributions.
- Returns:
The cut object that was applied.
- avg_pulses_auto_masks(max_pulses_to_use=7000, subtract_mean=True, forceNew=False)[source]¶
Compute an average pulse.
Compute average pulse using an automatically generated mask of +- 5%% around the median pulse_average value.
- Args:
- max_pulses_to_use (int): Use no more than
the first this many good pulses (default 7000).
forceNew (bool): whether to re-compute if results already exist (default False)
- bad(*args, **kwargs)[source]¶
Returns a boolean vector, one per pulse record, saying whether record is bad
- calibrate(attr, line_names, name_ext='', size_related_to_energy_resolution=10, fit_range_ev=200, excl=(), plot_on_fail=False, bin_size_ev=2.0, category={}, forceNew=False, maxacc=0.015, nextra=3, param_adjust_closure=None, curvetype='gain', approximate=False, diagnose=False)[source]¶
- compute_5lag_filter(fmax=None, f_3db=None, cut_pre=0, cut_post=0, category={}, forceNew=False)[source]¶
Requires that compute_noise has been run and that average pulse has been computed
- compute_ats_filter(fmax=None, f_3db=None, transform=None, cut_pre=0, cut_post=0, category={}, shift1=True, forceNew=False, minimum_n_pulses=20, maximum_n_pulses=4000, optimize_dp_dt=True)[source]¶
Compute a arrival-time-safe filter to model the pulse and its time-derivative. Requires that compute_noise has been run.
- Args:
- fmax: if not None, the hard cutoff in frequency space, above which
the DFT of the filter will be set to zero (default None)
- f_3db: if not None, the 3 dB rolloff point in frequency space, above which
the DFT of the filter will rolled off with a 1-pole filter (default None)
- transform: a callable object that will be called on all data records
before filtering (default None)
- optimize_dp_dt: bool, try a more elaborate approach to dp_dt than just the finite
difference (works well for x-ray, bad for gamma rays)
cut_pre: Cut this many samples from the start of the filter, giving them 0 weight. cut_post: Cut this many samples from the end of the filter, giving them 0 weight. shift1: Potentially shift each pulse by one sample based on ds.shift1 value, resulting filter is one sample shorter than pulse records. If you used a zero threshold trigger (eg dastard egdeMulti you can likely use shift1=False)
- Returns:
the filter (an ndarray)
Modified in April 2017 to make the model for the rising edge and the rest of the pulse differently. For the rising edge, we use entropy minimization to understand the pulse shape dependence on arrival-time. For the rest of the pulse, it is less noisy and in fact more robust to rely on the finite-difference of the pulse average to get the arrival-time dependence.
- compute_average_pulse(mask, subtract_mean=True, forceNew=False)[source]¶
Compute the average pulse this channel.
Store as self.average_pulse
- Args:
mask – A boolean array saying which records to average. subtract_mean – Whether to subtract the pretrigger mean and set the
pretrigger period to strictly zero (default True).
forceNew – Whether to recompute when already exists (default False)
- compute_noise(max_excursion=1000, forceNew=False)[source]¶
Compute the noise autocorrelation and power spectrum of this channel.
- Args:
- max_excursion (number): the biggest excursion from the median allowed
in each data segment, or else it will be ignored (default 1000).
- n_lags: if not None, the number of lags in each noise spectrum and the max lag
for the autocorrelation. If None, the record length is used (default None).
forceNew (bool): whether to recompute if it already exists (default False).
- compute_noise_nlags(n_lags, max_excursion=1000, plot=False)[source]¶
Compute the noise autocorrelation and power spectrum of this channel using records of length nlags. Treats data in separate noise traces as continuous.
- Args:
- max_excursion (number): the biggest excursion from the median allowed
in each data segment, or else it will be ignored (default 1000).
- n_lags: if not None, the number of lags in each noise spectrum and the max lag
for the autocorrelation. If None, the record length is used (default None).
forceNew (bool): whether to recompute if it already exists (default False).
- compute_noise_spectra(max_excursion=1000, n_lags=None, forceNew=False)[source]¶
Replaced by the equivalent compute_noise(…)
Deprecated since version 0.7.9: Use compute_noise(), which is equivalent but better named
- correct_flux_jumps(flux_quant)[source]¶
Remove ‘flux’ jumps’ from pretrigger mean.
When using umux readout, if a pulse is recorded that has a very fast rising edge (e.g. a cosmic ray), the readout system will “slip” an integer number of flux quanta. This means that the baseline level returned to after the pulse will different from the pretrigger value by an integer number of flux quanta. This causes that pretrigger mean summary quantity to jump around in a way that causes trouble for the rest of MASS. This function attempts to correct these jumps.
Arguments: flux_quant – size of 1 flux quantum
- drift_correct(attr='p_filt_value', forceNew=False, category={})[source]¶
Drift correct using the standard entropy-minimizing algorithm
- expected_attributes = ('nSamples', 'nPresamples', 'nPulses', 'timebase', 'channum', 'timestamp_offset')¶
- filter_data(filter_name='filt_noconst', transform=None, forceNew=False, use_cython=None)[source]¶
Filter the complete data file one chunk at a time.
- Args:
- filter_name: the object under self.filter to use for filtering the
data records (default ‘filt_noconst’)
- transform: a callable object that will be called on all data records
before filtering (default None)
forceNew: Whether to recompute when already exists (default False)
- first_n_good_pulses(n=50000, category={})[source]¶
Return the first good pulse records.
- Args:
n: maximum number of good pulses to include (default 50000).
- Returns:
(data, g) data is a (X,Y) array where X is number of records, and Y is number of samples per record g is a 1d array of of pulse record numbers of the pulses in data.
If we did load all of ds.data at once, this would be roughly equivalent to return ds.data[ds.cuts.good()][:n], np.nonzero(ds.cuts.good())[0][:n]
- fit_spectral_line(prange, mask=None, times=None, fit_type='dc', line='MnKAlpha', nbins=200, plot=True, **kwargs)[source]¶
- flag_crosstalking_pulses(priorTime, postTime, combineCategories=True, nearestNeighborsDistances=1, crosstalk_key='is_crosstalking', forceNew=False)[source]¶
Uses a list of nearest neighbor channels to flag pulses in current channel based on arrival times of pulses in neighboring channels
Args: priorTime (float): amount of time to check, in ms, before the pulse arrival time postTime (float): amount of time to check, in ms, after the pulse arrival time combineChannels (bool): whether to combine all neighboring channel pulses for flagging crosstalk nearestNeighborDistances (int or int array): nearest neighbor distances to use for flagging,
i.e. 1 = 1st nearest neighbors, 2 = 2nd nearest neighbors, etc.
forceNew (bool): whether to re-compute the crosstalk cuts (default False)
- get_pulse_model(f, f_5lag, n_basis, pulses_for_svd, extra_n_basis_5lag=0, maximum_n_pulses=4000, noise_weight_basis=True, category={})[source]¶
- good(*args, **kwargs)[source]¶
Returns a boolean vector, one per pulse record, saying whether record is good
- hist(bin_edges, attr='p_energy', t0=0, tlast=1e+20, category={}, g_func=None)[source]¶
return a tuple of (bin_centers, counts) of p_energy of good pulses (or another attribute).
Automatically filtes out nan values
Parameters¶
- bin_edges_type_
edges of bins unsed for histogram
- attrstr, optional
which attribute to histogram “p_energy” or “p_filt_value”, by default “p_energy”
- t0int, optional
cuts all pulses before this time before fitting, by default 0
- tlast_type_, optional
cuts all pulses after this time before fitting, by default 1e20
- categorydict, optional
_description_, by default {}
- g_func_type_, optional
a function a function taking a MicrocalDataSet and returnning a vector like ds.good() would return This vector is anded with the vector calculated by the histogrammer, by default None
Returns¶
- ndarray, ndarray
Histogram bin centers, counts
- linefit(line_name='MnKAlpha', t0=0, tlast=1e+20, axis=None, dlo=50, dhi=50, binsize=1, bin_edges=None, attr='p_energy', label='full', plot=True, guess_params=None, ph_units='eV', category={}, g_func=None, has_tails=False)[source]¶
Do a fit to line_name and return the fitter. You can get the params results with fitter.last_fit_params_dict or any other way you like.
line_name – A string like “MnKAlpha” will get “MnKAlphaFitter”, your you can pass in a fitter like a mass.GaussianFitter(). t0 and tlast – cuts all pulses outside this timerange before fitting axis – if axis is None and plot==True, will create a new figure, otherwise plot onto this axis dlo and dhi and binsize – by default it tries to fit with bin edges given by np.arange(fitter.spect.nominal_peak_energy-dlo,
fitter.spect.nominal_peak_energy+dhi, binsize)
bin_edges – pass the bin_edges you want as a numpy array attr – default is “p_energy”, you could pick “p_filt_value” or others. be sure to pass in bin_edges as well because
the default calculation will probably fail for anything other than p_energy
label – passed to fitter.plot plot – passed to fitter.fit, determine if plot happens guess_params – passed to fitter.fit, fitter.fit will guess the params on its own if this is None ph_units – passed to fitter.fit, used in plot label category – pass {“side”:”A”} or similar to use categorical cuts g_func – a function a function taking a MicrocalDataSet and returnning a vector like ds.good() would return holdvals – a dictionary mapping keys from fitter.params_meaning to values… eg {“background”:0, “dP_dE”:1}
This vector is anded with the vector calculated by the histogrammer
- property p_peak_time¶
- phase_correct(attr='p_filt_value_dc', forceNew=False, category={}, ph_peaks=None, method2017=True, kernel_width=None, save_to_hdf5=True)[source]¶
Apply the 2017 or 2015 phase correction method.
- Args:
forceNew (bool): whether to recompute if it already exists (default False). category (dict): if not None, then a dict giving a category name and the
required category label.
ph_peaks: Peaks to use for alignment. If None, then use _find_peaks_heuristic() kernel_width: Width (in PH units) of the kernel-smearing function. If None, use a heuristic.
- phase_correct2014(typical_resolution, maximum_num_records=50000, plot=False, forceNew=False, category={})[source]¶
Apply the phase correction that worked for calibronium-like data as of June 2014.
For more notes, do help(mass.core.analysis_algorithms.FilterTimeCorrection)
- Args:
- typical_resolution (number): should be an estimated energy resolution in UNITS OF
self.p_pulse_rms. This helps the peak-finding (clustering) algorithm decide which pulses go together into a single peak. Be careful to use a semi-reasonable quantity here.
- maximum_num_records (int): don’t use more than this many records to learn
the correction (default 50000).
plot (bool): whether to make a relevant plot forceNew (bool): whether to recompute if it already exists (default False). category (dict): if not None, then a dict giving a category name and the
required category label.
- property pkl_fname¶
- plot_hist(bin_edges, attr='p_energy', axis=None, label_lines=[], category={}, g_func=None)[source]¶
plot a coadded histogram from all good datasets and all good pulses bin_edges – edges of bins unsed for histogram attr – which attribute to histogram “p_energy” or “p_filt_value” axis – if None, then create a new figure, otherwise plot onto this axis annotate_lines – enter lines names in STANDARD_FEATURES to add to the plot, calls annotate_lines g_func – a function a function taking a MicrocalDataSet and returnning a vector like ds.good() would return
This vector is anded with the vector calculated by the histogrammer
- plot_summaries(valid='uncut', downsample=None, log=False)[source]¶
Plot a summary of the data set, including time series and histograms of key pulse properties.
- Args:
- valid: An array of booleans self.nPulses long saying which pulses are to be plotted
OR ‘uncut’ or ‘cut’, meaning that only uncut or cut data are to be plotted OR None or ‘all’, meaning that all pulses should be plotted.
- downsample: To prevent the scatter plots (left panels) from getting too crowded,
plot only one out of this many samples. If None, then plot will be downsampled to 10,000 total points (default None).
log (bool): Use logarithmic y-axis on the histograms (right panels). (Default False)
- plot_traces(pulsenums, pulse_summary=True, axis=None, difference=False, residual=False, valid_status=None, shift1=False, subtract_baseline=False, fcut=None)[source]¶
Plot some example pulses, given by sample number.
- Args:
<pulsenums> A sequence of sample numbers, or a single one. <pulse_summary> Whether to put text about the first few pulses on the plot <axis> A plt axis to plot on. <difference> Whether to show successive differences (that is, d(pulse)/dt) or the raw data <residual> Whether to show the residual between data and opt filtered model, or just raw data. <valid_status> If None, plot all pulses in <pulsenums>. If “valid” omit any from that set
that have been cut. If “cut”, show only those that have been cut.
<shift1> Whether to take pulses with p_shift1==True and delay them by 1 sample <subtract_baseline> Whether to subtract pretrigger mean prior to plotting the pulse <fcut> If not none, apply a lowpass filter with this cutoff frequency prior to plotting
- property rowcount¶
Deprecated since version 0.8.2: Use subframecount, which is equivalent but better named
- set_nearest_neighbors_list(mapFilename, nearestNeighborCategory='physical', distanceType='cartesian', forceNew=False)[source]¶
Finds the nearest neighbors in a given space for all channels in a data set
Args: mapFilename (str): Location of map file in the following format
Column 0 - list of channel numbers. Remaining column(s) - coordinates that define a particular column in a given space.
For example, can be the row and column number in a physical space or the frequency order number in a frequency space (umux readout).
- nearestNeighborCategory (str): name used to categorize the type of nearest neighbor.
This will be the name given to the subgroup of the hdf5 file under the nearest_neighbor group. This will also be a key for dictionary nearest_neighbors_dictionary
distanceType (str): Type of distance to measure between nearest neighbors, i.e. cartesian forceNew (bool): whether to re-compute nearest neighbors list if it exists (default False)
- property shortname¶
return a string containing part of the filename and the channel number, useful for labelling plots
- smart_cuts(threshold=10.0, n_trainings=10000, forceNew=False)[source]¶
Young! Why is there no doc string here??
- property subframes_after_last_external_trigger¶
- property subframes_from_nearest_external_trigger¶
- property subframes_until_next_external_trigger¶
- summarize_data(peak_time_microsec=None, pretrigger_ignore_microsec=None, cut_pre=0, cut_post=0, forceNew=False, use_cython=True, doPretrigFit=False)[source]¶
Summarize the complete data set one chunk at a time.
Store results in the HDF5 datasets p_pretrig_mean and similar.
Args: peak_time_microsec: the time in microseconds at which this channel’s
pulses typically peak (default None). You should leave this as None, and let the value be estimated from the data.
- pretrigger_ignore_microsec: how much time before the trigger to ignore
when computing pretrigger mean (default None). If None, it will be chosen sensibly.
cut_pre: Cut this many samples from the start of a pulse record when calculating summary values cut_post: Cut this many samples from the end of the a record when calculating summary values forceNew: whether to re-compute summaries if they exist (default False) use_cython: whether to use cython for summarizing the data (default True). doPretrigFit: whether to do a linear fit of the pretrigger data
- time_drift_correct(attr='p_filt_value_phc', sec_per_degree=2000, pulses_per_degree=2000, max_degrees=20, forceNew=False, category={})[source]¶
Drift correct over long times with an entropy-minimizing algorithm. Here we correct as a low-ish-order Legendre polynomial in time.
- attr: the attribute of self that is to be corrected. (The result
will be stored in self.p_filt_value_tdc[:]).
sec_per_degree: assign as many as one polynomial degree per this many seconds pulses_per_degree: assign as many as one polynomial degree per this many pulses max_degrees: never use more than this many degrees of Legendre polynomial.
forceNew: whether to do this step, if it appears already to have been done. category: choices for categorical cuts
- class mass.core.channel.NoiseRecords(filename, records_are_continuous=False, use_records=None, maxsegmentsize=None)[source]¶
Bases:
object
Encapsulate a set of noise records.
The noise records can either be assumed continuous or arbitrarily separated in time.
- ALLOWED_TYPES = ('ljh', 'virtual')¶
- DEFAULT_MAXSEGMENTSIZE = 32000000¶
- compute_autocorrelation(n_lags=None, data_samples=None, plot=True, max_excursion=1000)[source]¶
Compute the autocorrelation averaged across all “pulses” in the file.
- Args:
<n_lags> <data_samples> If not None, then a range [a,b] to use.
- compute_fancy_power_spectra(window=<function hann>, plot=True, seglength_choices=None)[source]¶
Compute a power spectrum using a few long segments for the low freq. and many short ones for the higher frequencies.
- compute_power_spectrum_reshape(window=<function hann>, seg_length=None, max_excursion=1000)[source]¶
Compute the noise power spectrum with noise “records” reparsed into separate records of a given length.
- Args:
- window (ndarray): a window function weighting, or a function that will
return a weighting.
- seg_length (int): length of the noise segments (default None). If None,
then use self.data.shape[0], which is self.data.nPulses, will be used as the number of segments, each having length self.data.nSamples.
- max_excursion (number): the biggest excursion from the median allowed
in each data segment, or else it will be ignored (default 1000).
By making <seg_length> small, you improve the noise on the PSD estimates at the price of poor frequency resolution. By making it large, you get good frequency resolution with worse uncertainty on each PSD estimate. No free lunch, know what I mean?
- copy()[source]¶
Return a copy of the object.
Handy when coding and you don’t want to read the whole data set back in, but you do want to update the method definitions.
- plot_autocorrelation(axis=None, color='blue', label=None)[source]¶
Plot the autocorrelation function.
- plot_power_spectrum(axis=None, scale=1.0, sqrt_psd=False, **kwarg)[source]¶
Plot the power spectrum of this noise record.
- Args:
<axis> Which plt.Axes object to plot on. If none, clear the figure and plot there. <scale> Scale all raw units by this number to convert counts to physical <sqrt_psd> Whether to take the sqrt(PSD) for plotting. Default is no sqrt
- class mass.core.channel.PulseRecords(filename, file_format=None)[source]¶
Bases:
object
Encapsulate a set of data containing multiple triggered pulse traces. The pulses should not be noise records.
This object will not contain derived facts such as pulse summaries, filtered values, and so forth. It is meant to be only a file interface.
- ALLOWED_TYPES = ('ljh', 'virtual')¶
- mass.core.channel.time_drift_correct(time, uncorrected, w, sec_per_degree=2000, pulses_per_degree=2000, max_degrees=20, ndeg=None, limit=None)[source]¶
Compute a time-based drift correction that minimizes the spectral entropy.
- Args:
time: The “time-axis”. Correction will be a low-order polynomial in this. uncorrected: A filtered pulse height vector. Same length as indicator.
Assumed to have some gain that is linearly related to indicator.
w: the kernel width for the Laplace KDE density estimator sec_per_degree: assign as many as one polynomial degree per this many seconds pulses_per_degree: assign as many as one polynomial degree per this many pulses max_degrees: never use more than this many degrees of Legendre polynomial. n_deg: If not None, use this many degrees, regardless of the values of
sec_per_degree, pulses_per_degree, and max_degress. In this case, never downsample.
- limit: The [lower,upper] limit of uncorrected values over which entropy is
computed (default None).
The entropy will be computed on corrected values only in the range [limit[0], limit[1]], so limit should be set to a characteristic large value of uncorrected. If limit is None (the default), then it will be computed as 25%% larger than the 99%%ile point of uncorrected.
Possible improvements in the future: * Move this routine to Cython. * Allow the parameters to be function arguments with defaults: photons per
degree of freedom, seconds per degree of freedom, and max degrees of freedom.
Figure out how to span the available time with more than one set of legendre polynomials, so that we can have more than 20 d.o.f. eventually, for long runs.
mass.core.channel_group module¶
channel_group.py
Part of the Microcalorimeter Analysis Software System (MASS).
This module defines classes that handle one or more TES data streams together.
- class mass.core.channel_group.CrosstalkVeto(datagroup=None, window_ms=(-10, 3), pileup_limit=100)[source]¶
Bases:
object
An object to allow vetoing of data in 1 channel when another is hit.
- mass.core.channel_group.RestoreTESGroup(hdf5filename, hdf5noisename=None)[source]¶
Generate a TESGroup object from a data summary HDF5 file.
- Args:
hdf5filename (string): the data summary file hdf5noisename (string): the noise summary file; this can often be inferred from
the noise raw filenames, which are stored in the pulse HDF5 file (assuming you aren’t doing something weird). (default None)
- class mass.core.channel_group.TESGroup(filenames, noise_filenames=None, noise_only=False, noise_is_continuous=True, hdf5_filename=None, hdf5_noisefilename=None, never_use=None, use_only=None, max_chans=None, experimentStateFile=None, excludeStates='auto', overwrite_hdf5_file=False)[source]¶
Bases:
CutFieldMixin
,GroupLooper
The interface for a group of one or more microcalorimeters.
- property channel¶
- compute_average_pulse(masks, subtract_mean=True, forceNew=False)[source]¶
Compute an average pulse in each TES channel.
Store the averages in self.datasets.average_pulse, a length nSamp vector. Note that this method replaces any previously computed self.datasets.average_pulse
- Args:
- masks: A sequence of length self.n_channels, one sequence per channel.
The elements of masks should be booleans or interpretable as booleans.
- subtract_mean (bool): whether each average pulse will subtract a constant
to ensure that the pretrigger mean (first self.nPresamples elements) is zero.
- compute_filters(fmax=None, f_3db=None, cut_pre=0, cut_post=0, forceNew=False, category=None, filter_type='ats')[source]¶
- compute_noise_spectra(max_excursion=1000, forceNew=False)[source]¶
Replaced by the equivalent compute_noise(…)
Deprecated since version 0.7.9: Use compute_noise(), which is equivalent but better named
- correct_flux_jumps(flux_quant)[source]¶
Remove ‘flux’ jumps’ from pretrigger mean.
When using umux readout, if a pulse is recorded that has a very fast rising edge (e.g. a cosmic ray), the readout system will “slip” an integer number of flux quanta. This means that the baseline level returned to after the pulse will different from the pretrigger value by an integer number of flux quanta. This causes that pretrigger mean summary quantity to jump around in a way that causes trouble for the rest of MASS. This function attempts to correct these jumps.
Arguments: flux_quant – size of 1 flux quantum
- property external_trigger_subframe_as_seconds¶
This is not a posix timestamp, it is just the external trigger subframecount converted to seconds based on the nominal clock rate of the crate.
- property external_trigger_subframe_count¶
- property first_good_dataset¶
- property good_channels¶
- hist(bin_edges, attr='p_energy', t0=0, tlast=1e+20, category={}, g_func=None)[source]¶
- return a tuple of (bin_centers, counts) of p_energy of good pulses in all good datasets
(use .hists to get the histograms individually). filters out nan values
bin_edges – edges of bins unsed for histogram attr – which attribute to histogram “p_energy” or “p_filt_value” t0 and tlast – cuts all pulses outside this timerange before fitting g_func – a function a function taking a MicrocalDataSet and returnning a vector like ds.good() would return
This vector is anded with the vector calculated by the histogrammer
- hists(bin_edges, attr='p_energy', t0=0, tlast=1e+20, category={}, g_func=None)[source]¶
return a tuple of (bin_centers, countsdict). automatically filters out nan values where countsdict is a dictionary mapping channel numbers to numpy arrays of counts bin_edges – edges of bins unsed for histogram attr – which attribute to histogram “p_energy” or “p_filt_value” t0 and tlast – cuts all pulses outside this timerange before fitting g_func – a function a function taking a MicrocalDataSet and returnning a vector like ds.good() would return
This vector is anded with the vector calculated by the histogrammer
- iter_channel_numbers(include_badchan=False)[source]¶
Iterator over the channel numbers in channel number order
- Args:
- include_badchan (bool): whether to include officially bad channels
in the result (default False).
- iter_channels(include_badchan=False)[source]¶
Iterator over the self.datasets in channel number order
- Args:
- include_badchan (bool): whether to include officially bad channels
in the result (default False).
- linefit(line_name='MnKAlpha', t0=0, tlast=1e+20, axis=None, dlo=50, dhi=50, binsize=1, bin_edges=None, attr='p_energy', label='full', plot=True, guess_params=None, ph_units='eV', category={}, g_func=None, has_tails=False)[source]¶
Do a fit to line_name and return the fitter. You can get the params results with fitter.last_fit_params_dict or any other way you like.
line_name – A string like “MnKAlpha” will get “MnKAlphaFitter”, your you can pass in a fitter like a mass.GaussianFitter(). t0 and tlast – cuts all pulses outside this timerange before fitting axis – if axis is None and plot==True, will create a new figure, otherwise plot onto this axis dlo and dhi and binsize – by default it tries to fit with bin edges given by np.arange(fitter.spect.nominal_peak_energy-dlo,
fitter.spect.nominal_peak_energy+dhi, binsize)
bin_edges – pass the bin_edges you want as a numpy array attr – default is “p_energy”, you could pick “p_filt_value” or others. be sure to pass in bin_edges as well because
the default calculation will probably fail for anything other than p_energy
label – passed to fitter.plot plot – passed to fitter.fit, determine if plot happens guess_params – passed to fitter.fit, fitter.fit will guess the params on its own if this is None ph_units – passed to fitter.fit, used in plot label category – pass {“side”:”A”} or similar to use categorical cuts g_func – a function a function taking a MicrocalDataSet and returnning a vector like ds.good() would return holdvals – a dictionary mapping keys from fitter.params_meaning to values… eg {“background”:0, “dP_dE”:1}
This vector is anded with the vector calculated by the histogrammer
this should be the same as ds.linefit, but for now I’ve just copied and pasted the code
- make_masks(pulse_avg_range=None, pulse_peak_range=None, pulse_rms_range=None, gains=None)[source]¶
Generate a sequence of masks for use in compute_average_pulses().
- Args:
pulse_avg_range – A 2-sequence giving the (minimum,maximum) p_pulse_average pulse_peak_range – A 2-sequence giving the (minimum,maximum) p_peak_value pulse_rms_range – A 2-sequence giving the (minimum,maximum) p_pulse_rms gains – The set of gains to use, if any.
- Returns:
a list of ndvectors of boolean dtype, one list per channel. Each vector says whether each pulse in that channel is in the given range of allowed pulse sizes.
- property num_good_channels¶
- plot_average_pulses(axis=None, channels=None, cmap=None, legend=True, fcut=None, include_badchan=False)[source]¶
Plot average pulse for channel number <channum> on matplotlib.Axes <axis>, or on a new Axes if <axis> is None. If <channum> is not a valid channel number, then plot all average pulses. If <fcut> is not None, then lowpass filter the traces with this cutoff frequency prior to plotting.
- plot_filters(axis=None, channels=None, cmap=None, filtname='filt_noconst', legend=True)[source]¶
Plot the optimal filters.
- Args:
channels: Sequence of channel numbers to display. If None, then show all.
- plot_histogram_pages(attr, valrange, bins, y_range=None, subplot_shape=(3, 4), suffix=None, lines=None, fileformat='png', one_file=False)[source]¶
Make plots of histograms for all channels.
This creates the plots for each good channel, placing multiple plots on each page, and saves each page to its own file. Only pulses that pass cuts are included. The file names have the form “<attr>-hist-<suffix>-<page number>.png”. The default value for the suffix is that pulsefile’s base name.
- Arguments:
attr – string containing name of attribute to plot valrange – range of value over which to histogram (passed into histogram function) bins – number of bins (passed into histogram function) y_range – if not None, values to use for y limits. Defaults to None. subplot_shape – tuple indicating shape of subplots. First element is
number of rows, second is number of columns.
- suffix – suffix to use for filenames. Defaults to None, which causes the
function to use the first 15 characters of the pulse filename for the first data set (which typically will have a value like ‘20171017_103454’)
- lines – if not None, must contain a hashtable, keyed off of channel
number. The value for each channel is a list of numbers. A dashed horizontal line is plotted for each value in this list. Defaults to None.
- fileformat – output format (‘png’, ‘pdf’, etc). Must be a value supported by
your installation of matplotlib.
- one_file – If True, combine all pages to one pdf file. If False, use
separate files for all pages. Defaults to False. If format is something other than ‘pdf’, this uses the ImageMagick program convert to combine the files. You can install it on ubuntu via apt-get install imagemagick.
- plot_noise(axis=None, channels=None, cmap=None, scale_factor=1.0, sqrt_psd=False, legend=True, include_badchan=False)[source]¶
Plot the noise power spectra.
- Args:
channels: Sequence of channels to display. If None, then show all. scale_factor: Multiply counts by this number to get physical units. sqrt_psd: Whether to show the sqrt(PSD) or (by default) the PSD itself. cmap: A matplotlib color map. Defaults to something. legend (bool): Whether to plot the legend (default True)
- plot_noise_autocorrelation(axis=None, channels=None, cmap=None, legend=True)[source]¶
Plot the noise autocorrelation functions.
- Args:
channels: Sequence of channel numbers to display. If None, then show all.
- plot_summaries(quantity, valid='uncut', downsample=None, log=False, hist_limits=None, channel_numbers=None, dataset_numbers=None)[source]¶
Plot a summary of one quantity from the data set.
This plot includes time series and histograms of this quantity. This method plots all channels in the group, but only one quantity. If you would rather see all quantities for one channel, then use the group’s group.channel[i].plot_summaries() method.
- Args:
- quantity: A case-insensitive whitespace-ignored one of the following list, or the numbers
that go with it: “Pulse RMS” (0) “Pulse Avg” (1) “Peak Value” (2) “Pretrig RMS” (3) “Pretrig Mean” (4) “Max PT Deriv” (5) “Rise Time” (6) “Peak Time” (7) “Peak Index” (8)
- valid: The words ‘uncut’ or ‘cut’, meaning that only uncut or cut data
are to be plotted OR None, meaning that all pulses should be plotted.
- downsample (int): To prevent the scatter plots (left panels) from getting too crowded,
plot only one out of this many samples. If None, then plot will be downsampled to 10,000 total points.
log (bool): Use logarithmic y-axis on the histograms (right panels). hist_limits: if not None, limit the right-panel histograms to this range. channel_numbers: A sequence of channel numbers to plot. If None, then plot all. dataset_numbers: A sequence of the datasets [0…n_channels-1] to plot. If None
(the default) then plot all datasets in numerical order. But ignored if channel_numbers is not None.
- plot_summary_pages(x_attr, y_attr, x_range=None, y_range=None, subplot_shape=(3, 4), suffix=None, lines=None, down=10, fileformat='png', one_file=False)[source]¶
Make scatter plots of summary quantities for all channels.
This creates the plots for each good channel, placing multiple plots on each page, and saves each page to its own file. Pulses that pass cuts are plotted in blue, and cut pulses are plotted in gray. The file names have the form “<x_attr>.vs.<y-attr>-<suffix>-<page number>.png”. The default value for the suffix is that pulsefile’s base name.
- Arguments:
x_attr – string containing name of X value attribute y_attr – string containing name of Y value attribute x_range – if not None, values to use for x limits. Defaults to None. y_range – if not None, values to use for y limits. Defaults to None. subplot_shape – tuple indicating shape of subplots. First element is
number of rows, second is number of columns.
- suffix – suffix to use for filenames. Defaults to None, which causes the
function to use the first 15 characters of the pulse filename for the first data set (which typically will have a value like ‘20171017_103454’)
- lines – if not None, must contain a hashtable, keyed off of channel
number. The value for each channel is a list of numbers. A dashed horizontal line is plotted for each value in this list. Defaults to None.
down – downsample by this factor. Defaults to 10 fileformat – output format (‘png’, ‘pdf’, etc). Must be a value supported by
your installation of matplotlib.
- one_file – If True, combine all pages to one pdf file. If False, use
separate files for all pages. Defaults to False. If format is something other than ‘pdf’, this uses the ImageMagick program convert to combine the files. You can install it on ubuntu via apt-get install imagemagick.
- plot_traces(pulsenums, dataset_num=0, channum=None, pulse_summary=True, axis=None, difference=False, residual=False, valid_status=None, shift1=False)[source]¶
Plot some example pulses, given by record number.
- Args:
<pulsenums> A sequence of record numbers, or a single number. <dataset_num> Dataset index (0 to n_dets-1, inclusive). Will be used only if
<channum> is invalid.
<channum> Channel number. If valid, it will be used instead of dataset_num. <pulse_summary> Whether to put text about the first few pulses on the plot
(default True)
<axis> A plt axis to plot on (default None, i.e., create a new axis) <difference> Whether to show successive differences (that is, d(pulse)/dt) or the raw data
(default False).
- <residual> Whether to show the residual between data and opt filtered model,
or just raw data (default False).
- <valid_status> If None, plot all pulses in <pulsenums>. If “valid” omit any from that set
that have been cut. If “cut”, show only those that have been cut. (default None).
- <shift1> Whether to take pulses with p_shift1==True and delay them by
1 sample (default False, i.e., show the pure raw data w/o shifting).
- pulse_model_to_hdf5(hdf5_file=None, n_basis=6, replace_output=False, maximum_n_pulses=4000, extra_n_basis_5lag=0, noise_weight_basis=True, category=None, f_3db_5lag=None, _rethrow=False)[source]¶
- read_trace(record_num, dataset_num=0, channum=None)[source]¶
Read one trace from cache or disk.
- Args:
record_num (int): the pulse record number to read. dataset_num (int): the dataset number to use channum (int): the channel number to use (if both this and dataset_num
are given, use channum in preference).
- Returns:
an ndarray: the pulse numbered <record_num>
- segnum2sample_range(segnum)[source]¶
Return the (first,end) sample numbers of the segment numbered <segnum>. Note that <end> is 1 beyond the last sample number in that segment.
- set_chan_bad(*args)[source]¶
Set one or more channels to be bad.
(No effect for channels already listed as bad.)
- Args:
- *args Arguments to this function are integers or containers of integers. Each
integer is added to the bad-channels list.
- Examples:
data.set_chan_bad(1, “too few good pulses”) data.set_chan_bad(103, [1, 3, 5], “detector unstable”)
- set_chan_good(*args)[source]¶
Set one or more channels to be good.
(No effect for channels already listed as good.)
- Args:
- *args Arguments to this function are integers or containers of integers. Each
integer is removed from the bad-channels list.
- property shortname¶
Return a string containing part of the filename and the number of good channels
- summarize_data(peak_time_microsec=None, pretrigger_ignore_microsec=None, cut_pre=0, cut_post=0, include_badchan=False, forceNew=False, use_cython=True, doPretrigFit=False)[source]¶
Summarize the data with per-pulse summary quantities for each channel.
peak_time_microsec will be determined automatically if None, and will be stored in channels as ds.peak_samplenumber.
- Args:
use_cython uses a cython (aka faster) implementation of summarize.
- property timestamp_offset¶
- property why_chan_bad¶
mass.core.channel_group_hdf5_only module¶
Functions related to using a group of data sets where the raw (LJH) files are not used, but the HDF5 files created from them are available.
mass.core.controller module¶
Contains the class AnalysisControl. It was once intended to control the full behavior of a lot of analysis operations. In reality, we only use it to specify the pulse quality cuts.
- class mass.core.controller.AnalysisControl(**kwargs)[source]¶
Bases:
PrmDictBase
Control the behavior of an analysis operation.
mass.core.cut module¶
Created on Apr 22, 2016
- class mass.core.cut.CutFieldMixin[source]¶
Bases:
object
A mixin object that gives a class access to lots of features involving boolean per-pulse cuts and per-pulse categorization.
- BUILTIN_BOOLEAN_CUT_FIELDS = ['pretrigger_rms', 'pretrigger_mean', 'pretrigger_mean_departure_from_median', 'peak_time_ms', 'rise_time_ms', 'postpeak_deriv', 'pulse_average', 'min_value', 'timestamp_sec', 'timestamp_diff_sec', 'subframecount_diff_sec', 'peak_value', 'energy', 'timing', 'p_filt_phase', 'smart_cuts']¶
- BUILTIN_CATEGORICAL_CUT_FIELDS = [['calibration', ['in', 'out'], 'in']]¶
- CUT_BOOLEAN_FIELD_DESC_DTYPE = dtype([('name', 'S64'), ('mask', '<u4')])¶
- CUT_CATEGORICAL_FIELD_DESC_DTYPE = dtype([('name', 'S64'), ('mask', '<u4')])¶
- CUT_CATEGORY_LIST_DTYPE = dtype([('field', 'S64'), ('category', 'S64'), ('code', '<u4')])¶
- property boolean_cut_desc¶
- property categorical_cut_desc¶
- property cut_category_list¶
- cut_field_desc_init()[source]¶
Initialize the cut field descriptions. This methods expects self to have the hdf5_file attribute.
- property cut_used_bit_flags¶
- register_boolean_cut_fields(*names)[source]¶
Register one or more boolean cut field(s). If any of given boolean cut fields already exist, it silently ignore.
- Args:
names (sequence of str): name(s) of one or more cut fields(s).
- register_categorical_cut_field(name, categories, default='uncategorized')[source]¶
Register one categorical cut field.
- Args:
name (str): the name of a new categorical cut field. categories (list[str]): the list of the names of categories of the cut field.
“uncategorized” category will be added if it doesn’t have already.
default (str): the name of default category.
- class mass.core.cut.Cuts(n, tes_group, hdf5_group=None)[source]¶
Bases:
object
Object to hold a 32-bit cut mask for each triggered record.
- bad(*args, **kwargs)[source]¶
Select pulses which are bad for at least one of specified boolean cut fields.
If any categorical cut fields are given, only pulses in the combination of categories are considered.
- category_codes(name)[source]¶
Returns the category codes of a single categorical cut field.
- Args:
name (str): the name of a categorical cut field.
- Returns:
- numpy array of uint32 :
category codes of a categorical cut field ‘name’.
- Raises:
- KeyError
when a name is not a registered categorical cut field.
- clear_cut(*args)[source]¶
Clear one or more boolean fields.
- Args:
- *args: one or more args giving the names to clear. If no name is
given, clear all boolean fields.
- cut(cut_num, mask)[source]¶
Set the mask of a single field. It could be a boolean or categorical field.
- Args:
cut_num (string or int): the name of a cut field. mask (np.array(dtype=bool) or np.array(dtype=np.uint32): a cut mask for the cut field.
- Raises:
ValueError: if cut_num or mask don’t make sense.
- cut_categorical(field, booldict)[source]¶
Set the value of one categorical cut.
- Args:
field (str): the name of category booldict (dict{str: np.array(dtype=bool)}): Keys are categories of the field and
entries are bool vectors of length equal to mask indicating belongingness.
- Raises:
ValueError: if any pulse is assigned to more than one category.
- cut_mask(*fields)[source]¶
Retrieves masks of multiple cut fields. They could be boolean or categorical.
- Args:
fields (list(str)): cut field name or names.
- cut_parameter(data, allowed, cut_id)[source]¶
Apply a cut on some per-pulse parameter.
- Args:
- <data> The per-pulse parameter to cut on. It can be an attribute of self, or it
can be computed from one or more arrays, but it must be an array of length self.nPulses
<allowed> The cut to apply (see below). <cut_id> The bit number (range [0,31]) to identify this cut or (as a
string) the name of the cut.
<allowed> is a 2-element sequence (a,b), then the cut requires a < data < b. Either a or b may be None, indicating no cut. OR <allowed> is a sequence of 2-element sequences (a,b), then the cut cuts data that does not meet a <= data <=b for any of the two element sequences.
mass.core.cython_channel module¶
Contains the class CythonMicrocalDataSet, which subclasses MicrocalDataSet to add a much faster, Cython version of .summarize_data_segment().
- mass.core.cython_channel.summarize_data_cython(const unsigned short[:, :] rawdata, double timebase, long peak_samplenumber, long pretrigger_ignore, long nPresamples, long first=0, long end=0)¶
Summarize one segment of the data file, loading it into cache.
mass.core.fake_data module¶
fake_data - Objects to make fake data for use, e.g., in demonstration scripts.
Joe Fowler, NIST
November 7, 2011
- class mass.core.fake_data.FakeDataGenerator(sample_time, n_samples, n_presamples=None, model_peak=None, seed=None)[source]¶
Bases:
object
An object to create fake data in memory.
Can generate a single mass.MicrocalDataSet or a 1+channel mass.TESGroup.
Only basic functionality is here so far.
Many interesting randomizations could be added in the future, such as gain variation, baseline drift. Pulse pileup should definitely be added.
- compute_model(model_peak=None)[source]¶
Compute the noise-free model pulse shape, given the 2 time constants.
- generate_microcal_dataset(n_pulses, distributions=None)[source]¶
Return a single mass.MicrocalDataset
- generate_tesgroup(n_pulses, n_noise=1024, distributions=None, distribution_weights=None, nchan=1)[source]¶
Return a mass.TESGroup with multiple channels in it.
- Args:
n_pulses (int): the number of pulses per channel n_noise (int): the number of noise records per channel distributions: ?? distribution_weights: ?? nchan (int): how many channels to generate (default 1).
mass.core.files module¶
The mass.core.files module contains classes required for handling the various types of pulse data files. In principle, there could be multiple data file types. But this module contains only two concrete classes, the VirtualFile and the LJHFile (along with the abstract base class MicrocalFile). VirtualFile is for treating an array of data as if it were a file.
If you find yourself wanting to read other file types in the future, then make a new class that inherits from MicrocalFile and calls MicrocalFile.__init__ to verify that it has the required interface: * read_trace(trace_num) * copy()
Created on Feb 16, 2011
- class mass.core.files.LJHFile(filename, header_dict, header_size)[source]¶
Bases:
MicrocalFile
Read a single LJH file of version 2.2 or 2.1.
The class is not meant to be created directly. Instead, use the class method LJHFile.open(filename) to return an instance of the appropriate subclass (either LJHFile2_2 or LJHFile2_1), determined by reading the LJH header before creating the instance.
usage: filename = “path/to/my/file_chan1.ljh” ljh = mass.LJHFile.open(filename)
- property alldata¶
- classmethod open(filename)[source]¶
A factory-like function.
Read the LJH header and return an instance of the appropriate subclass of LJHFile based on contents of the LJH version string.
This is the appropriate way to create an LJHFile in normal usage.
- read_trace_with_timing(trace_num)[source]¶
Return a single data trace as (subframecount, posix_usec, pulse_record).
- set_segment_size(segmentsize=None)[source]¶
Set the segmentsize in bytes.
Segments are not an intrinsic part of handling MASS memory, but they can be convenient as a way to offer modestly sized chunks of data for certain processing.
- property source¶
Report the ‘Data source’ as found in the LJH header.
- class mass.core.files.MicrocalFile[source]¶
Bases:
object
A set of data on disk containing triggered records from a microcalorimeter.
The pulses can be noise or X-rays. This is meant to be an abstract class. Use LJHFile.open() or VirtualFile() to create one. In the future, other derived classes could implement copy() and read_trace() to process other file types.
- class mass.core.files.VirtualFile(data, times=None, presamples=0)[source]¶
Bases:
MicrocalFile
Object to act like a single microcalorimeter data file on disk, though the data are all held only in memory.
- property source¶
Name of the data source
mass.core.ljh_modify module¶
Functions ljh_copy_traces and ljh_append_traces and class LJHModify, all of which can modify existing LJH files.
- mass.core.ljh_modify.LJHModify(input_filename, output_filename, callback, overwrite=False)[source]¶
Copy an LJH file input_filename to a new LJH file output_filename with the identical header, but with the raw data records transformed in-place by the function (or other callable object) callback.
The function callback should be of the form modified=callback(record), where record is an array of raw data records of shape (Nsamples, ). The callback might take the following form, if you need it to loop over records:
- def mycallback(record):
return 1000 + (record/2) # or whatever operations you need.
NOT IMPLEMENTED: this version of LJHModify does not allow the caller to modify the per-pulse row counter or posix time. Please file an issue if this becomes a problem.
- mass.core.ljh_modify.ljh_append_traces(src_name, dest_name, pulses=None)[source]¶
Append traces from one LJH file onto another. The destination file is assumed to be version 2.2.0.
Can be used to grab specific traces from some other ljh file, and append them onto an existing ljh file.
- Args:
src_name: the name of the source file dest_name: the name of the destination file pulses: indices of the pulses to copy (default: None, meaning copy all)
- mass.core.ljh_modify.ljh_copy_traces(src_name, dest_name, pulses, overwrite=False)[source]¶
Copy traces from one ljh file to another. The destination file will be of LJH version 2.2.0.
Can be used to grab specific traces from some other ljh file, and put them into a new file
- Args:
src_name: the name of the source file dest_name: the name of the destination file pulses: indices of the pulses to copy overwrite: If the destination file exists and overwrite is not True,
then the copy fails (default False).
- mass.core.ljh_modify.ljh_truncate(input_filename, output_filename, n_pulses=None, timestamp=None, segmentsize=None)[source]¶
Truncate an LJH file.
Writes a new copy of an LJH file, with with the identical header, but with a smaller number of raw data pulses.
Arguments: input_filename – name of file to truncate output_filename – filename for truncated file n_pulses – truncate to include only this many pulses (default None) timestamp – truncate to include only pulses with timestamp earlier
than this number (default None)
- segmentsize – number of bytes per segment; this is primarily here to
facilitate testing (defaults to same value as in LJHFile)
Exactly one of n_pulses and timestamp must be specified.
mass.core.ljh_util module¶
Various functions for manipulating LJH files’ filenames (extracting the channel number from the name, sorting names by channel number, and so on).
- mass.core.ljh_util.filename_glob_expand(pattern)[source]¶
Return the result of glob-expansion on the input pattern.
- Parameters:
pattern (str) – If a string, treat it as a glob pattern and return the glob-result as a list. If it isn’t a string, return it unchanged (presumably then it’s already a sequence).
- Returns:
filenames; the result is sorted first by str.sort, then by ljh_sort_filenames_numerically()
- Return type:
list
- mass.core.ljh_util.ljh_basename_channum(fname)[source]¶
Returns the base LJH file name and the channel number parsed from the name.
Finds the channel number by the pattern in the file’s base name, such as ‘blahblah_chan15.suffix’
- Returns:
(basename, channum) where basename is the full file path, up to the last occurance of ‘_chan’, and channum is an int (or None, if not found).
- mass.core.ljh_util.ljh_channum(name)[source]¶
Return the channel number found in the filename, as an int.
- mass.core.ljh_util.ljh_sort_filenames_numerically(fnames, inclusion_list=None)[source]¶
Sort filenames of the form ‘_chanXXX.’, according to the numerical value of channel number XXX.
Filenames are first sorted by the usual string comparisons, then by channel number. In this way, the standard sort is applied to all files with the same channel number.
- Parameters:
fnames (list of str) – A sequence of filenames of the form ‘_chan.*’
inclusion_list (sequence of int, optional) – If not None, a container with channel numbers. All files whose channel numbers are not on this list will be omitted from the output, defaults to None
- Returns:
A list containg the same filenames, sorted according to the numerical value of channel number.
- Return type:
list
- mass.core.ljh_util.remove_unpaired_channel_files(filenames1, filenames2, never_use=None, use_only=None)[source]¶
Extract the channel number in the filenames appearing in both lists.
Remove from each list any file whose channel number doesn’t appear on both lists. Also remove any file whose channel number is in the never_use list.
If either filenames1 or filenames2 is empty, only apply the never_use and use_only lists.
- Parameters:
filenames1 (list of str) – a list of filenames containing channel #s in the form “blah_chan15”.
filenames2 (list of str, optional) – another list of filenames containing channel #s in the form “blah_chan15”.
never_use (list of int, optional) – a sequence of channel numbers to exclude even if found in both lists, defaults to None
use_only (list of int, optional) – if a sequence of channel numbers, exclude any channels not in it, defaults to None
mass.core.message_logging module¶
Simple logging functions, to help us control how verbose MASS is at a terminal or when being tested.
mass.core.optimal_filtering module¶
Contains classes to do time-domain optimal filtering.
- class mass.core.optimal_filtering.ArrivalTimeSafeFilter(pulsemodel, n_pretrigger, noise_autocorr=None, whitener=None, sample_time=None, peak=1.0)[source]¶
Bases:
Filter
Compute a filter for pulses given a pulse model expressed as a polynomial in “arrival time”. The filter will be insensitive to the linear (and any higher-order) terms.
- compute(fmax=None, f_3db=None, cut_pre=0, cut_post=0)[source]¶
Compute a single filter.
<fmax> The strict maximum frequency to be passed in all filters. <f_3db> The 3 dB point for a one-pole low-pass filter to be applied to all filters. <cut_pre> Cut this many samples from the start of the filter, giving them 0 weight. <cut_post> Cut this many samples from the end of the filter, giving them 0 weight.
Either or both of <fmax> and <f_3db> are allowed.
- class mass.core.optimal_filtering.ExperimentalFilter(avg_signal, n_pretrigger, noise_psd=None, noise_autocorr=None, sample_time=None, shorten=0, tau=2.0)[source]¶
Bases:
Filter
Compute and all filters for pulses given an <avgpulse>, the <noise_autocorr>, and an expected time constant <tau> for decaying exponentials. Shorten the filters w.r.t. the avgpulse function by <shorten> samples on each end.
CAUTION: THESE ARE EXPERIMENTAL! Don’t use yet if you don’t know what you’re doing!
- compute(fmax=None, f_3db=None)[source]¶
Compute a set of filters. This is called once on construction, but you can call it again if you want to change the frequency cutoff or rolloff points.
Set is: filt_fourier Fourier filter for signals filt_full Alpert basic filter filt_noconst Alpert filter insensitive to constants filt_noexp Alpert filter insensitive to exp(-t/tau) filt_noexpcon Alpert filter insensitive to exp(-t/tau) and to constants filt_noslope Alpert filter insensitive to slopes filt_nopoly1 Alpert filter insensitive to Chebyshev polynomials order 0 to 1 filt_nopoly2 Alpert filter insensitive to Chebyshev polynomials order 0 to 2 filt_nopoly3 Alpert filter insensitive to Chebyshev polynomials order 0 to 3
- class mass.core.optimal_filtering.Filter(avg_signal, n_pretrigger, noise_psd=None, noise_autocorr=None, whitener=None, sample_time=None, shorten=0, cut_pre=0, cut_post=0)[source]¶
Bases:
object
A set of optimal filters based on a single signal and noise set.
- static bracketR(q, noise)[source]¶
Return the dot product (q^T R q) for vector <q> and matrix R constructed from the vector <noise> by R_ij = noise_|i-j|. We don’t want to construct the full matrix R because for records as long as 10,000 samples, the matrix will consist of 10^8 floats (800 MB of memory).
- compute(fmax=None, f_3db=None)[source]¶
Compute a single filter.
<fmax> The strict maximum frequency to be passed in all filters. <f_3db> The 3 dB point for a one-pole low-pass filter to be applied to all filters. <cut_pre> Cut this many samples from the start of the filter, giving them 0 weight. <cut_post> Cut this many samples from the end of the filter, giving them 0 weight.
Either or both of <fmax> and <f_3db> are allowed.
- normalize_filter(q)[source]¶
Rescale filter <q> in-place so that it gives unit response to self.avg_signal
- report(filters=None, std_energy=5898.8)[source]¶
Report on V/dV for all filters
- Args:
- <filters> Either the name of one filter or a sequence of names. If not given, then all filters
not starting with “baseline” will be reported.
- <std_energy> Energy (in eV) of a “standard” pulse. Resolution will be given in eV at this energy,
assuming linear devices.
- class mass.core.optimal_filtering.ToeplitzWhitener(thetacoef, phicoef)[source]¶
Bases:
object
An object that can perform approximate noise whitening.
For an ARMA(p,q) noise model, mutliply by (or solve) the matrix W (or its transpose), where W is the Toeplitz approximation to the whitening matrix V. A whitening matrix V means that if R is the ARMA noise covariance matrix, then VRV’ = I. While W is only approximately equal to V, it has some handy properties that make it a useful replacement. (In particular, it has the time-transpose property that if you zero-pad the beginning of vector v and shift the remaining elements, then the same is doen to Wv.)
The callable function object returns Wv or WM if called with vector v or matrix M. Other methods:
tw.whiten(v) returns Wv, equivalent to tw(v)
tw.solveWT(v) returns inv(W’)*v
tw.applyWT(v) returns W’v
tw.solveW(v) returns inv(W)*v
mass.core.param_dict_base module¶
param_dict_base.py
By Hans Petter Langtangen from book “Python Scripting for Computational Science” (1st ed). Found online at http://folk.uio.no/hpl/scripting/ specifically in http://folk.uio.no/hpl/scripting/scripting-src-1st-ed.tar.gz look in src/tools/py4cs
Provides a base class PrmDictBase that can hold more than one dictionary of parameters (each named self.*_prm), which can be restricted to contain only certain keys and can optionally check the type of any values that the user tries to assign.
- class mass.core.param_dict_base.PrmDictBase[source]¶
Bases:
object
Base class for solvers with parameters stored in dictionaries.
- Data dicts whose keys are fixed (non-extensible):
self.*_prm
- These are filled in subclasses by, e.g.,
self.physical_prm[‘someprm’] = value
- or
- self.physical_prm.update({‘someprm’: value,
‘another’: other_value})
The dictionary with all legal keys should be defined in the subclass.
- List of the dictionaries with fixed keys:
self._prm_list = [self.physical_prm, self.numerical_prm]
Subclasses define any self._*_prm dicts and append them to self._prm_list.
Meta data given by the user can be stored in self.user_prm. This attribute is None if meta data are not allowed, otherwise it is a dictionary that holds parameters.
self._type_check[prm] is defined if we want to type check a parameter prm. if self._type_check[prm] is True (or False), prm must be None, of the same type as the previous registered value of prm, or any number (float, int, complex) if the previous value prm was any number.
- static dicts2namespace(namespace, dicts, overwrite=True)[source]¶
Make namespace variables out of dict items.
mass.core.utilities module¶
Various utility functions and classes:
- MouseClickReader: a class to use as a callback for reading mouse click
locations in matplotlib plots.
- InlineUpdater: a class that loops over a generator and prints a message to
the terminal each time it yields.
- class mass.core.utilities.InlineUpdater(baseString)[source]¶
Bases:
object
- property elapsedTimeSec¶
- property elapsedTimeStr¶
- property timeRemaining¶
- property timeRemainingStr¶
- class mass.core.utilities.MouseClickReader(figure)[source]¶
Bases:
object
A callback for reading mouse clicks in data coordinates in pylab plots.
Stores self.b, .x, .y giving the button pressed, and the x,y data coordinates of the pointer when clicked.
- mass.core.utilities.annotate_lines(axis, label_lines, label_lines_color2=[], color1='k', color2='r')[source]¶
Annotate plot on axis with line names. label_lines – eg [“MnKAlpha”,”TiKBeta”] list of keys of STANDARD_FEATURES label_lines_color2 – optional,eg [“MnKAlpha”,”TiKBeta”] list of keys of STANDARD_FEATURES color1 – text color for label_lines color2 – text color for label_lines_color2