Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 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
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
File renamed without changes.
144 changes: 144 additions & 0 deletions examples/convolution.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"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.utils import convolution \n",
"from easydynamics.utils import _detailed_balance_factor as detailed_balance_factor\n",
"\n",
"import matplotlib.pyplot as plt"
]
},
{
"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.2,area=0.8)\n",
"resolution_lorentzian = Lorentzian(name='Resolution Lorentzian',width=0.2,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",
"y = convolution(sample_model=sample_model,\n",
" resolution_model=resolution_model,\n",
" energy=energy,\n",
" )\n",
"\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)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fede1a58",
"metadata": {},
"outputs": [],
"source": [
"# Use some of the extra settings for the numerical convolution\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",
"\n",
"resolution_model = SampleModel(name='resolution_model')\n",
"resolution_gaussian=Gaussian(name='Resolution Gaussian',width=0.2,area=0.8)\n",
"resolution_lorentzian = Lorentzian(name='Resolution Lorentzian',width=0.2,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 = 15.0 # Temperature in Kelvin\n",
"offset = 0.3\n",
"upsample_factor = 5\n",
"extension_factor = 0.2\n",
"\n",
"plt.xlabel('Energy (meV)')\n",
"plt.ylabel('Intensity (arb. units)')\n",
"\n",
"y = convolution(sample_model=sample_model,\n",
" resolution_model=resolution_model,\n",
" energy=energy,\n",
" offset=offset,\n",
" method=\"auto\",\n",
" upsample_factor=upsample_factor,\n",
" extension_factor=extension_factor,\n",
" temperature=temperature,\n",
" normalize_detailed_balance=True,\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",
"\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
}
144 changes: 144 additions & 0 deletions examples/sample_model.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/easydynamics/sample_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Polynomial,
Voigt,
)
from .sample_model import SampleModel

__all__ = [
"SampleModel",
Expand Down
Loading