Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ node_modules
# Tox
.tox

# Git worktrees checked out inside the repository
.worktrees/

# Misc
.benchmarks
.cache
Expand Down
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ git add .
git commit -m "Improve performance of time integrator for large systems"
```

### Imports in Tutorials and Examples

Anything user-facing — the tutorial notebooks and the `python` examples
in docstrings — reaches EasyDynamics through a single namespace:

```python
import easydynamics as edyn

experiment = edyn.Experiment('Vanadium')
model = edyn.SampleModel(components=edyn.Gaussian(width=0.1))
```

Every public name is re-exported from `easydynamics`, so this always
works. Please do not mix in `import easydynamics.sample_model as sm`, or
reach into a module with
`from easydynamics.analysis.analysis1d import Analysis1d`: a reader then
has to scroll back to the imports to find out where a name came from.

If something you need is missing from `edyn.`, add it to `__all__` in
`src/easydynamics/__init__.py` rather than importing around it.

Inside the library itself, keep importing from the specific module that
defines a name. Only the public front door is flat.

---

## 6. Code Quality Checks
Expand Down
39 changes: 19 additions & 20 deletions docs/docs/tutorials/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"import pooch\n",
"\n",
"import easydynamics as edyn\n",
"import easydynamics.sample_model as sm\n",
"\n",
"%matplotlib widget"
]
Expand Down Expand Up @@ -56,28 +55,28 @@
"# Example of Analysis with a simple sample model and instrument model\n",
"# The scattering from vanadium is purely elastic, so we model it with a\n",
"# delta function\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = sm.SampleModel(\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = edyn.SampleModel(\n",
" components=delta_function,\n",
")\n",
"\n",
"# The resolution is in this case modeled as a Gaussian. However, we can\n",
"# add as many components as we like to the resolution model\n",
"res_gauss = sm.Gaussian(width=0.1)\n",
"res_gauss = edyn.Gaussian(width=0.1)\n",
"res_gauss.area.fixed = True\n",
"resolution_components = sm.ComponentCollection()\n",
"resolution_components = edyn.ComponentCollection()\n",
"resolution_components.append_component(res_gauss)\n",
"resolution_model = sm.ResolutionModel(components=resolution_components)\n",
"resolution_model = edyn.ResolutionModel(components=resolution_components)\n",
"\n",
"# The background model is created in the same way. In this case, we use\n",
"# a flat background\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"# We combine the resolution abd background model into an instrument\n",
"# model. This model also contains a small energy offset to account for\n",
"# instrument misalignment.\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" resolution_model=resolution_model,\n",
" background_model=background_model,\n",
")\n",
Expand Down Expand Up @@ -190,19 +189,19 @@
"# Now we set up the model, similarly to how we set up the model for the\n",
"# vanadium data.\n",
"\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"lorentzian = sm.Lorentzian(display_name='Lorentzian', area=0.5, width=0.3)\n",
"component_collection = sm.ComponentCollection(\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"lorentzian = edyn.Lorentzian(display_name='Lorentzian', area=0.5, width=0.3)\n",
"component_collection = edyn.ComponentCollection(\n",
" components=[delta_function, lorentzian],\n",
")\n",
"\n",
"sample_model = sm.SampleModel(\n",
"sample_model = edyn.SampleModel(\n",
" components=component_collection,\n",
")\n",
"\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" background_model=background_model,\n",
")\n",
"\n",
Expand Down Expand Up @@ -265,22 +264,22 @@
"# Let us now fit directly to a diffusion model. We replace the\n",
"# Lorentzian with a Brownian translational diffusion model and keep the\n",
"# other parameters the same.\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"component_collection = sm.ComponentCollection(\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"component_collection = edyn.ComponentCollection(\n",
" components=[delta_function],\n",
")\n",
"diffusion_model = sm.BrownianTranslationalDiffusion(\n",
"diffusion_model = edyn.BrownianTranslationalDiffusion(\n",
" display_name='Brownian Translational Diffusion', diffusion_coefficient=2.4e-9, scale=0.5\n",
")\n",
"\n",
"sample_model = sm.SampleModel(\n",
"sample_model = edyn.SampleModel(\n",
" components=component_collection,\n",
" diffusion_models=diffusion_model,\n",
")\n",
"\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" background_model=background_model,\n",
")\n",
"\n",
Expand Down
18 changes: 8 additions & 10 deletions docs/docs/tutorials/analysis1d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"import pooch\n",
"\n",
"import easydynamics as edyn\n",
"import easydynamics.sample_model as sm\n",
"from easydynamics.analysis.analysis1d import Analysis1d\n",
"\n",
"%matplotlib widget"
]
Expand Down Expand Up @@ -49,24 +47,24 @@
"metadata": {},
"outputs": [],
"source": [
"# Example of Analysis1d with a simple sample model and instrument model\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = sm.SampleModel(\n",
"# Example of edyn.Analysis1d with a simple sample model and instrument model\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = edyn.SampleModel(\n",
" components=delta_function,\n",
")\n",
"\n",
"res_gauss = sm.Gaussian(width=0.1)\n",
"resolution_model = sm.ResolutionModel(components=res_gauss)\n",
"res_gauss = edyn.Gaussian(width=0.1)\n",
"resolution_model = edyn.ResolutionModel(components=res_gauss)\n",
"\n",
"\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" resolution_model=resolution_model,\n",
" background_model=background_model,\n",
")\n",
"\n",
"my_analysis = Analysis1d(\n",
"my_analysis = edyn.Analysis1d(\n",
" display_name='Vanadium Analysis',\n",
" experiment=vanadium_experiment,\n",
" sample_model=sample_model,\n",
Expand Down
Loading