Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
d1c20a4
Add basic sample_model and tests
henrikjacobsenfys Oct 14, 2025
a782693
Clean up, fix tests
henrikjacobsenfys Oct 15, 2025
2fb844b
Improve tests
henrikjacobsenfys Oct 17, 2025
d4309fc
Update example and tests
henrikjacobsenfys Oct 17, 2025
cde9b4b
Add one more test
henrikjacobsenfys Oct 17, 2025
6f797f8
Added a few tests
henrikjacobsenfys Oct 17, 2025
3435da5
a few more tests
henrikjacobsenfys Oct 17, 2025
c0a4f2c
fix a test
henrikjacobsenfys Oct 17, 2025
a4ba794
respond to PR comments
henrikjacobsenfys Oct 17, 2025
d1d28d2
Use CollectionBase
henrikjacobsenfys Oct 20, 2025
ce49f05
Update example
henrikjacobsenfys Oct 20, 2025
0eb1bba
Merge branch 'develop' into SampleModel2
henrikjacobsenfys Oct 28, 2025
07c070a
Update to new ModelComponent
henrikjacobsenfys Oct 28, 2025
3a7187c
Cleanup and a few tests
henrikjacobsenfys Oct 28, 2025
77c11f6
First implementation of convolution
henrikjacobsenfys Oct 29, 2025
d7a95f2
Update tests and convolution
henrikjacobsenfys Oct 29, 2025
05b7465
Cleaning up
henrikjacobsenfys Oct 29, 2025
6c59a05
Fix test
henrikjacobsenfys Oct 29, 2025
fd3eff6
make tests nicer
henrikjacobsenfys Oct 29, 2025
0d6d63a
fix test
henrikjacobsenfys Oct 29, 2025
5f7da95
fix test
henrikjacobsenfys Oct 29, 2025
f8deef3
Small update
henrikjacobsenfys Oct 30, 2025
7707703
Type hints and docstrings
henrikjacobsenfys Oct 31, 2025
885382f
Add example and performance test
henrikjacobsenfys Oct 31, 2025
62f5ce2
Update tests
henrikjacobsenfys Oct 31, 2025
0649310
Clear example notebook
henrikjacobsenfys Oct 31, 2025
4adf07d
Add comment about thresholds
henrikjacobsenfys Oct 31, 2025
bc498ba
Delete old examples
henrikjacobsenfys Oct 31, 2025
93c5299
small update
henrikjacobsenfys Nov 3, 2025
df616b3
Rename x to energy, add auto method
henrikjacobsenfys Nov 4, 2025
60b77b0
Add example
henrikjacobsenfys Nov 4, 2025
040c8c6
Fix a test
henrikjacobsenfys Nov 4, 2025
33729a7
update numerical convolution
henrikjacobsenfys Nov 5, 2025
176ce80
Polishing
henrikjacobsenfys Nov 5, 2025
f24662f
starting to refactor....
henrikjacobsenfys Nov 13, 2025
078ce87
Lots of refactoring
henrikjacobsenfys Nov 19, 2025
f0d2c77
Update example, fix minor things
henrikjacobsenfys Nov 19, 2025
2e1c826
Allow energy to be a scipp variable
henrikjacobsenfys Nov 19, 2025
4d5fe40
Flesh out base class
henrikjacobsenfys Nov 19, 2025
aa271bd
Update numerical convolution base
henrikjacobsenfys Nov 19, 2025
953279e
Clean up numerical convolution
henrikjacobsenfys Nov 19, 2025
40bc58a
First draft of refactor done, time for tests
henrikjacobsenfys Nov 19, 2025
8646baa
test convolution_base
henrikjacobsenfys Nov 19, 2025
bbfff6c
Add edge case tests
henrikjacobsenfys Nov 19, 2025
134b35f
Update performance test
henrikjacobsenfys Nov 19, 2025
1eea4c7
Small updates
henrikjacobsenfys Nov 19, 2025
c935efc
Begin test of numerical convolution base
henrikjacobsenfys Nov 19, 2025
8e7c64c
Update analytical convolution and some tests
henrikjacobsenfys Nov 20, 2025
d85d73b
Finish test of analytical convolution
henrikjacobsenfys Nov 20, 2025
efe6f8d
Add comment
henrikjacobsenfys Nov 20, 2025
2c57726
test offset
henrikjacobsenfys Nov 21, 2025
d9d2cf6
Remove offset
henrikjacobsenfys Nov 21, 2025
8ae2364
Update example and fix offset bug
henrikjacobsenfys Nov 21, 2025
5b69dec
small changes
henrikjacobsenfys Nov 21, 2025
6ffe598
Small updates
henrikjacobsenfys Dec 10, 2025
5fda58d
More tests of numerical convolution
henrikjacobsenfys Dec 12, 2025
cabd355
fix small bug
henrikjacobsenfys Dec 12, 2025
fe293bc
100% coverage of numerical convolution?
henrikjacobsenfys Dec 12, 2025
c2aa048
100%!
henrikjacobsenfys Dec 12, 2025
2a7e804
Test numerical convolution
henrikjacobsenfys Dec 12, 2025
fe841e1
small update
henrikjacobsenfys Dec 15, 2025
180c382
Make convolution plan logic more robust
henrikjacobsenfys Dec 15, 2025
2fdea2b
update init test of convolution
henrikjacobsenfys Dec 15, 2025
fc8da9d
More tests
henrikjacobsenfys Dec 15, 2025
84717dc
remove outdated test
henrikjacobsenfys Dec 15, 2025
cc5ee14
Remove comments
henrikjacobsenfys Dec 15, 2025
ae31323
Update type hints
henrikjacobsenfys Dec 16, 2025
b6e0590
100% coverage?
henrikjacobsenfys Dec 16, 2025
ea3cbad
100% coverage!
henrikjacobsenfys Dec 16, 2025
64cf5fd
Remove output from Jupyter notebook
henrikjacobsenfys Dec 16, 2025
9ac4159
update notebook
henrikjacobsenfys Dec 16, 2025
f862067
Respond to PR comments
henrikjacobsenfys Dec 16, 2025
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
12 changes: 5 additions & 7 deletions examples/component_example.ipynb → examples/components.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,16 @@
"source": [
"delta = DeltaFunction(name='Delta', center=0.0, area=1.0)\n",
"x1=np.linspace(-2, 2, 100)\n",
"y=delta.evaluate(x1)\n",
"y1=delta.evaluate(x1)\n",
"x2=np.linspace(-2,2,51)\n",
"y2=delta.evaluate(x2)\n",
"plt.figure()\n",
"plt.plot(x1, y, label='Delta Function')\n",
"plt.plot(x1, y1, label='Delta Function')\n",
"plt.plot(x2, y2, label='Delta Function (coarser)')\n",
"plt.legend()\n",
"plt.show()\n",
"# The area under the Delta function is indeed equal to the area parameter.\n",
"xx=np.linspace(-2, 2, 10000)\n",
"yy=delta.evaluate(xx)\n",
"area= np.trapezoid(y, x1)\n",
"area= np.trapezoid(y1, x1)\n",
"print(area)\n"
]
},
Expand Down Expand Up @@ -114,7 +112,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "newdynamics",
"display_name": "easydynamics_newbase",
"language": "python",
"name": "python3"
},
Expand All @@ -128,7 +126,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.13"
"version": "3.12.12"
}
},
"nbformat": 4,
Expand Down
154 changes: 154 additions & 0 deletions examples/convolution.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "f42e34d0",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from easydynamics.sample_model import DeltaFunction, Gaussian, Lorentzian, SampleModel, DampedHarmonicOscillator\n",
"from easydynamics.convolution import Convolution \n",
"from easydynamics.utils import _detailed_balance_factor as detailed_balance_factor\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib widget\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "600c0850",
"metadata": {},
"outputs": [],
"source": [
"# Standard example of convolution of a sample model with a resolution model\n",
"sample_model=SampleModel(name='sample_model')\n",
"gaussian=Gaussian(name='Gaussian',width=0.5,area=1)\n",
"dho = DampedHarmonicOscillator(name='DHO',center=1.0,width=0.3,area=2.0)\n",
"lorentzian = Lorentzian(name='Lorentzian',center=-1.0,width=0.2,area=1.0)\n",
"delta = DeltaFunction(name='Delta',center=0.4,area=0.5)\n",
"sample_model.add_component(gaussian)\n",
"# sample_model.add_component(dho)\n",
"sample_model.add_component(lorentzian)\n",
"sample_model.add_component(delta)\n",
"\n",
"resolution_model = SampleModel(name='resolution_model')\n",
"resolution_gaussian=Gaussian(name='Resolution Gaussian',width=0.015,area=0.8)\n",
"resolution_lorentzian = Lorentzian(name='Resolution Lorentzian',width=0.025,area=0.2)\n",
"resolution_model.add_component(resolution_gaussian)\n",
"resolution_model.add_component(resolution_lorentzian)\n",
"\n",
"energy=np.linspace(-2, 2, 100)\n",
"\n",
"convolver = Convolution(sample_model=sample_model, resolution_model=resolution_model, energy=energy)\n",
"y = convolver.convolution()\n",
"plt.figure()\n",
"plt.plot(energy, y, label='Convoluted Model')\n",
"plt.xlabel('Energy (meV)')\n",
"plt.ylabel('Intensity (arb. units)')\n",
"plt.title('Convolution of Sample Model with Resolution Model')\n",
"\n",
"plt.plot(energy, sample_model.evaluate(energy), label='Sample Model', linestyle='--')\n",
"plt.plot(energy, resolution_model.evaluate(energy), label='Resolution Model', linestyle=':')\n",
"\n",
"\n",
"plt.legend()\n",
"# set the limit on the y axis\n",
"plt.ylim(0,6)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7d49acae",
"metadata": {},
"outputs": [],
"source": [
"convolver.upsample_factor"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fede1a58",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Use some of the extra settings for the numerical convolution\n",
"sample_model=SampleModel(name='sample_model')\n",
"gaussian=Gaussian(name='Gaussian',width=0.3,area=1)\n",
"dho = DampedHarmonicOscillator(name='DHO',center=1.0,width=0.3,area=2.0)\n",
"lorentzian = Lorentzian(name='Lorentzian',center=-1.0,width=0.2,area=1.0)\n",
"delta = DeltaFunction(name='Delta',center=0.4,area=0.5)\n",
"sample_model.add_component(gaussian)\n",
"sample_model.add_component(dho)\n",
"sample_model.add_component(lorentzian)\n",
"\n",
"resolution_model = SampleModel(name='resolution_model')\n",
"resolution_gaussian=Gaussian(name='Resolution Gaussian',width=0.15,area=0.8)\n",
"resolution_lorentzian = Lorentzian(name='Resolution Lorentzian',width=0.25,area=0.2)\n",
"resolution_model.add_component(resolution_gaussian)\n",
"resolution_model.add_component(resolution_lorentzian)\n",
"\n",
"energy=np.linspace(-2, 2, 100)\n",
"\n",
"\n",
"temperature = 10.0 # Temperature in Kelvin\n",
"offset = 0.5\n",
"upsample_factor = 5\n",
"extension_factor = 0.5\n",
"plt.figure()\n",
"plt.xlabel('Energy (meV)')\n",
"plt.ylabel('Intensity (arb. units)')\n",
"\n",
"convolver = Convolution(\n",
" sample_model=sample_model, \n",
" resolution_model=resolution_model, \n",
" energy=energy-offset, \n",
" upsample_factor=upsample_factor,\n",
" extension_factor=extension_factor,\n",
" temperature=temperature,\n",
" normalize_detailed_balance=True,)\n",
"y = convolver.convolution()\n",
"\n",
"\n",
"plt.plot(energy, y, label='Convoluted Model')\n",
"\n",
"plt.plot(energy, sample_model.evaluate(energy-offset)*detailed_balance_factor(energy-offset, temperature), label='Sample Model with DB', linestyle='--')\n",
"\n",
"plt.plot(energy, resolution_model.evaluate(energy ), label='Resolution Model', linestyle=':')\n",
"plt.title('Convolution of Sample Model with Resolution Model with detailed balancing')\n",
"\n",
"plt.legend()\n",
"plt.ylim(0,2.5)\n",
"plt.show()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "newdynamics",
"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.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
92 changes: 7 additions & 85 deletions examples/detailed_balance.ipynb

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions examples/sample_model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "64deaa41",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from easydynamics.sample_model import Gaussian\n",
"from easydynamics.sample_model import Lorentzian\n",
"from easydynamics.sample_model import DampedHarmonicOscillator\n",
"from easydynamics.sample_model import Polynomial\n",
"\n",
"from easydynamics.sample_model import SampleModel\n",
"\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "784d9e82",
"metadata": {},
"outputs": [],
"source": [
"sample_model=SampleModel(name='sample_model')\n",
"\n",
"# Creating components\n",
"gaussian=Gaussian(name='Gaussian',width=0.5,area=1)\n",
"dho = DampedHarmonicOscillator(name='DHO',center=1.0,width=0.3,area=2.0)\n",
"lorentzian = Lorentzian(name='Lorentzian',center=-1.0,width=0.2,area=1.0)\n",
"polynomial = Polynomial(name='Polynomial',coefficients=[0.1, 0, 0.5]) # y=0.1+0.5*x^2\n",
"\n",
"sample_model.add_component(gaussian)\n",
"sample_model.add_component(dho)\n",
"sample_model.add_component(lorentzian)\n",
"sample_model.add_component(polynomial)\n",
"\n",
"\n",
"x=np.linspace(-2, 2, 100)\n",
"\n",
"plt.figure()\n",
"y=sample_model.evaluate(x)\n",
"plt.plot(x, y, label='Sample Model')\n",
"\n",
"for component in list(sample_model):\n",
" y = component.evaluate(x)\n",
" plt.plot(x, y, label=component.name)\n",
"\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d35179d8",
"metadata": {},
"outputs": [],
"source": [
"# sample_model=SampleModel(name='sample_model')\n",
"sample_model.components"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "newdynamics",
"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.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
3 changes: 3 additions & 0 deletions src/easydynamics/convolution/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .convolution import Convolution

__all__ = ["Convolution"]
Loading