Skip to content

Commit

Permalink
Merge pull request #98 from aglavic/release
Browse files Browse the repository at this point in the history
Release version 1.1
  • Loading branch information
aglavic authored Mar 3, 2023
2 parents efd3abb + 7ba5595 commit f34bfd6
Show file tree
Hide file tree
Showing 8 changed files with 624 additions and 11 deletions.
17 changes: 17 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
History
=======

1.1.0 (2023-02-20)
------------------

* Introduction of simple model language that can be used to describe
sample structures. The module *orsopy.fileio.model_language* is used to implement
and parse the model language.
See https://www.reflectometry.org/projects/simple_model for specifications.
Sample model examples can be found in the examples folder together
with scripts using the orsopy module to parse and plot the data.
* Add polarization channels for x-ray experiments
* Implement ErrorValue class for optional description of errors
on values within the file header.
* Update of .ort standard according to discussions with community.
(E.g. rename of column attribute "dimension" to "physical_quantity")

1.0.1 (2022-06-28)
------------------

* Fix bug that did allow some dictionary type values to be created in Sample.
* Update the schema files for released .ort standard.
* Sample.sample_parameters keys to be strings and values restricted to
Value, ValueRange, ValueVector or ComplexValue.
* Add *as_unit* method to value classes that uses the *pint* library to convert
values to supplied unit automatically.

1.0.0 (2022-06-10)
------------------
Expand Down
6 changes: 3 additions & 3 deletions examples/simple_model_example_3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ sample:
substrate:
sequence:
- material: Si
sigma: 2
roughness: 2
- material: SiO2
thickness: 5
sigma: 3
roughness: 3
film:
repetitions: 5
stack: head_group 4 | tail | tail | head_group 4
Expand All @@ -35,7 +35,7 @@ sample:
H2O: 0.3
D2O: 0.7
globals:
sigma: {magnitude: 5, unit: angstrom}
roughness: {magnitude: 5, unit: angstrom}
length_unit: angstrom
mass_density_unit: g/cm^3
sld_unit: 1/angstrom^2
Expand Down
2 changes: 1 addition & 1 deletion orsopy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Top-level package for orsopy."""

__version__ = "1.0.1"
__version__ = "1.1.0"
11 changes: 11 additions & 0 deletions orsopy/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@

def _field_init(f, frozen, locals, self_name):
return _field_init_real(f, frozen, locals, self_name, False)


elif sys.version_info < (3, 7, 0):
# fix bug in python 3.6 when using default_factory for dataclass objects
_orig_field = field

def field(*args, **opts):
if "default_factory" in opts and not opts["default_factory"] in [list, tuple]:
return opts["default_factory"]()
else:
return _orig_field(*args, **opts)
23 changes: 17 additions & 6 deletions orsopy/fileio/model_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from typing import Any, Dict, List, Optional, Union

from ..dataclasses import field
from ..utils.chemical_formula import Formula
from ..utils.density_resolver import DensityResolver
from .base import ComplexValue, Header, Value, orsodataclass
Expand All @@ -26,12 +27,12 @@ def find_idx(string, start, value):

@orsodataclass
class ModelParameters(Header):
roughness: Optional[Value] = Value(0.3, "nm")
length_unit: Optional[str] = "nm"
mass_density_unit: Optional[str] = "g/cm^3"
number_density_unit: Optional[str] = "1/nm^3"
sld_unit: Optional[str] = "1/angstrom^2"
magnetic_moment_unit: Optional[str] = "muB"
roughness: Value = field(default_factory=lambda: Value(0.3, "nm"))
length_unit: str = "nm"
mass_density_unit: str = "g/cm^3"
number_density_unit: str = "1/nm^3"
sld_unit: str = "1/angstrom^2"
magnetic_moment_unit: str = "muB"


@orsodataclass
Expand Down Expand Up @@ -152,6 +153,8 @@ def get_sld(self, xray_energy=None) -> complex:
class Composit(Header):
composition: Dict[str, float]

original_name = None

def resolve_names(self, resolvable_items):
self._composition_materials = {}
for key, value in self.composition.items():
Expand Down Expand Up @@ -288,6 +291,8 @@ class SubStack(Header):
arguments: Optional[List[Any]] = None
keywords: Optional[Dict[str, Any]] = None

original_name = None

def resolve_names(self, resolvable_items):
if self.stack is None and self.sequence is None:
raise ValueError("SubStack has to either define stack or sequence")
Expand Down Expand Up @@ -319,6 +324,7 @@ def resolve_names(self, resolvable_items):
obj.thickness = thickness
else:
obj = Layer(material=item, thickness=thickness)
obj.original_name = item
if hasattr(obj, "resolve_names"):
obj.resolve_names(resolvable_items)
output.append(obj)
Expand Down Expand Up @@ -375,6 +381,8 @@ def __post_init__(self):
def resolvable_items(self):
output = {}
if self.sub_stacks:
for key, ssi in self.sub_stacks.items():
ssi.original_name = key
output.update(self.sub_stacks)
if self.layers:
for key, li in self.layers.items():
Expand All @@ -385,6 +393,8 @@ def resolvable_items(self):
mi.original_name = key
output.update(self.materials)
if self.composits:
for key, ci in self.composits.items():
ci.original_name = key
output.update(self.composits)
return output

Expand Down Expand Up @@ -421,6 +431,7 @@ def resolve_stack(self):
obj.thickness = thickness
else:
obj = Layer(material=item, thickness=thickness)
obj.original_name = item
if hasattr(obj, "resolve_names"):
obj.resolve_names(ri)
if hasattr(obj, "resolve_defaults"):
Expand Down
Loading

0 comments on commit f34bfd6

Please sign in to comment.