Structure of the code #61
henrikjacobsenfys
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is a loose stream-of-consciousnss description of the structure of the code.
Analyis
Responsible for fitting etc. Will take a
SampleModel,InstrumentModelas input.Will have multiple fit methods: fit sequential (fit all or a subset of all data to the model in the list of
ComponentCollections as discussed in SampleModel, fit simultaneous acrossQ(probably automatically chosen if there's aDiffusionModelin theSampleModel, since in this case, we fit the diffusion model parameters, which define a number of Lorentzians and other components with dependentParameters, or fit the widths ofLorentziansto aDiffusionModelThat will probably have a different name.I'm unsure how to handle it if there are two Lorentzians in the model and they should be fitted with two different
DiffusionModels, but it's probably somewhat straightforward to choose from a list via indexing.It will use a
Calculator(name pending review) to actually do the math.Calculator
Will calculate the total scattering from the sample, roughly using
We will make a
Calculatorfor eachQand temperature in the list (see below)SampleModel
The current
SampleModelwill be renamed toComponentCollectionor something similar. It will take a list (perhaps sc.array) ofQamong other things.The
SampleModelwill allow the user to appendDiffusionModels to a list ofDiffusionModels and appendModelComponents to aComponentCollection.There will also be a list of
ComponentCollections, where each is a copy of theComponentCollectionthat the user supplied. The user will also be allowed to work directly with this list. The list is the same length as Q; eachComponentCollectioncorresponds to a singleQ.Behind the scenes, it will have a list of
ComponentCollection, which contains all the user suppliedComponentCollections.The
DiffusionModelwill also be able to generate components. It may be best to keep them in a separate list ofComponentCollections, just to make sure they don't accidentally get overwritten or changed by the user. It should be possible to append aDiffusionModelwithout actually generating the components it contains., Fitting entire diffusion models is very difficult until you have a very good understanding of your data, and can take very long - in preliminary tests, fitting sequentially took about 3 seconds, and aDiffusionModelfrom an ok, but not great, starting point took 15 minutes.Perhaps it will have an explicit
generate_diffusion_model_componentsor some such.It should have a
calculateandplotmethod to plot the model of the scattering of the sample before convolution. I suppose that they could take two lists ofComponentCollections and make a singleComponentCollectionout of them?It will have an optional
Temperature, which when not None will include detailed balance calculations.It will eventually also have to support taking a list of temperatures and allow models to vary as function of temperature - not entirely sure how that will work. Perhaps we will actually have a list of list of
ComponentCollection, where one is over temperature, and the other is overQ. Let's deal with that when we get there.SampleModelwill inherit fromSampleModelBaseor something similar.SampleModelBase
Base class for sample models - contains a list of
ComponentCollectionas function ofQand probably not much elseInstrumentModel
Will inherit from
SampleModelBasebut will not have temperature. Also contains anenergy_offset. TheComponentCollectionit contains will be called something likebackground_model, and it will have a method that tentatively is calledcalculate_background.The data underpinning the instrument resolution description should probably live here, but I'm not quite sure about that. Thoughts are welcome.
ComponentCollection
This is essentially what the current
SampleModelis, and as the name implies, just a list of components. It will probably be nice to add a__add__method to easily add/append anotherComponentCollection, e.g. if the user has supplied aDiffusionModeland a couple of other components for their fit.DiffusionModel
Diffusion models generally can generate a number of (typically)
DeltaFunctionsandLorentziansas function ofQ. They get put into aComponentCollection.Some more advanced models may also generate a number of functions as function of temperature or perhaps even of sample, but we'll cross that bridge when we get there.
Convolution
Takes a
SampleModelandInstrumentModeland computes their convolution as function of energy. The temperature for detailed balancing will live inSampleModel, and the offset in energy will live inInstrumentModel.I may also want to allow to take
ModelComponentfor the model andModelComponentorSampleModelfor theInstrumentModel, since this is nice if users want to make use of convolutions.Underneath, it has
AnalyticalConvolutionfor analytical pairs ofModelComponents,NumericalConvolutionfor non-analytical pairs (or if temperature is not None), and perhaps even a full class forDeltaConvolution, although the latter feels like overkill since delta functions act as an identity in convolutions and are thus very easy to implement. There's also aNumericalConvolutionBasewhich inherits fromConvolutionBase.AnalyticalConvolutionalso inherits fromConvolutionBase.Experiment
This will contain the data and not much else, I think. I'm actually not entirely sure how to share the responsibilities between
Experiment(orMeasurement?) andInstrument- thoughts are welcome.Job
This, I think, will hold several
Analysisobjects as well as potentially severalExperiments. I'm not exactly sure how to structure this yet. I think some chatting with a cup of tea next to a whiteboard could help clear this up.Basically, the typical workflow people will want is this:
scipp.DataArrayor similar, which will then contain intensity as function of energy, Q, and temperature. We may even want to have it as function of sample.A question to still be answered: What should
Qbe? Right now, it's a np.array, which I think is nice for the users. But it will probably make some things easier if it's internally stored as ascipp.array, since we don't have to worry too much about units. Some dependency expressions useQ, and in those cases, we'll convert the (single)Qvalue to aDescriptorNumber.Beta Was this translation helpful? Give feedback.
All reactions