Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1d5643a
initial analysis class
henrikjacobsenfys Feb 3, 2026
5e460ce
make analysis_base
henrikjacobsenfys Feb 6, 2026
74629d8
test things in notebook
henrikjacobsenfys Feb 6, 2026
9af6322
reintroduce energy_offset in convolution. It's needed.
henrikjacobsenfys Feb 6, 2026
ba85d95
Progress on Analysis
henrikjacobsenfys Feb 6, 2026
1c77784
multiple parameters with same unique_name?????
henrikjacobsenfys Feb 8, 2026
8c37ee4
fitting and plotting for multiple Q
henrikjacobsenfys Feb 10, 2026
b477a38
analysis MWP
henrikjacobsenfys Feb 11, 2026
08cdef2
Add plotting of parameters and examples
henrikjacobsenfys Feb 12, 2026
02158a1
Update failing tests
henrikjacobsenfys Feb 12, 2026
b9d3fec
Instrument model (#94)
henrikjacobsenfys Feb 5, 2026
248773d
initial analysis class
henrikjacobsenfys Feb 3, 2026
ce9acf8
fix merge conflict
henrikjacobsenfys Feb 12, 2026
f16a7e3
Remove notebook
henrikjacobsenfys Feb 12, 2026
7a31120
Update notebook, remove unused file
henrikjacobsenfys Feb 12, 2026
10d085e
pixi run fix
henrikjacobsenfys Feb 12, 2026
4e3d1c4
add missing tests
henrikjacobsenfys Feb 12, 2026
703d824
More missing tests
henrikjacobsenfys Feb 12, 2026
e343767
test analysis_base
henrikjacobsenfys Feb 12, 2026
fb7682c
100% coverage of base
henrikjacobsenfys Feb 12, 2026
51194a5
Test analysis1d
henrikjacobsenfys Feb 16, 2026
0972807
Another test
henrikjacobsenfys Feb 16, 2026
d054345
More analysis1d tests
henrikjacobsenfys Feb 17, 2026
9c01ffc
linting
henrikjacobsenfys Feb 17, 2026
61f49bd
update component_collection among other things
henrikjacobsenfys Feb 18, 2026
5178525
Add a few more tests
henrikjacobsenfys Feb 18, 2026
ad0689b
fix failing test
henrikjacobsenfys Feb 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 269 additions & 0 deletions docs/docs/tutorials/analysis.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "8643b10c",
"metadata": {},
"source": [
"# Analysis\n",
"It is time to analyse some data. We here show how to set up an Analysis object and use it to first fit an artificial vanadium measurements, and next an artificial measurement of a model with diffusion and some elastic scattering.\n",
"\n",
"In the near future, it will be possible to fit the width and area of the Lorentzian to the diffusion model, as well as fitting the diffusion model directly to the data."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bca91d3c",
"metadata": {},
"outputs": [],
"source": [
"\n",
"from easydynamics.analysis.analysis import Analysis\n",
"from easydynamics.experiment import Experiment\n",
"from easydynamics.sample_model import ComponentCollection\n",
"from easydynamics.sample_model import DeltaFunction\n",
"from easydynamics.sample_model import Gaussian\n",
"from easydynamics.sample_model import Lorentzian\n",
"from easydynamics.sample_model import Polynomial\n",
"from easydynamics.sample_model.background_model import BackgroundModel\n",
"from easydynamics.sample_model.instrument_model import InstrumentModel\n",
"from easydynamics.sample_model.resolution_model import ResolutionModel\n",
"from easydynamics.sample_model.sample_model import SampleModel\n",
"\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8deca9b6",
"metadata": {},
"outputs": [],
"source": [
"vanadium_experiment = Experiment('Vanadium')\n",
"vanadium_experiment.load_hdf5(filename='vanadium_data_example.h5')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6762faba",
"metadata": {},
"outputs": [],
"source": [
"# Example of Analysis with a simple sample model and instrument model\n",
"delta_function = DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = SampleModel(\n",
" components=delta_function,\n",
")\n",
"\n",
"res_gauss = Gaussian(width=0.1)\n",
"res_gauss.area.fixed = True\n",
"resolution_model = ResolutionModel(components=res_gauss)\n",
"\n",
"\n",
"background_model = BackgroundModel(components=Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = InstrumentModel(\n",
" resolution_model=resolution_model,\n",
" background_model=background_model,\n",
")\n",
"\n",
"vanadium_analysis = Analysis(\n",
" display_name='Vanadium Full Analysis',\n",
" experiment=vanadium_experiment,\n",
" sample_model=sample_model,\n",
" instrument_model=instrument_model,\n",
")\n",
"\n",
"fit_result_independent_single_Q = vanadium_analysis.fit(fit_method='independent', Q_index=5)\n",
"vanadium_analysis.plot_data_and_model(Q_index=5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e98e3d65",
"metadata": {},
"outputs": [],
"source": [
"fit_result_independent_all_Q = vanadium_analysis.fit(fit_method='independent')\n",
"vanadium_analysis.plot_data_and_model()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "af13afce",
"metadata": {},
"outputs": [],
"source": [
"fit_result_simultaneous = vanadium_analysis.fit(fit_method='simultaneous')\n",
"fit_result_simultaneous\n",
"vanadium_analysis.plot_data_and_model()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "133e682e",
"metadata": {},
"outputs": [],
"source": [
"# Inspect the Parameters as a scipp Dataset\n",
"vanadium_analysis.parameters_to_dataset()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dfacdf24",
"metadata": {},
"outputs": [],
"source": [
"# Plot some of fitted parameters as a function of Q\n",
"vanadium_analysis.plot_parameters(names=['DeltaFunction area'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6f9f316",
"metadata": {},
"outputs": [],
"source": [
"vanadium_analysis.plot_parameters(names=['Gaussian width'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "572664a0",
"metadata": {},
"outputs": [],
"source": [
"vanadium_analysis.plot_parameters(names=['energy_offset'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3609e6c1",
"metadata": {},
"outputs": [],
"source": [
"# Set up the diffusion analysis with the same resolution model as the\n",
"# vanadium analysis\n",
"diffusion_experiment = Experiment('Diffusion')\n",
"diffusion_experiment.load_hdf5(filename='diffusion_data_example.h5')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e685909a",
"metadata": {},
"outputs": [],
"source": [
"# We set up the model first.\n",
"delta_function = DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"lorentzian = Lorentzian(display_name='Lorentzian', area=0.5, width=0.3)\n",
"component_collection = ComponentCollection(\n",
" components=[delta_function, lorentzian],\n",
")\n",
"sample_model = SampleModel(\n",
" components=component_collection,\n",
")\n",
"\n",
"background_model = BackgroundModel(components=Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = InstrumentModel(\n",
" background_model=background_model,\n",
")\n",
"\n",
"diffusion_analysis = Analysis(\n",
" display_name='Diffusion Full Analysis',\n",
" experiment=diffusion_experiment,\n",
" sample_model=sample_model,\n",
" instrument_model=instrument_model,\n",
")\n",
"\n",
"# We need to hack in the resolution model from the vanadium analysis,\n",
"# since the setters and getters overwrite the model. This will be fixed\n",
"# asap.\n",
"diffusion_analysis.instrument_model._resolution_model = (\n",
" vanadium_analysis.instrument_model.resolution_model\n",
")\n",
"diffusion_analysis.instrument_model.resolution_model.fix_all_parameters()\n",
"diffusion_analysis.plot_parameters(names=['Gaussian width'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c66828eb",
"metadata": {},
"outputs": [],
"source": [
"# Let us see how good the starting parameters are\n",
"diffusion_analysis.plot_data_and_model()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "197b44c5",
"metadata": {},
"outputs": [],
"source": [
"# Now we fit the data and plot the result. Looks good!\n",
"diffusion_analysis.fit(fit_method='independent')\n",
"diffusion_analysis.plot_data_and_model()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df14b5c4",
"metadata": {},
"outputs": [],
"source": [
"# Let us look at the most interesting fit parameters\n",
"diffusion_analysis.plot_parameters(names=['Lorentzian width', 'Lorentzian area'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eb226c8f",
"metadata": {},
"outputs": [],
"source": [
"# It will be possible to fit this to a DiffusionModel, but that will\n",
"# come later."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "easydynamics_newbase",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
109 changes: 109 additions & 0 deletions docs/docs/tutorials/analysis1d.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "8643b10c",
"metadata": {},
"source": [
"# Analysis1d\n",
"Sometimes, you will only be interested in a particular Q, not the full dataset. For this, use the Analysis1d object. We here show how to set it up to fit an artificial vanadium measurement."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bca91d3c",
"metadata": {},
"outputs": [],
"source": [
"from easydynamics.analysis.analysis1d import Analysis1d\n",
"from easydynamics.experiment import Experiment\n",
"from easydynamics.sample_model import DeltaFunction\n",
"from easydynamics.sample_model import Gaussian\n",
"from easydynamics.sample_model import Polynomial\n",
"from easydynamics.sample_model.background_model import BackgroundModel\n",
"from easydynamics.sample_model.instrument_model import InstrumentModel\n",
"from easydynamics.sample_model.resolution_model import ResolutionModel\n",
"from easydynamics.sample_model.sample_model import SampleModel\n",
"\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8deca9b6",
"metadata": {},
"outputs": [],
"source": [
"vanadium_experiment = Experiment('Vanadium')\n",
"vanadium_experiment.load_hdf5(filename='vanadium_data_example.h5')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "41f842f0",
"metadata": {},
"outputs": [],
"source": [
"# Example of Analysis1d with a simple sample model and instrument model\n",
"delta_function = DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = SampleModel(\n",
" components=delta_function,\n",
")\n",
"\n",
"res_gauss = Gaussian(width=0.1)\n",
"resolution_model = ResolutionModel(components=res_gauss)\n",
"\n",
"\n",
"background_model = BackgroundModel(components=Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = InstrumentModel(\n",
" resolution_model=resolution_model,\n",
" background_model=background_model,\n",
")\n",
"\n",
"my_analysis = Analysis1d(\n",
" display_name='Vanadium Analysis',\n",
" experiment=vanadium_experiment,\n",
" sample_model=sample_model,\n",
" instrument_model=instrument_model,\n",
" Q_index=5,\n",
")\n",
"\n",
"fit_result = my_analysis.fit()\n",
"my_analysis.plot_data_and_model()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c055bd93",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "easydynamics_newbase",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading