evaluation
#
Classes:
|
Main class for evaluating data. |
- class pyEvalData.evaluation.Evaluation(source)[source]#
Bases:
object
Main class for evaluating data. The raw data is accessed via a
Source
object. The evaluation allows to bin data, calculate errors and propagate them. There is also an interface tolmfit
for easy batch-fitting.- Parameters
source (Source) – raw data source.
- Attributes
log (logging.logger) – logger instance from logging.
clist (list[str]) – list of counter names to evaluate.
cdef (dict{str – str}): dict of predefined counter names and definitions.
xcol (str) – counter or motor for x-axis.
t0 (float) – approx. time zero for delay scans to determine the unpumped region of the data for normalization.
custom_counters (list[str]) – list of custom counters - default is []
math_keys (list[str]) – list of keywords which are evaluated as numpy functions
statistic_type (str) – ‘gauss’ for normal averaging, ‘poisson’ for counting statistics
propagate_errors (bool) – propagate errors for dpendent counters.
Methods:
Returns a list of counters as defined by the user.
traverse_counters
(clist[, source_cols])Traverse all counters and replace all predefined counter definitions.
resolve_counter_name
(col_name[, source_cols])Replace all predefined counter definitions in a given counter name.
col_string_to_eval_string
(col_string[, ...])Use regular expressions in order to generate an evaluateable string from the counter string in order to append the new counter to the spec data.
add_custom_counters
(spec_data, scan_num, ...)Add custom counters to the spec data array.
filter_data
(data)- param data
DESCRIPTION.
get_scan_data
(scan_num)- param scan_num
DESCRIPTION.
get_scan_list_data
(scan_list)- param scan_num
DESCRIPTION.
avg_N_bin_scans
(scan_list[, xgrid, binning])Averages data defined by the counter list, clist, onto an optional xgrid.
plot_scans
(scan_list[, ylims, xlims, ...])Plot a list of scans from the spec file.
plot_mesh_scan
(scan_num[, skip_plot, ...])Plot a single mesh scan from the spec file.
plot_scan_sequence
(scan_sequence[, ylims, ...])Plot a list of scans from the spec file.
export_scan_sequence
(scan_sequence, path, ...)Exports spec data for each scan list in the sequence as individual file.
fit_scans
(scans, mod, pars[, ylims, xlims, ...])Fit, plot, and return the data of scans.
fit_scan_sequence
(scan_sequence, mod, pars)Fit, plot, and return the data of a scan sequence.
Return the last figure number of all opened figures for plotting data in the same figure during for-loops.
Return the number of the next available figure.
- get_clist()[source]#
Returns a list of counters as defined by the user. If the counters where defined in a
dict
it will be converted to alist
for backwards compatibility.- Returns
clist (list[str]) – list of counter names to evaluate.
- traverse_counters(clist, source_cols='')[source]#
Traverse all counters and replace all predefined counter definitions. Returns also a list of the included source counters for error propagation.
- Parameters
clist (list[str]) – Initial counter list.
source_cols (list[str], optional) – counters in the raw source data.
- Returns
(tuple) –
resolved_counters (list[str]) - resolved counters.
source_counters (list[str]) - all source counters in the resolved counters.
- resolve_counter_name(col_name, source_cols='')[source]#
Replace all predefined counter definitions in a given counter name. The function works recursively.
- Parameters
col_name (str) – initial counter string.
source_cols (list[str], optional) – columns in the source data.
- Returns
(tuple) –
col_string (str) - resolved counter string.
source_counters (list[str]) - source counters in the col_string
- col_string_to_eval_string(col_string, array_name='spec_data')[source]#
Use regular expressions in order to generate an evaluateable string from the counter string in order to append the new counter to the spec data.
- Parameters
col_string (str) – Definition of the counter.
mode (int) – Flag for different modes
- Returns
eval_string (str) –
- Evaluateable string to add the new counter
to the spec data.
- add_custom_counters(spec_data, scan_num, source_counters)[source]#
Add custom counters to the spec data array. This is a stub for child classes.
- Parameters
spec_data (ndarray) – Data array from the spec scan.
scan_num (int) – Scan number of the spec scan.
list (source_counters) – List of the source counters and custom counters from the clist and xcol.
- Returns
spec_data (ndarray) – Updated data array from the spec scan.
- get_scan_data(scan_num)[source]#
- Parameters
scan_num (TYPE) – DESCRIPTION.
- Returns
TYPE – DESCRIPTION.
- get_scan_list_data(scan_list)[source]#
- Parameters
scan_num (TYPE) – DESCRIPTION.
- Returns
TYPE – DESCRIPTION.
- avg_N_bin_scans(scan_list, xgrid=array([], dtype=float64), binning=True)[source]#
Averages data defined by the counter list, clist, onto an optional xgrid. If no xgrid is given the x-axis data of the first scan in the list is used instead.
- Parameters
scan_list (List[int]) – List of scan numbers.
xgrid (Optional[ndarray]) – Grid to bin the data to - default in empty so use the x-axis of the first scan.
- Returns
avg_data (ndarray) – Averaged data for the scan list. std_data (ndarray) : Standart derivation of the data for the scan list. err_data (ndarray) : Error of the data for the scan list. name (str) : Name of the data set.
- plot_scans(scan_list, ylims=[], xlims=[], fig_size=[], xgrid=[], yerr='std', xerr='std', norm2one=False, binning=True, label_text='', title_text='', skip_plot=False, grid_on=True, ytext='', xtext='', fmt='-o')[source]#
Plot a list of scans from the spec file. Various plot parameters are provided. The plotted data are returned.
- Parameters
scan_list (List[int]) – List of scan numbers.
ylims (Optional[ndarray]) – ylim for the plot.
xlims (Optional[ndarray]) – xlim for the plot.
fig_size (Optional[ndarray]) – Figure size of the figure.
xgrid (Optional[ndarray]) – Grid to bin the data to - default in empty so use the x-axis of the first scan.
yerr (Optional[ndarray]) – Type of the errors in y: [err, std, none] default is ‘std’.
xerr (Optional[ndarray]) – Type of the errors in x: [err, std, none] default is ‘std’.
norm2one (Optional[bool]) – Norm transient data to 1 for t < t0 default is False.
label_text (Optional[str]) – Label of the plot - default is none.
title_text (Optional[str]) – Title of the figure - default is none.
skip_plot (Optional[bool]) – Skip plotting, just return data default is False.
grid_on (Optional[bool]) – Add grid to plot - default is True.
ytext (Optional[str]) – y-Label of the plot - defaults is none.
xtext (Optional[str]) – x-Label of the plot - defaults is none.
fmt (Optional[str]) – format string of the plot - defaults is -o.
- Returns
y2plot (OrderedDict) – y-data which was plotted. x2plot (ndarray) : x-data which was plotted. yerr2plot (OrderedDict) : y-error which was plotted. xerr2plot (ndarray) : x-error which was plotted. name (str) : Name of the data set.
- plot_mesh_scan(scan_num, skip_plot=False, grid_on=False, ytext='', xtext='', levels=20, cbar=True)[source]#
Plot a single mesh scan from the spec file. Various plot parameters are provided. The plotted data are returned.
- Parameters
scan_num (int) – Scan number of the spec scan.
skip_plot (Optional[bool]) – Skip plotting, just return data default is False.
grid_on (Optional[bool]) – Add grid to plot - default is False.
ytext (Optional[str]) – y-Label of the plot - defaults is none.
xtext (Optional[str]) – x-Label of the plot - defaults is none.
levels (Optional[int]) – levels of contour plot - defaults is 20.
cbar (Optional[bool]) – Add colorbar to plot - default is True.
- Returns
xx, yy, zz – x,y,z data which was plotted
- plot_scan_sequence(scan_sequence, ylims=[], xlims=[], fig_size=[], xgrid=[], yerr='std', xerr='std', norm2one=False, binning=True, sequence_type='', label_text='', title_text='', skip_plot=False, grid_on=True, ytext='', xtext='', fmt='-o')[source]#
Plot a list of scans from the spec file. Various plot parameters are provided. The plotted data are returned.
- Parameters
(List[ (scan_sequence) – List/Tuple[List[int], int/str]]) : Sequence of scan lists and parameters.
ylims (Optional[ndarray]) – ylim for the plot.
xlims (Optional[ndarray]) – xlim for the plot.
fig_size (Optional[ndarray]) – Figure size of the figure.
xgrid (Optional[ndarray]) – Grid to bin the data to - default in empty so use the x-axis of the first scan.
yerr (Optional[ndarray]) – Type of the errors in y: [err, std, none] default is ‘std’.
xerr (Optional[ndarray]) – Type of the errors in x: [err, std, none] default is ‘std’.
norm2one (Optional[bool]) – Norm transient data to 1 for t < t0 default is False.
sequence_type (Optional[str]) – Type of the sequence: [fluence, delay, energy, theta, position, voltage, none, text] - default is enumeration.
label_text (Optional[str]) – Label of the plot - default is none.
title_text (Optional[str]) – Title of the figure - default is none.
skip_plot (Optional[bool]) – Skip plotting, just return data default is False.
grid_on (Optional[bool]) – Add grid to plot - default is True.
ytext (Optional[str]) – y-Label of the plot - defaults is none.
xtext (Optional[str]) – x-Label of the plot - defaults is none.
fmt (Optional[str]) – format string of the plot - defaults is -o.
- Returns
sequence_data (OrderedDict) – Dictionary of the averaged scan data. parameters (List[str, float]) : Parameters of the sequence. names (List[str]) : List of names of each data set. label_texts (List[str]) : List of labels for each data set.
- export_scan_sequence(scan_sequence, path, fileName, yerr='std', xerr='std', xgrid=[], norm2one=False, binning=True)[source]#
Exports spec data for each scan list in the sequence as individual file.
- Parameters
(List[ (scan_sequence) – List/Tuple[List[int], int/str]]) : Sequence of scan lists and parameters.
path (str) – Path of the file to export to.
fileName (str) – Name of the file to export to.
yerr (Optional[ndarray]) – Type of the errors in y: [err, std, none] default is ‘std’.
xerr (Optional[ndarray]) – Type of the errors in x: [err, std, none] default is ‘std’.
xgrid (Optional[ndarray]) – Grid to bin the data to - default in empty so use the x-axis of the first scan.
norm2one (Optional[bool]) – Norm transient data to 1 for t < t0 default is False.
- fit_scans(scans, mod, pars, ylims=[], xlims=[], fig_size=[], xgrid=[], yerr='std', xerr='std', norm2one=False, binning=True, sequence_type='text', label_text='', title_text='', ytext='', xtext='', select='', fit_report=0, show_single=False, weights=False, fit_method='leastsq', offset_t0=False, plot_separate=False, grid_on=True, fmt='o')[source]#
Fit, plot, and return the data of scans.
This is just a wrapper for the fit_scan_sequence method
- fit_scan_sequence(scan_sequence, mod, pars, ylims=[], xlims=[], fig_size=[], xgrid=[], yerr='std', xerr='std', norm2one=False, binning=True, sequence_type='', label_text='', title_text='', ytext='', xtext='', select='', fit_report=0, show_single=False, weights=False, fit_method='leastsq', offset_t0=False, plot_separate=False, grid_on=True, last_res_as_par=False, sequence_data=[], fmt='o')[source]#
Fit, plot, and return the data of a scan sequence.
- Parameters
(List[ (scan_sequence) – List/Tuple[List[int], int/str]]) : Sequence of scan lists and parameters.
mod (Model[lmfit]) – lmfit model for fitting the data.
pars (Parameters[lmfit]) – lmfit parameters for fitting the data.
ylims (Optional[ndarray]) – ylim for the plot.
xlims (Optional[ndarray]) – xlim for the plot.
fig_size (Optional[ndarray]) – Figure size of the figure.
xgrid (Optional[ndarray]) – Grid to bin the data to - default in empty so use the x-axis of the first scan.
yerr (Optional[ndarray]) – Type of the errors in y: [err, std, none] default is ‘std’.
xerr (Optional[ndarray]) – Type of the errors in x: [err, std, none] default is ‘std’.
norm2one (Optional[bool]) – Norm transient data to 1 for t < t0 default is False.
sequence_type (Optional[str]) – Type of the sequence: [fluence, delay, energy, theta] - default is fluence.
label_text (Optional[str]) – Label of the plot - default is none.
title_text (Optional[str]) – Title of the figure - default is none.
ytext (Optional[str]) – y-Label of the plot - defaults is none.
xtext (Optional[str]) – x-Label of the plot - defaults is none.
select (Optional[str]) – String to evaluate as select statement for the fit region - default is none
fit_report (Optional[int]) – Set the fit reporting level: [0: none, 1: basic, 2: full] default 0.
show_single (Optional[bool]) – Plot each fit seperately - default False.
weights (Optional[bool]) – Use weights for fitting - default False.
fit_method (Optional[str]) – Method to use for fitting; refer to lmfit - default is ‘leastsq’.
offset_t0 (Optional[bool]) – Offset time scans by the fitted t0 parameter - default False.
plot_separate (Optional[bool]) – A single plot for each counter default False.
grid_on (Optional[bool]) – Add grid to plot - default is True.
last_res_as_par (Optional[bool]) – Use the last fit result as start values for next fit - default is False.
sequence_data (Optional[ndarray]) – actual exp. data are externally given. default is empty
fmt (Optional[str]) – format string of the plot - defaults is -o.
- Returns
res (Dict[ndarray]) – Fit results. parameters (ndarray) : Parameters of the sequence. sequence_data (OrderedDict) : Dictionary of the averaged scan data.equenceData