TimeSpectrum
- class nexus.TimeSpectrum(experiment, time_length=200.0, time_step=0.2, max_detuning=400.0, electronic=False, time_data=[], intensity_data=[], scaling='auto', background=0.0, offset=0.0, distribution_points=1, fit_weight=1.0, bunch_spacing=inf, instrument=<nexus.clib.cnexus.DefaultInstrumentGaussian; proxy of <Swig Object of type 'Instrument *'> >, residual=<nexus.clib.cnexus.Sqrt; proxy of <Swig Object of type 'Residual *'> >, fft_window='auto', coherence=False, id='')
Bases:
FitMeasurementConstructor for the
TimeSpectrumclass. Class to calculate the time-dependent intensity of the experiment.- Parameters:
id (string) – User identifier.
experiment (
Experiment) – Experimenttime_length (float) – Length of the calculation (nanoseconds).
time_step (float) – Step size of the calculation (nanoseconds).
max_detuning (float) – Maximum value of the energy detuning (Gamma). Set this value to speed up the calculation. If set to zero no maximum is applied. Also see
fft_window.electronic (bool) – If True electronic scattering is included.
time_data (list or ndarray) – Time data for fitting (nanoseconds).
intensity_data (list or ndarray) – Intensity data for fitting.
scaling (float or
Varor string) – Intensity scaling factor for fitting. Default isauto.background (float or
Varor string) – Background for fitting. Default is0.offset (float or
Var) –Temporal offset of the model. Default is
0.Added in version 1.1.0.
resolution (float or
Var) –Resolution value for convolution (nanoseconds). Corresponds to the APD resolution.
Removed in version 2.0.0.
instrument (
Instrument) –Instrumentobject with the implementation of a resolution function. Default is a Gaussian instrument function with FWHM = 0.5 ns.Added in version 2.0.0.
distribution_points (int) – Number of points for thickness distributions in forward geometry and angular divergence in grazing geometry. Both distributions assume incoherent summation over the weighted contributions. Default is 1.
fit_weight (float) – Relative weight for the cost function in multi measurement fitting.
bunch_spacing (float) – Spacing of subsequent X-ray bunches in time (nanoseconds).
residual (
Residual) – Implementation of the residual calculation used for fitting.fft_window (string) –
A window function that is applied during the Fourier transformation from energy to time. This should be used when the
max_detuningis not zero. Options areauto(default) - will pick a Hann window ifmax_detuningis not zero, no window otherwise.HannHammingSineWelchKaiser2- \(\alpha = 2\)Kaiser25- \(\alpha = 2.5\)Kaiser3- \(\alpha = 3\)none
coherence (bool) –
Determines if the summation over the thickness and divergence distributions is performed coherently (
True) or incoherently (False). Default isFalse.Added in version 1.0.3.
- id
User identifier.
- Type:
string
- experiment
Experiment
- Type:
- time_length
Length of the calculation (nanoseconds).
- Type:
float
- time_step
Step size of the calculation (nanoseconds).
- Type:
float
- max_detuning
Maximum value of the energy detuning (Gamma). Set this value to speed up the calculation. If set to zero no maximum is applied. Also see
fft_window.- Type:
float
- electronic
If True electronic scattering is included.
- Type:
bool
- time_data
Time data for fitting (nanoseconds).
- Type:
list
- intensity_data
Intensity data for fitting.
- Type:
list
- data_size
Number of data points of experimental data.
- Type:
int
- resolution
Resolution value for convolution (nanoseconds). Corresponds to the APD resolution.
Removed in version 2.0.0.
- Type:
- resolution_kernel
weight of the Gaussian resolution same step size as detuning.
Removed in version 2.0.0.
- Type:
list
- distribution_points
Number of points for thickness distributions in forward geometry and angular divergence in grazing geometry. Both distributions assume incoherent summation over the weighted contributions.
- Type:
int
- fit_weight
Relative weight for the cost function in multi measurement fitting.
- Type:
float
- bunch_spacing
Spacing of subsequent X-ray bunches in time (nanoseconds). instrument (
Instrument):Instrumentobject.Added in version 2.0.0.
- Type:
float
- fft_window
A window function that is applied during the Fourier transformation from energy to time. This should be used when the
max_detuningis not zero. Options areauto(default) - will pick a Hann window ifmax_detuningis not zero, no window otherwise.HannHammingSineWelchKaiser2- \(\alpha = 2\)Kaiser25- \(\alpha = 2.5\)Kaiser3- \(\alpha = 3\)none
- Type:
string
- coherence
Determines if the summation over the thickness and divergence distributions is performed coherently (
True) or incoherently (False). Default isFalse.Added in version 1.0.3.
- Type:
bool
- result
List of intensity values. It is the energy-integrated intensity per time in units of \(\Gamma /ns\).
- Type:
list
- Calculate()
Calculates the class method. Also callable via operator
().- Returns:
Time array of float values. ndarray: Intensity array of float values.
- Return type:
ndarray
- Cost()
Get the cost function of the measurement
\[cost = \frac{1}{n} \sum_i r(y_i, \hat{y}_i)\]Added in version 2.0.0.
- Returns:
cost function value.
- Return type:
float
- MeanSquaredError()
Get the mean squared error (MSE) of the measurement
\[cost = \frac{1}{n} \sum_i (y_i - \hat{y}_i)^2\]Added in version 2.0.0.
- Returns:
MSE value.
- Return type:
float
- Plot(data=True, residuals=True, datacolor='black', theorycolor='r', theorywidth=2, datalinestyle='none', datamarker='+', datamarkersize=2, datafillstyle='full', legend=True, errors=False, errorcap=2, name=None)
Plot the
TimeSpectrum.Added in version 1.0.3.
Changed in version 1.2.0.
- Parameters:
data (bool) – Select if
intensity_datashould be plot.residuals (bool) – Select if
residualsfrom fit should be plot.datacolor (string) – See matplotlib documentation.
theorycolor (string) – See matplotlib documentation.
theorywidth (float) – See matplotlib documentation.
datalinestyle (string) – See matplotlib documentation.
datamarker (string) – See matplotlib documentation.
datamarkersize (float) – See matplotlib documentation.
datafillstyle (string) – See matplotlib documentation.
legend (bool) – Select if legend should be plot when model and data are plot.
errors (bool) – Select if error bars should be plot.
errorcap (float) – See matplotlib documentation (
capsize).name (string) –
If given, the plot is saved under this name.
Added in version 1.2.0.
- Velocity()
Returns the velocity detuning of the measurement in units of mm/s.
- Returns:
Velocity detuning (mm/s).
- Return type:
ndarray