ADR suggestion Analysis
#5
Replies: 2 comments 1 reply
-
|
A few comments here. The |
Beta Was this translation helpful? Give feedback.
-
|
Based on what was discussed in e.g. easyscience/EasyDiffractionLib#97 Similar comment is to other setters, especially with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
General
The
Analysisclass is where fitting takes place. This ADR suggestions is a work in progress.Current implementation
Only a skeleton has been implemented
Suggested implementation
There will be three
Analysisclasses:AnalysisBase,Analysis1dandAnalysis. The base class handles all shared logic, of course.Analysis1dwill have aQ_indexproperty, and will work with data (intensity with variances as function of energy) for that singleQ_index. TheAnalysisclass will contain a list ofAnalysis1dobjects; one for eachQ_indexin the underlying experimental data.AnalysisBaseAnalysisBaseinherits fromModelBase.It takes the following input:
display_nameandunique_name(probably changing toname)experiment: An EasyDynamicsExperimentobject, which contains a scipp DataArray with coordinatesenergyandQ. TheQfrom theExperimentwill be used as the trueQ(e.g. the one that theAnalysisgetters will refer to) and copied into all models.sample_model: An EasyDynamicsSampleModelobject, which contains aComponentCollectionfor eachQ_indexinstrument_model: An EasyDynamicsInstrumentModelobject, which contains an optionalResolutionModelandBackgroundModel(similar to theSampleModel), and a list ofenergy_offsetParameters, one for eachQ`.It contains setters and getters for all these models. In addition, it has a
_create_convolvermethod, which creates a EasyDynamicsConvolutionobject for a givenQ_index, which handles the convolution of the sampleComponentCollectionwith the instrument resolutionComponentCollectionAnalysis1dIt also takes the following two inputs:
a
Q_index, which selects a particularQof the data and all the attached models.(slightly controversial, but I really want this):
extra_parameters: AParameteror a list ofParameter, which the user can define as they please. I do not know exactly how users will use this, but they may, for example, decide that the widths of the Lorentzians in their model should be dependentParameters with some custom dependency on anotherParameter. Most users will not touch it, but it's there to allow flexibility for advanced users.Other methods:
get_all_variables(): gets all the variables of the relevant models atself._Q_index, all sharedParameters like the temperature of theSampleModeland anyParameters fromDiffusionModels. And of course the extraParameters that users can pass to itcalculate(orevaluateor something else): Calculate the scattering atself._Q_index. Includes checks and may regenerate theConvolutionobject if needed_calculate: doethe actual calculation with minimal checks for speed for thefit: uses the EasyScienceFitterto fit the data at the givenQ_indexcalculate_individual_component: calculates individual components including resolution abd background contributions forplot_data_and_modelAnalysisContains a list of
Analysis1dobjects and the following primary methods:fit: fits the data with various settings, calling various sub-functions, such as_fit_single_Q: calls the relevantAnalysis1d._fit_all_Q_independently: calls all the relevantAnalysis1dobjects one after the other_fit_all_Q_simultaneously: This is the fun one! It passes all theAnalysis1dobjects and the correct fit functions to do what the name implies, allowing fits of full diffusion models_calculate_all_Q: for plotting_calculate_individual_component_all_Q(name pending): for plottingplot_data_and_model: uses a Scipp DataGroup and plopp to make slicers and other types of plots easilyplot_fit_parameter: plot e.g. the width of one (or more) of the Lorentzians. Will at first take indices, later names to choose which parameters to plot.fit_diffusion_modelor some thing similar: fit the width (and optional area) of e.g. a Lorentzian to a diffusion model. It should of course also be possible to plot the fit of this parameter together with the values.This is more or less it for the minimal version, but
Extensions:
For the fitting I also want utility such as:
fit a single
Q_index, then copy the values of the fit to the other ones to have better start guessesFit all
Qindependently, but use the previous fit as the start guess for the next oneeasy access to fix
Parameters acrossQ, and to makeParameters dependent on each other.It will also allow extra
Parameters, just like theAnalysis1dclass.I also of course need to be able to pass settings to the
Convolutionclasses, to the fitter and to the plotting. That will not be there for the minimal model, since it's effort.A note on Energy
the energy axis is handled somewhat inconsistently throughout the library. I want users to be able to pass a list of numpy array, but it's probably easiest and best to use a scipp variable internally. The work is already growing quite big with some necessary changes to unrelated code, so I'm making an ugly and simple solution that works, and pinky promising to get back to the energy later.
Beta Was this translation helpful? Give feedback.
All reactions