Skip to content

Commit

Permalink
fix for entry_type assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbrock committed Nov 15, 2024
1 parent 012dc6d commit f15d5f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/pynxtools/nomad/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,28 @@ def parse(
archive.metadata = EntryMetadata()

# Normalise experiment type
app_def = str(self.nx_root).split("(")[1].split(")")[0].split(",")[0]
app_defs = str(self.nx_root).split("(")[1].split(")")[0].split(",")
print(app_defs)
app_def_list = []
for app_elem in app_defs:
app = app_elem.lstrip()
try:
app_sec = getattr(self.nx_root, app)
try:
app_entry = getattr(app_sec, "ENTRY")
except AttributeError:
app_entry = getattr(app_sec, "entry")
app_def_list.append(
app if app != rename_nx_for_nomad("NXroot") else "Generic"
)
except AttributeError:
pass
if len(app_def_list) == 0:
app_def = "Experiment"
app_def = ", ".join(app_def_list) + (
" Experiment" if len(app_def_list) == 1 else "Experiments"
)
print(app_def)
if archive.metadata.entry_type is None:
archive.metadata.entry_type = app_def
archive.metadata.domain = "nexus"
Expand Down
2 changes: 1 addition & 1 deletion tests/nomad/test_metainfo_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@pytest.mark.parametrize(
"path,value",
[
pytest.param("name", "nexus"),
pytest.param("name", "pynxtools.nomad.schema"),
pytest.param("NXobject.name", "NXobject"),
pytest.param(rename_nx_for_nomad("NXentry") + ".nx_kind", "group"),
pytest.param(rename_nx_for_nomad("NXdetector") + ".real_time__field", "*"),
Expand Down

0 comments on commit f15d5f5

Please sign in to comment.