Skip to content
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
81b437e
update definitions
lukaspie Mar 6, 2025
5b7a4f5
change plugin branches for testing
lukaspie Mar 6, 2025
e19509e
update definitions once more
lukaspie Mar 7, 2025
912e60c
initial attempt at nameType in validation
lukaspie Mar 7, 2025
a64af5e
update defs again
lukaspie Mar 7, 2025
882ff00
update defs
lukaspie Mar 10, 2025
971db9a
nameType fixes, remove prints
lukaspie Mar 11, 2025
d9b7921
implement test cases for partial nameType and open enums
lukaspie Mar 11, 2025
f632f48
implement open enums in the validation
lukaspie Mar 11, 2025
14da1bf
add NX_CHAR_OR_NUMBER to NeXusTree
lukaspie Mar 11, 2025
19eea47
properly build inheritance and siblings
lukaspie Mar 11, 2025
3032895
extends NXobject in NeXusTree
lukaspie Mar 11, 2025
94193ca
update defs to feature branch for dev_tools
lukaspie Mar 11, 2025
c4e57f9
implement test for open enum
lukaspie Mar 11, 2025
dead37b
reorganize open enum tests in validatation
lukaspie Mar 11, 2025
8ecad81
adjust namefitting for is_documented
lukaspie Mar 11, 2025
df9f59a
test for identifier in nested NXdata
lukaspie Mar 11, 2025
c5087f8
remove improper test value from NXdata
lukaspie Mar 11, 2025
06405eb
change back to fairmat branch for definitions
lukaspie Mar 12, 2025
6a3ae12
use new NXroot attributs
lukaspie Mar 12, 2025
0dfa370
support complex units like eV/mm in nomad schema generation
lukaspie Mar 12, 2025
c3f4428
mypy fix
lukaspie Mar 12, 2025
b186762
remove print statements
lukaspie Mar 12, 2025
3b0c956
adjust docstrings
lukaspie Mar 12, 2025
61e30ea
update definitions once more
lukaspie Mar 14, 2025
b52aeb4
Merge branch 'master' into update-defs-and-related-tools
lukaspie Mar 17, 2025
098fe0e
remove NXtest2, check NXtest more thoroughly
lukaspie Mar 17, 2025
76d32cd
remove print statement
lukaspie Mar 17, 2025
4572927
update ref nexus log
lukaspie Mar 17, 2025
7865b39
catch another pint error
lukaspie Mar 17, 2025
32e32f9
ignore one test case
lukaspie Mar 17, 2025
741c4a8
update defs
lukaspie Mar 17, 2025
3d1b37c
add a test for unit examples
lukaspie Mar 17, 2025
0d0e7e5
only give UnitWithoutDocumentation if not ignore_undocumented
lukaspie Mar 17, 2025
3277974
add a test for variadic concept for required field
lukaspie Mar 18, 2025
ce96690
adding tests for checking attributes
sanbrock Mar 18, 2025
4e0e8db
Merge remote-tracking branch 'refs/remotes/origin/update-defs-and-rel…
sanbrock Mar 18, 2025
4753cb2
add test for nameType=any
lukaspie Mar 19, 2025
9544651
properly handle variadic attributes in groups and fields
lukaspie Mar 19, 2025
0b73752
fix reader test
lukaspie Mar 19, 2025
0cb5be1
Merge branch 'master' into update-defs-and-related-tools
lukaspie Mar 19, 2025
c211caf
update test framework for plugins to allow skipping expected output
lukaspie Mar 19, 2025
feec5df
add tests for identifierNAME
lukaspie Mar 19, 2025
7b9546e
handling of identifierNAME and NXcollection
lukaspie Mar 19, 2025
53bdacb
correctly check for named collections
lukaspie Mar 19, 2025
05ce29f
linting fix
lukaspie Mar 19, 2025
3eba315
remove commented code
lukaspie Mar 19, 2025
0c6db81
update defs
lukaspie Mar 20, 2025
9ac4396
use uppercase HDF5_Version in NXroot writing
lukaspie Mar 20, 2025
a2b3b34
use main branches for raman and ellips again
lukaspie Mar 20, 2025
5ba7b2f
dont collect illegal unit in NXcollection
lukaspie Mar 20, 2025
737c5e3
fix unit examples in NOMAD
lukaspie Mar 20, 2025
7b590cc
update definitions once more
lukaspie Mar 20, 2025
b9fbc9d
update CITATION.cff before release
lukaspie Mar 20, 2025
b454916
reset plugin test branches
lukaspie Mar 20, 2025
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
8 changes: 4 additions & 4 deletions .github/workflows/plugin_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
branch: main
tests_to_run: tests/.
- plugin: pynxtools-ellips
branch: main
branch: update
tests_to_run: tests/.
- plugin: pynxtools-em
branch: main
Expand All @@ -36,13 +36,13 @@ jobs:
branch: update-definitions
tests_to_run: tests/.
- plugin: pynxtools-raman
branch: main
branch: update
tests_to_run: tests/.
- plugin: pynxtools-spm
branch: main
branch: FixReaderAlngAppDef
tests_to_run: tests/.
- plugin: pynxtools-xps
branch: main
branch: update-to-new-nxmpes
tests_to_run: tests/.
- plugin: pynxtools-xrd
branch: main
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"lxml>=4.9.1",
"toposort>=1.10.0",
"anytree",
"pint==0.17",
Comment thread
rettigl marked this conversation as resolved.
]

[project.urls]
Expand Down
20 changes: 13 additions & 7 deletions src/pynxtools/data/NXtest.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
<item value="NXtest"/>
</enumeration>
</field>
<group type="NXdata" name="OPTIONAL_group" optional="true">
<group type="NXdata" name="OPTIONAL_group" optional="true" nameType="partial">
<field name="required_field" required="true" type="NX_INT">
<doc>A dummy entry to test optional parent check for a required child.</doc>
</field>
<field name="optional_field" optional="true" type="NX_INT">
<doc>A dummy entry to test optional parent check for an optional child.</doc>
</field>
</group>
<group type="NXdata" name="NXODD_name">
<field name="anamethatRENAMES" nameType="any" type="NX_INT" units="NX_UNITLESS"/>
<group type="NXdata" name="NXODD_name" nameType="partial">
<field name="anamethatRENAMES" nameType="partial" type="NX_INT" units="NX_UNITLESS"/>
Comment thread
lukaspie marked this conversation as resolved.
<field name="float_value" type="NX_FLOAT" optional="true" units="NX_ENERGY">
<doc>A dummy entry for a float value.</doc>
</field>
Expand All @@ -52,10 +52,10 @@
</field>
<field name="type">
<enumeration>
<item value="1st type" />
<item value="2nd type" />
<item value="3rd type" />
<item value="4th type" />
<item value="1st type"/>
<item value="2nd type"/>
<item value="3rd type"/>
<item value="4th type"/>
</enumeration>
<attribute name="array" type="NX_INT">
<enumeration>
Expand All @@ -64,6 +64,12 @@
</enumeration>
</attribute>
</field>
<field name="type2" optional="true">
<enumeration open="true">
<item value="1st type open"/>
<item value="2nd type open"/>
</enumeration>
</field>
<attribute name="group_attribute">
</attribute>
<attribute name="signal">
Expand Down
82 changes: 54 additions & 28 deletions src/pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,25 @@
class ValidationProblem(Enum):
UnitWithoutDocumentation = 1
InvalidEnum = 2
MissingRequiredGroup = 3
MissingRequiredField = 4
MissingRequiredAttribute = 5
InvalidType = 6
InvalidDatetime = 7
IsNotPosInt = 8
ExpectedGroup = 9
MissingDocumentation = 10
MissingUnit = 11
ChoiceValidationError = 12
UnitWithoutField = 13
AttributeForNonExistingField = 14
BrokenLink = 15
FailedNamefitting = 16
NXdataMissingSignalData = 17
NXdataMissingAxisData = 18
NXdataAxisMismatch = 19
KeyToBeRemoved = 20
OpenEnumWithNewItem = 3
MissingRequiredGroup = 4
MissingRequiredField = 5
MissingRequiredAttribute = 6
InvalidType = 7
InvalidDatetime = 8
IsNotPosInt = 9
ExpectedGroup = 10
MissingDocumentation = 11
MissingUnit = 12
ChoiceValidationError = 13
UnitWithoutField = 14
AttributeForNonExistingField = 15
BrokenLink = 16
FailedNamefitting = 17
NXdataMissingSignalData = 18
NXdataMissingAxisData = 19
NXdataAxisMismatch = 20
KeyToBeRemoved = 21


class Collector:
Expand All @@ -85,7 +86,11 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
)
elif log_type == ValidationProblem.InvalidEnum:
logger.warning(
f"The value at {path} should be one of the following: {value}"
f"The value at {path} should be one of the following: {value}."
)
elif log_type == ValidationProblem.OpenEnumWithNewItem:
logger.info(
f"The value at {path} does not match with the enumerated items from the open enumeration: {value}."
)
elif log_type == ValidationProblem.MissingRequiredGroup:
logger.warning(f"The required group, {path}, hasn't been supplied.")
Expand Down Expand Up @@ -164,7 +169,10 @@ def collect_and_log(
if self.logging and path + str(log_type) + str(value) not in self.data:
self._log(path, log_type, value, *args, **kwargs)
# info messages should not fail validation
if log_type not in (ValidationProblem.UnitWithoutDocumentation,):
if log_type not in (
ValidationProblem.UnitWithoutDocumentation,
ValidationProblem.OpenEnumWithNewItem,
):
self.data.add(path + str(log_type) + str(value))

def has_validation_problems(self):
Expand Down Expand Up @@ -266,7 +274,7 @@ def get_all_parents_for(xml_elem: ET._Element) -> List[ET._Element]:
root = get_appdef_root(xml_elem)
inheritance_chain = []
extends = root.get("extends")
while extends is not None and extends != "NXobject":
while extends is not None:
parent_xml_root, _ = get_nxdl_root_and_path(extends)
extends = parent_xml_root.get("extends")
inheritance_chain.append(parent_xml_root)
Expand Down Expand Up @@ -489,6 +497,15 @@ def contains_uppercase(field_name: Optional[str]) -> bool:
return any(char.isupper() for char in field_name)


def is_variadic(name: str, name_type: str) -> bool:
"""
Determine if a name is variadic based on its nameType.
"""
if name:
return False if name_type == "specified" else True
return True


def convert_nexus_to_suggested_name(nexus_name):
"""Helper function to suggest a name for a group from its NeXus class."""
if contains_uppercase(nexus_name):
Expand Down Expand Up @@ -646,7 +663,9 @@ def convert_str_to_bool_safe(value: str) -> Optional[bool]:
raise ValueError(f"Could not interpret string '{value}' as boolean.")


def is_valid_data_field(value: Any, nxdl_type: str, nxdl_enum: list, path: str) -> Any:
def is_valid_data_field(
value: Any, nxdl_type: str, nxdl_enum: list, nxdl_enum_open: bool, path: str
) -> Any:
# todo: Check this function and write test for it. It seems the function is not
# working as expected.
"""Checks whether a given value is valid according to the type defined in the NXDL.
Expand Down Expand Up @@ -688,11 +707,18 @@ def is_valid_data_field(value: Any, nxdl_type: str, nxdl_enum: list, path: str)

# Check enumeration
if nxdl_enum is not None and value not in nxdl_enum:
collector.collect_and_log(
path,
ValidationProblem.InvalidEnum,
nxdl_enum,
)
if nxdl_enum_open:
collector.collect_and_log(
path,
ValidationProblem.OpenEnumWithNewItem,
nxdl_enum,
)
else:
collector.collect_and_log(
path,
ValidationProblem.InvalidEnum,
nxdl_enum,
)

return value

Expand Down Expand Up @@ -871,7 +897,7 @@ def update_and_warn(key: str, value: str):
"https://github.com/FAIRmat-NFDI/nexus_definitions/"
f"blob/{get_nexus_version_hash()}",
)
update_and_warn("/@NeXus_version", get_nexus_version())
update_and_warn("/@NeXus_release", get_nexus_version())
update_and_warn("/@HDF5_version", ".".join(map(str, h5py.h5.get_libversion())))
update_and_warn("/@h5py_version", h5py.__version__)

Expand Down
Loading