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
2 changes: 1 addition & 1 deletion .github/workflows/documentation-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.12
python-version: 3.11
- name: Install Pandoc, repo and dependencies
run: |
sudo apt install pandoc
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.11', '3.12']
os: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11','3.12']
python-version: ['3.11','3.12']
if: "!contains(github.event.head_commit.message, '[ci skip]')"

steps:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.md.
3. The pull request should work for Python, 3.10, 3.11 and 3.12, and for PyPy. Check
3. The pull request should work for Python, 3.11 and 3.12, and for PyPy. Check
https://travis-ci.com/easyScience/EasyReflectometryLib/pull_requests
and make sure that the tests pass for all supported Python versions.

Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/advancedfitting/multi_contrast.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@
"d83acmw.head_layer.area_per_molecule_parameter.enabled = True\n",
"d83acmw.tail_layer.area_per_molecule_parameter.enabled = True\n",
"\n",
"d70d2o.constain_multiple_contrast(d13d2o)\n",
"d83acmw.constain_multiple_contrast(d70d2o)"
"d70d2o.constrain_multiple_contrast(d13d2o)\n",
"d83acmw.constrain_multiple_contrast(d70d2o)"
]
},
{
Expand Down
69 changes: 64 additions & 5 deletions docs/src/tutorials/simulation/resolution_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"from easyreflectometry.model import Model\n",
"from easyreflectometry.model import LinearSpline\n",
"from easyreflectometry.model import PercentageFwhm\n",
"from easyreflectometry.model import Pointwise\n",
"from easyreflectometry.sample import Layer\n",
"from easyreflectometry.sample import Material\n",
"from easyreflectometry.sample import Multilayer\n",
Expand Down Expand Up @@ -115,6 +116,16 @@
"dict_reference['10'] = load(file_path_10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e5f65ed7",
"metadata": {},
"outputs": [],
"source": [
"dict_reference['0']"
]
},
{
"cell_type": "markdown",
"id": "1ab3a164-62c8-4bd3-b0d8-e6f22c83dc74",
Expand Down Expand Up @@ -251,9 +262,15 @@
"id": "defd6dd5-c618-4af6-a5c7-17532207f0a0",
"metadata": {},
"source": [
"## Resolution functions\n",
"\n",
"We now define the different resoultion functions. "
"## Resolution functions "
]
},
{
"cell_type": "markdown",
"id": "c9d903db",
"metadata": {},
"source": [
"We can now define the different resoultion functions. "
]
},
{
Expand Down Expand Up @@ -376,11 +393,53 @@
"plt.yscale('log')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43881642",
"metadata": {},
"outputs": [],
"source": [
"key = '1'\n",
"reference_coords = dict_reference[key]['coords']['Qz_0'].values\n",
"reference_variances = dict_reference[key]['coords']['Qz_0'].variances\n",
"reference_data = dict_reference[key]['data']['R_0'].values\n",
"model_coords = np.linspace(\n",
" start=min(reference_coords),\n",
" stop=max(reference_coords),\n",
" num=1000,\n",
")\n",
"\n",
"model.resolution_function = resolution_function_dict[key]\n",
"model_data = model.interface().reflectity_profile(\n",
" model_coords,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data, 'k-', label=f'Variable', linewidth=5)\n",
"data_points = []\n",
"data_points.append(reference_coords) # Qz\n",
"data_points.append(reference_data) # R\n",
"data_points.append(reference_variances) # sQz\n",
"model.resolution_function = Pointwise(q_data_points=data_points)\n",
"model_data = model.interface().reflectity_profile(\n",
" model_coords,\n",
" model.unique_name,\n",
")\n",
"plt.plot(model_coords, model_data, 'r-', label=f'Pointwise')\n",
"\n",
"ax = plt.gca()\n",
"ax.set_xlim([-0.01, 0.45])\n",
"ax.set_ylim([1e-10, 2.5])\n",
"plt.legend()\n",
"plt.yscale('log')\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "easyref",
"display_name": "erl",
"language": "python",
"name": "python3"
},
Expand All @@ -394,7 +453,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
"version": "3.12.10"
}
},
"nbformat": 4,
Expand Down
50 changes: 24 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,40 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 3 - Alpha"
]

requires-python = ">=3.10,<3.13"
requires-python = ">=3.11,<3.13"

dependencies = [
"easyscience==1.3.0",
"scipp==25.2.0",
"refnx==0.1.52",
"refl1d[webview]==1.0.0a12",
"orsopy==1.2.1",
"xhtml2pdf==0.2.17",
"bumps==1.0.0b7",
"easyscience",
"scipp",
"refnx",
"refl1d>=1.0.0rc0",
"orsopy",
"xhtml2pdf",
"bumps",
]

[project.optional-dependencies]
dev = [
"build==1.2.2.post1",
"codecov==2.1.13",
"coverage==7.7.0",
"coveralls==4.0.1",
"flake8==7.1.2",
"ipykernel==6.29.5",
"jupyter==1.1.1",
"jupyterlab==4.3.6",
"plopp==25.3.0",
"pooch==1.8.2",
"pytest==8.3.5",
"pytest-cov==6.0.0",
"ruff==0.11.0",
"toml==0.10.2",
"yapf==0.43.0",
"build",
"codecov",
"coverage",
"coveralls",
"flake8",
"ipykernel",
"jupyter",
"jupyterlab",
"plopp",
"pooch",
"pytest",
"pytest-cov",
"ruff",
"toml",
"yapf",
]

docs = [
Expand Down Expand Up @@ -134,10 +133,9 @@ force-single-line = true
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = py{3.10,3.11,3.12}
envlist = py{3.11,3.12}
[gh-actions]
python =
3.10: py310
3.11: py311
3.12: py312
[gh-actions:env]
Expand Down
2 changes: 1 addition & 1 deletion src/easyreflectometry/calculators/bornagain/calculator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__author__ = 'github.com/arm61'

from easyscience.Objects.Inferface import ItemContainer
from easyscience.fitting.calculators.interface_factory import ItemContainer

from easyreflectometry.model import Model
from easyreflectometry.sample import Layer
Expand Down
6 changes: 3 additions & 3 deletions src/easyreflectometry/calculators/calculator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import Callable

import numpy as np
from easyscience.Objects.core import ComponentSerializer
from easyscience.Objects.Inferface import ItemContainer
from easyscience.fitting.calculators.interface_factory import ItemContainer
from easyscience.io import SerializerComponent

from easyreflectometry.model import Model
from easyreflectometry.sample import BaseAssembly
Expand All @@ -17,7 +17,7 @@
from .wrapper_base import WrapperBase


class CalculatorBase(ComponentSerializer, metaclass=ABCMeta):
class CalculatorBase(SerializerComponent, metaclass=ABCMeta):
"""
This class is a template and defines all properties that a calculator should have.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/easyreflectometry/calculators/factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = 'github.com/wardsimon'
from typing import Callable

from easyscience.Objects.Inferface import InterfaceFactoryTemplate
from easyscience.fitting.calculators.interface_factory import InterfaceFactoryTemplate

from easyreflectometry.calculators import CalculatorBase

Expand Down
25 changes: 19 additions & 6 deletions src/easyreflectometry/calculators/refl1d/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def create_item(self, name: str):

:param name: The name of the item
"""
self.storage['item'][name] = Repeat(
names.Stack(names.Slab(names.SLD(), thickness=0, interface=0)), name=str(name)
)
self.storage['item'][name] = Repeat(names.Stack(names.Slab(names.SLD(), thickness=0, interface=0)), name=str(name))
del self.storage['item'][name].stack[0]

def update_layer(self, name: str, **kwargs):
Expand All @@ -66,7 +64,9 @@ def get_layer_value(self, name: str, key: str) -> float:
:param key: The given value keys
"""
if key in ['magnetism_rhoM', 'magnetism_thetaM']:
return getattr(self.storage['layer'][name].magnetism, key.split('_')[-1]).value #TODO: check if we want to return the raw value or the full Parameter # noqa: E501
return getattr(
self.storage['layer'][name].magnetism, key.split('_')[-1]
).value # TODO: check if we want to return the raw value or the full Parameter # noqa: E501
return super().get_layer_value(name, key)

def create_model(self, name: str):
Expand Down Expand Up @@ -231,13 +231,20 @@ def _get_probe(
model_name: str,
storage: dict,
oversampling_factor: int = 1,
magnetism: bool = False,
) -> names.QProbe:
probe = names.QProbe(
Q=q_array,
dQ=dq_array,
intensity=storage['model'][model_name]['scale'],
background=storage['model'][model_name]['bkg'],
)

# Add theta_offset attribute if magnetism is enabled
# This is required for PolarizedQProbe to work correctly
if magnetism:
probe.theta_offset = names.Parameter.default(0, name='theta_offset')

if oversampling_factor > 1:
probe.calc_Qo = _get_oversampling_q(q_array, dq_array, oversampling_factor)
return probe
Expand All @@ -250,7 +257,7 @@ def _get_polarized_probe(
storage: dict,
oversampling_factor: int = 1,
all_polarizations: bool = False,
) -> names.PolarizedQProbe:
) -> names.PolarizedNeutronQProbe:
four_probes = []
for i in range(4):
if i == 0 or all_polarizations:
Expand All @@ -260,11 +267,17 @@ def _get_polarized_probe(
model_name=model_name,
storage=storage,
oversampling_factor=oversampling_factor,
magnetism=True, # Enable magnetism for polarized probes
)
else:
probe = None
four_probes.append(probe)
return names.PolarizedQProbe(xs=four_probes, name='polarized')

# Create polarized probe and work around initialization bug
polarized_probe = names.PolarizedNeutronQProbe.__new__(names.PolarizedNeutronQProbe)
polarized_probe._union_cache_key = None # Initialize missing attribute
polarized_probe.__init__(xs=four_probes, name='polarized')
return polarized_probe


def _build_sample(storage: dict, model_name: str) -> names.Stack:
Expand Down
10 changes: 6 additions & 4 deletions src/easyreflectometry/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from .data_store import ProjectData
from .measurement import load
from .measurement import load_as_dataset
from .measurement import merge_datagroups

__all__ = [
"load",
"load_as_dataset",
"ProjectData",
"DataSet1D",
'load',
'load_as_dataset',
'merge_datagroups',
'ProjectData',
'DataSet1D',
]
Loading
Loading