-
Notifications
You must be signed in to change notification settings - Fork 2
Validate NX_class against known NeXus class names #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
a0baa32
845f881
753330b
e3a231f
7edd233
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
| """NeXus base class names. | ||
|
|
||
| Source: https://github.com/nexusformat/definitions/tree/main/base_classes | ||
| Regenerated by ``tools/refresh_nexus_base_classes.py``; do not edit by hand. | ||
|
|
||
| Includes deprecated classes (NXgeometry, NXorientation, NXshape, NXtranslation), | ||
| which are flagged separately by NX_class_is_legacy. | ||
| """ | ||
|
|
||
| nexus_base_classes = frozenset( | ||
| [ | ||
| "NXaberration", | ||
| "NXactivity", | ||
| "NXactuator", | ||
| "NXaperture", | ||
| "NXapm_charge_state_analysis", | ||
| "NXapm_event_data", | ||
| "NXapm_instrument", | ||
| "NXapm_measurement", | ||
| "NXapm_ranging", | ||
| "NXapm_reconstruction", | ||
| "NXapm_simulation", | ||
| "NXatom", | ||
| "NXattenuator", | ||
| "NXbeam", | ||
| "NXbeam_stop", | ||
| "NXbeam_transfer_matrix_table", | ||
| "NXbending_magnet", | ||
| "NXcalibration", | ||
| "NXcapillary", | ||
| "NXcg_alpha_complex", | ||
| "NXcg_cylinder", | ||
| "NXcg_ellipsoid", | ||
| "NXcg_face_list_data_structure", | ||
| "NXcg_grid", | ||
| "NXcg_half_edge_data_structure", | ||
| "NXcg_hexahedron", | ||
| "NXcg_parallelogram", | ||
| "NXcg_point", | ||
| "NXcg_polygon", | ||
| "NXcg_polyhedron", | ||
| "NXcg_polyline", | ||
| "NXcg_primitive", | ||
| "NXcg_roi", | ||
| "NXcg_tetrahedron", | ||
| "NXcg_triangle", | ||
| "NXcg_unit_normal", | ||
| "NXchemical_composition", | ||
| "NXcircuit", | ||
| "NXcite", | ||
| "NXcollection", | ||
| "NXcollectioncolumn", | ||
| "NXcollimator", | ||
| "NXcomponent", | ||
| "NXcoordinate_system", | ||
| "NXcorrector_cs", | ||
| "NXcrystal", | ||
| "NXcs_computer", | ||
| "NXcs_filter_boolean_mask", | ||
| "NXcs_memory", | ||
| "NXcs_prng", | ||
| "NXcs_processor", | ||
| "NXcs_profiling", | ||
| "NXcs_profiling_event", | ||
| "NXcs_storage", | ||
| "NXcylindrical_geometry", | ||
| "NXdata", | ||
| "NXdeflector", | ||
| "NXdetector", | ||
| "NXdetector_channel", | ||
| "NXdetector_group", | ||
| "NXdetector_module", | ||
| "NXdisk_chopper", | ||
| "NXdistortion", | ||
| "NXebeam_column", | ||
| "NXelectromagnetic_lens", | ||
| "NXelectron_detector", | ||
| "NXelectronanalyzer", | ||
| "NXem_ebsd", | ||
| "NXem_eds", | ||
| "NXem_eels", | ||
| "NXem_event_data", | ||
| "NXem_img", | ||
| "NXem_instrument", | ||
| "NXem_interaction_volume", | ||
| "NXem_measurement", | ||
| "NXem_optical_system", | ||
| "NXem_simulation", | ||
| "NXenergydispersion", | ||
| "NXentry", | ||
| "NXenvironment", | ||
| "NXevent_data", | ||
| "NXfabrication", | ||
| "NXfermi_chopper", | ||
| "NXfilter", | ||
| "NXfit", | ||
| "NXfit_function", | ||
| "NXflipper", | ||
| "NXfresnel_zone_plate", | ||
| "NXgeometry", | ||
| "NXgrating", | ||
| "NXguide", | ||
| "NXhistory", | ||
| "NXibeam_column", | ||
| "NXimage", | ||
| "NXinsertion_device", | ||
| "NXinstrument", | ||
| "NXlog", | ||
| "NXmanipulator", | ||
| "NXmirror", | ||
| "NXmoderator", | ||
| "NXmonitor", | ||
| "NXmonochromator", | ||
| "NXnote", | ||
| "NXobject", | ||
| "NXoff_geometry", | ||
| "NXoptical_lens", | ||
| "NXoptical_window", | ||
| "NXorientation", | ||
| "NXparameters", | ||
| "NXpdb", | ||
| "NXpeak", | ||
| "NXphase", | ||
| "NXpid_controller", | ||
| "NXpinhole", | ||
| "NXpolarizer", | ||
| "NXpositioner", | ||
| "NXprocess", | ||
| "NXprogram", | ||
| "NXpump", | ||
| "NXreflections", | ||
| "NXregistration", | ||
| "NXresolution", | ||
| "NXroi_process", | ||
| "NXroot", | ||
| "NXrotations", | ||
| "NXsample", | ||
| "NXsample_component", | ||
| "NXscan_controller", | ||
| "NXsensor", | ||
| "NXshape", | ||
| "NXslit", | ||
| "NXsource", | ||
| "NXspectrum", | ||
| "NXspindispersion", | ||
| "NXsubentry", | ||
| "NXtransformations", | ||
| "NXtranslation", | ||
| "NXunit_cell", | ||
| "NXuser", | ||
| "NXvelocity_selector", | ||
| "NXwaveplate", | ||
| "NXxraylens", | ||
| ] | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
|
SimonHeybrock marked this conversation as resolved.
Outdated
|
||
| """Regenerate ``src/chexus/nexus_base_classes.py`` from the upstream NeXus | ||
| definitions repository. | ||
|
|
||
| Requires the GitHub CLI (``gh``) to be installed and authenticated. | ||
|
|
||
| Usage: | ||
| python tools/refresh_nexus_base_classes.py | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| REPO = "nexusformat/definitions" | ||
| DIRECTORY = "base_classes" | ||
| SUFFIX = ".nxdl.xml" | ||
| TARGET = ( | ||
| Path(__file__).resolve().parent.parent / "src" / "chexus" / "nexus_base_classes.py" | ||
| ) | ||
|
|
||
| HEADER = '''# SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sticking with 2023 now? I've noticed this in a couple of your files but wasn't sure if it's on purpose.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is a while since I looked at headers, just copy and paste from other file I suppose :D
SimonHeybrock marked this conversation as resolved.
Outdated
|
||
| """NeXus base class names. | ||
|
|
||
| Source: https://github.com/nexusformat/definitions/tree/main/base_classes | ||
| Regenerated by ``tools/refresh_nexus_base_classes.py``; do not edit by hand. | ||
|
|
||
| Includes deprecated classes (NXgeometry, NXorientation, NXshape, NXtranslation), | ||
| which are flagged separately by NX_class_is_legacy. | ||
| """ | ||
|
|
||
| nexus_base_classes = frozenset( | ||
| [ | ||
| ''' | ||
|
|
||
| FOOTER = """ ] | ||
| ) | ||
| """ | ||
|
|
||
|
|
||
| def fetch_names() -> list[str]: | ||
| result = subprocess.run( | ||
| ["gh", "api", f"repos/{REPO}/contents/{DIRECTORY}", "--jq", ".[].name"], | ||
| capture_output=True, | ||
| text=True, | ||
| check=True, | ||
| ) | ||
| names = [ | ||
| line.removesuffix(SUFFIX) | ||
| for line in result.stdout.splitlines() | ||
| if line.endswith(SUFFIX) | ||
| ] | ||
| return sorted(names) | ||
|
|
||
|
|
||
| def render(names: list[str]) -> str: | ||
| body = "".join(f' "{name}",\n' for name in names) | ||
| return HEADER + body + FOOTER | ||
|
|
||
|
|
||
| def main() -> int: | ||
| names = fetch_names() | ||
| if not names: | ||
| print("No base classes returned from gh api", file=sys.stderr) | ||
| return 1 | ||
| TARGET.write_text(render(names)) | ||
| print(f"Wrote {len(names)} base classes to {TARGET}") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
Uh oh!
There was an error while loading. Please reload this page.