Skip to content

Commit

Permalink
only parameters in project
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Nov 6, 2024
1 parent 3965023 commit 49368a2
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/easyreflectometry/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.ObjectClasses import BaseObj

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.parameter_utils import yaml_dump
from easyreflectometry.utils import get_as_parameter
from easyreflectometry.utils import yaml_dump
from easyreflectometry.sample import BaseAssembly
from easyreflectometry.sample import Sample

Expand Down
4 changes: 3 additions & 1 deletion src/easyreflectometry/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from easyreflectometry.sample import Multilayer
from easyreflectometry.sample import Sample
from easyreflectometry.sample.collections.base_collection import BaseCollection
from easyreflectometry.utils import collect_unique_names_from_dict

Q_MIN = 0.001
Q_MAX = 0.3
Expand Down Expand Up @@ -67,10 +68,11 @@ def reset(self):

@property
def parameters(self) -> List[Parameter]:
unique_names_in_project = collect_unique_names_from_dict(self.as_dict())
parameters = []
for vertice_str in global_object.map.vertices():
vertice_obj = global_object.map.get_item_by_key(vertice_str)
if isinstance(vertice_obj, Parameter):
if isinstance(vertice_obj, Parameter) and vertice_str in unique_names_in_project:
parameters.append(vertice_obj)
return parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter

from ..collections.layer_collection import LayerCollection
from ..elements.layers.layer import Layer
Expand Down
2 changes: 1 addition & 1 deletion src/easyreflectometry/sample/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from easyscience.Objects.ObjectClasses import BaseObj

from easyreflectometry.parameter_utils import yaml_dump
from easyreflectometry.utils import yaml_dump


class BaseCore(BaseObj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from easyscience import global_object
from easyscience.Objects.Groups import BaseCollection as EasyBaseCollection

from easyreflectometry.parameter_utils import yaml_dump
from easyreflectometry.utils import yaml_dump


class BaseCollection(EasyBaseCollection):
Expand Down
2 changes: 1 addition & 1 deletion src/easyreflectometry/sample/elements/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter

from ...base_core import BaseCore
from ..materials.material import Material
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from easyscience.Constraints import FunctionalConstraint
from easyscience.Objects.new_variable import Parameter

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter
from easyreflectometry.special.calculations import area_per_molecule_to_scattering_length_density
from easyreflectometry.special.calculations import neutron_scattering_length

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter

from ...base_core import BaseCore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from easyscience.Constraints import FunctionalConstraint
from easyscience.Objects.new_variable import Parameter

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter
from easyreflectometry.special.calculations import density_to_sld
from easyreflectometry.special.calculations import molecular_weight
from easyreflectometry.special.calculations import neutron_scattering_length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from easyscience.Constraints import FunctionalConstraint
from easyscience.Objects.new_variable import Parameter

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter
from easyreflectometry.special.calculations import weighted_average

from ...base_core import BaseCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter

from .material import Material
from .material_mixture import MaterialMixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ def get_as_parameter(

def yaml_dump(dict_repr: dict) -> str:
return yaml.dump(dict_repr, sort_keys=False, allow_unicode=True)


def collect_unique_names_from_dict(structure_dict: dict, unique_names: Optional[list[str]] = None) -> dict:
"""
This function returns a list with the 'unique_name' found the input dictionary.
"""
if unique_names is None:
unique_names = []

for key, value in structure_dict.items():
if isinstance(value, dict):
collect_unique_names_from_dict(value, unique_names)
elif isinstance(value, list):
for element in value:
collect_unique_names_from_dict(element, unique_names)
if key == 'unique_name':
unique_names.append(value)
return unique_names
2 changes: 1 addition & 1 deletion tests/sample/elements/layers/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from numpy.testing import assert_equal

from easyreflectometry.calculators.factory import CalculatorFactory
from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter
from easyreflectometry.sample.elements.layers.layer import DEFAULTS
from easyreflectometry.sample.elements.layers.layer import Layer
from easyreflectometry.sample.elements.materials.material import Material
Expand Down
2 changes: 1 addition & 1 deletion tests/sample/elements/materials/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
from easyscience import global_object

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter
from easyreflectometry.sample.elements.materials.material import DEFAULTS
from easyreflectometry.sample.elements.materials.material import Material

Expand Down
2 changes: 1 addition & 1 deletion tests/test_parameter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from numpy.testing import assert_equal

from easyreflectometry.parameter_utils import get_as_parameter
from easyreflectometry.utils import get_as_parameter

PARAMETER_DETAILS = {
'test_parameter': {
Expand Down
13 changes: 11 additions & 2 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def test_constructor(self):
assert project._report is None
assert project._created is False
assert project._with_experiments is False
assert project._current_material_index == 0
assert project._current_model_index == 0
assert project._current_assembly_index == 0
assert project._current_layer_index == 0
assert project._fitter is None
assert project._current_model_index is None
assert project._q_min is None
assert project._q_max is None
assert project._q_resolution is None
Expand All @@ -63,7 +66,10 @@ def test_reset(self):
project._with_experiments = True
project._path_project_parent = 'project_path'
project._fitter = 'fitter'
project._current_material_index = 10
project._current_model_index = 10
project._current_assembly_index = 10
project._current_layer_index = 10
project._q_min = 'q_min'
project._q_max = 'q_max'
project._q_resolution == 'q_resolution'
Expand Down Expand Up @@ -91,7 +97,10 @@ def test_reset(self):
assert project._with_experiments is False
assert global_object.map.vertices() == ['project_models', 'project_materials']
assert project._fitter is None
assert project._current_model_index is None
assert project._current_material_index == 0
assert project._current_model_index == 0
assert project._current_assembly_index == 0
assert project._current_layer_index == 0
assert project._q_min is None
assert project._q_max is None
assert project._q_resolution is None
Expand Down

0 comments on commit 49368a2

Please sign in to comment.