Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Apr 26, 2024
1 parent 1261e6a commit 485ffd9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 42 deletions.
4 changes: 2 additions & 2 deletions pynxtools/dataconverter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from pynxtools.dataconverter.readers.base.reader import BaseReader
from pynxtools.dataconverter.template import Template
from pynxtools.dataconverter.writer import Writer
from pynxtools.nexus import nexus
from pynxtools.definitions.dev_tools.utils.nxdl_utils import get_nexus_definitions_path

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -120,7 +120,7 @@ def get_nxdl_root_and_path(nxdl: str):
Error if no file with the given nxdl name is found.
"""
# Reading in the NXDL and generating a template
definitions_path = nexus.get_nexus_definitions_path()
definitions_path = get_nexus_definitions_path()
if nxdl == "NXtest":
nxdl_f_path = os.path.join(
f"{os.path.abspath(os.path.dirname(__file__))}/../../",
Expand Down
8 changes: 6 additions & 2 deletions pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from ase.data import chemical_symbols
from pint import UndefinedUnitError

import pynxtools.definitions.dev_tools.utils.nxdl_utils as nexus
from pynxtools import get_nexus_version, get_nexus_version_hash
from pynxtools.dataconverter.template import Template
from pynxtools.dataconverter.units import ureg
Expand All @@ -40,6 +41,9 @@
get_inherited_nodes,
get_node_at_nxdl_path,
)
from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
get_required_string as nexus_get_required_string,
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -212,7 +216,7 @@ def get_all_defined_required_children(nxdl_path, nxdl_name):
if nxdl_name == "NXtest":
return []

elist = nexus.get_inherited_nodes(nxdl_path, nx_name=nxdl_name)[2]
elist = get_inherited_nodes(nxdl_path, nx_name=nxdl_name)[2]
list_of_children_to_add = set()
for elem in elist:
list_of_children_to_add.update(get_all_defined_required_children_for_elem(elem))
Expand Down Expand Up @@ -315,7 +319,7 @@ def generate_template_from_nxdl(

def get_required_string(elem):
"""Helper function to return nicely formatted names for optionality."""
return nexus.get_required_string(elem)[2:-2].lower()
return nexus_get_required_string(elem)[2:-2].lower()


def convert_nexus_to_caps(nexus_name):
Expand Down
4 changes: 2 additions & 2 deletions pynxtools/dataconverter/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from pynxtools.dataconverter import helpers
from pynxtools.dataconverter.template import Template
from pynxtools.nexus import nexus
from pynxtools.definitions.dev_tools.utils.nxdl_utils import get_nexus_definitions_path

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,7 +68,7 @@ def _get_def_map(file: str) -> Dict[str, str]:


def _get_nxdl_root(nxdl: str) -> ET.Element:
definitions_path = nexus.get_nexus_definitions_path()
definitions_path = get_nexus_definitions_path()
nxdl_path = os.path.join(
definitions_path, "contributed_definitions", f"{nxdl}.nxdl.xml"
)
Expand Down
10 changes: 6 additions & 4 deletions pynxtools/dataconverter/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

from pynxtools.dataconverter import helpers
from pynxtools.dataconverter.exceptions import InvalidDictProvided
from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
NxdlAttributeNotFoundError,
get_node_at_nxdl_path,
)
from pynxtools.nexus import nexus

logger = logging.getLogger(__name__) # pylint: disable=C0103
Expand Down Expand Up @@ -219,10 +223,8 @@ def __nxdl_to_attrs(self, path: str = "/") -> dict:
nxdl_path = helpers.convert_data_converter_dict_to_nxdl_path(path)

try:
elem = nexus.get_node_at_nxdl_path(
nxdl_path, elem=copy.deepcopy(self.nxdl_data)
)
except nexus.NxdlAttributeNotFoundError:
elem = get_node_at_nxdl_path(nxdl_path, elem=copy.deepcopy(self.nxdl_data))
except NxdlAttributeNotFoundError:
return None

# Remove the name attribute as we only use it to name the HDF5 entry
Expand Down
20 changes: 10 additions & 10 deletions tests/data/dataconverter/readers/json_map/data.mapping.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"/ENTRY[entry]/NXODD_name[odd_name]/bool_value": "/a_level_down/bool_value",
"/ENTRY[entry]/NXODD_name[odd_name]/char_value": "/a_level_down/char_value",
"/ENTRY[entry]/NXODD_name[odd_name]/date_value": "/date_value",
"/ENTRY[entry]/NXODD_name[odd_name]/float_value": "/a_level_down/float_value",
"/ENTRY[entry]/NXODD_name[odd_name]/float_value/@units": "/a_level_down/float_value_units",
"/ENTRY[entry]/NXODD_name[odd_name]/int_value": "/a_level_down/int_value",
"/ENTRY[entry]/NXODD_name[odd_name]/int_value/@units": "/a_level_down/another_level_down/int_value_units",
"/ENTRY[entry]/NXODD_name[odd_name]/posint_value": "/a_level_down/another_level_down/posint_value",
"/ENTRY[entry]/NXODD_name[odd_name]/posint_value/@units": "/posint_value_units",
"/ENTRY[entry]/NXODD_name[odd_name]/type": "/type",
"/ENTRY[entry]/NXODD_name[nxodd_name]/bool_value": "/a_level_down/bool_value",
"/ENTRY[entry]/NXODD_name[nxodd_name]/char_value": "/a_level_down/char_value",
"/ENTRY[entry]/NXODD_name[nxodd_name]/date_value": "/date_value",
"/ENTRY[entry]/NXODD_name[nxodd_name]/float_value": "/a_level_down/float_value",
"/ENTRY[entry]/NXODD_name[nxodd_name]/float_value/@units": "/a_level_down/float_value_units",
"/ENTRY[entry]/NXODD_name[nxodd_name]/int_value": "/a_level_down/int_value",
"/ENTRY[entry]/NXODD_name[nxodd_name]/int_value/@units": "/a_level_down/another_level_down/int_value_units",
"/ENTRY[entry]/NXODD_name[nxodd_name]/posint_value": "/a_level_down/another_level_down/posint_value",
"/ENTRY[entry]/NXODD_name[nxodd_name]/posint_value/@units": "/posint_value_units",
"/ENTRY[entry]/NXODD_name[nxodd_name]/type": "/type",
"/ENTRY[entry]/definition": "/definition",
"/ENTRY[entry]/definition/@version": "/definition_version",
"/ENTRY[entry]/optional_parent/optional_child": {
Expand Down
49 changes: 27 additions & 22 deletions tests/nexus/test_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

import lxml.etree as ET

from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
get_inherited_nodes,
get_node_at_nxdl_path,
get_nx_attribute_type,
get_nx_classes,
get_nx_units,
)
from pynxtools.nexus import nexus

logger = logging.getLogger(__name__)
Expand All @@ -35,16 +42,16 @@ def test_get_nexus_classes_units_attributes():
the tested functions can be found in nexus.py file"""

# Test 1
nexus_classes_list = nexus.get_nx_classes()
nexus_classes_list = get_nx_classes()

assert "NXbeam" in nexus_classes_list

# Test 2
nexus_units_list = nexus.get_nx_units()
nexus_units_list = get_nx_units()
assert "NX_TEMPERATURE" in nexus_units_list

# Test 3
nexus_attribute_list = nexus.get_nx_attribute_type()
nexus_attribute_list = get_nx_attribute_type()
assert "NX_FLOAT" in nexus_attribute_list


Expand Down Expand Up @@ -86,59 +93,57 @@ def test_get_node_at_nxdl_path():
local_dir = os.path.abspath(os.path.dirname(__file__))
nxdl_file_path = os.path.join(local_dir, "../data/dataconverter/NXtest.nxdl.xml")
elem = ET.parse(nxdl_file_path).getroot()
node = nexus.get_node_at_nxdl_path("/ENTRY/NXODD_name", elem=elem)
node = get_node_at_nxdl_path("/ENTRY/NXODD_name", elem=elem)
assert node.attrib["type"] == "NXdata"
assert node.attrib["name"] == "NXODD_name"

node = nexus.get_node_at_nxdl_path("/ENTRY/NXODD_name/float_value", elem=elem)
node = get_node_at_nxdl_path("/ENTRY/NXODD_name/float_value", elem=elem)
assert node.attrib["type"] == "NX_FLOAT"
assert node.attrib["name"] == "float_value"

node = nexus.get_node_at_nxdl_path(
"/ENTRY/NXODD_name/AXISNAME/long_name", elem=elem
)
node = get_node_at_nxdl_path("/ENTRY/NXODD_name/AXISNAME/long_name", elem=elem)
assert node.attrib["name"] == "long_name"

nxdl_file_path = os.path.join(local_dir, "../data/nexus/NXtest2.nxdl.xml")
elem = ET.parse(nxdl_file_path).getroot()
node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/measurement/EVENT_DATA_EM/USER/affiliation", elem=elem
)
assert node.attrib["name"] == "affiliation"

node = nexus.get_node_at_nxdl_path("/ENTRY/measurement", elem=elem)
node = get_node_at_nxdl_path("/ENTRY/measurement", elem=elem)
assert node.attrib["type"] == "NXevent_data_em_set"

node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/measurement/EVENT_DATA_EM/SPECTRUM_SET/collection", elem=elem
)
assert node.attrib["type"] == "NXdata"

node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/measurement/EVENT_DATA_EM/SPECTRUM_SET/collection/DATA", elem=elem
)
assert node.attrib["type"] == "NX_NUMBER"

node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/measurement/EVENT_DATA_EM/SPECTRUM_SET/collection/AXISNAME_indices",
elem=elem,
)
assert node.attrib["name"] == "AXISNAME_indices"

node = nexus.get_node_at_nxdl_path("/ENTRY/COORDINATE_SYSTEM_SET", elem=elem)
node = get_node_at_nxdl_path("/ENTRY/COORDINATE_SYSTEM_SET", elem=elem)
assert node.attrib["type"] == "NXcoordinate_system_set"

node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/COORDINATE_SYSTEM_SET/TRANSFORMATIONS", elem=elem
)
assert node.attrib["type"] == "NXtransformations"

node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/COORDINATE_SYSTEM_SET/TRANSFORMATIONS/AXISNAME", elem=elem
)
assert node.attrib["type"] == "NX_NUMBER"

node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/COORDINATE_SYSTEM_SET/TRANSFORMATIONS/AXISNAME/transformation_type",
elem=elem,
)
Expand All @@ -149,12 +154,12 @@ def test_get_node_at_nxdl_path():
"../../pynxtools/definitions/contributed_definitions/NXiv_temp.nxdl.xml",
)
elem = ET.parse(nxdl_file_path).getroot()
node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/INSTRUMENT/ENVIRONMENT/voltage_controller", elem=elem
)
assert node.attrib["name"] == "voltage_controller"

node = nexus.get_node_at_nxdl_path(
node = get_node_at_nxdl_path(
"/ENTRY/INSTRUMENT/ENVIRONMENT/voltage_controller/calibration_time", elem=elem
)
assert node.attrib["name"] == "calibration_time"
Expand All @@ -168,17 +173,17 @@ def test_get_inherited_nodes():
"../../pynxtools/definitions/contributed_definitions/NXiv_temp.nxdl.xml",
)
elem = ET.parse(nxdl_file_path).getroot()
(_, _, elist) = nexus.get_inherited_nodes(
(_, _, elist) = get_inherited_nodes(
nxdl_path="/ENTRY/INSTRUMENT/ENVIRONMENT", elem=elem
)
assert len(elist) == 3

(_, _, elist) = nexus.get_inherited_nodes(
(_, _, elist) = get_inherited_nodes(
nxdl_path="/ENTRY/INSTRUMENT/ENVIRONMENT/voltage_controller", elem=elem
)
assert len(elist) == 4

(_, _, elist) = nexus.get_inherited_nodes(
(_, _, elist) = get_inherited_nodes(
nxdl_path="/ENTRY/INSTRUMENT/ENVIRONMENT/voltage_controller",
nx_name="NXiv_temp",
)
Expand Down

0 comments on commit 485ffd9

Please sign in to comment.