diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8f60f75e..68a0d008 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,4 +19,3 @@ repos: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - diff --git a/.vscode/settings.json b/.vscode/settings.json index 9b388533..a3a18383 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,4 +4,4 @@ ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true -} \ No newline at end of file +} diff --git a/docs/conf.py b/docs/conf.py index 203bf5e3..3a8d8b81 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,6 +4,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html import os import sys + import versioningit sys.path.insert(0, os.path.abspath("../src")) @@ -59,7 +60,9 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = "alabaster" # "sphinx_rtd_theme", please add corresponding package to environment.yml if you want to use it +html_theme = ( + "alabaster" # "sphinx_rtd_theme", please add corresponding package to environment.yml if you want to use it +) autosummary_generate = True # Napoleon settings diff --git a/docs/ex_h5py_NXtas.py b/docs/ex_h5py_NXtas.py index ba0d469f..a73d1a2e 100644 --- a/docs/ex_h5py_NXtas.py +++ b/docs/ex_h5py_NXtas.py @@ -1,241 +1,242 @@ - -import numpy as np import datetime -import h5py import os - -# Note this example script was generated by nxdl_to_hdf5.py using the current -# installed version of the NEXUS definitions ver[v2020.10] - -root = h5py.File('NXtas.h5', 'w') - -# Create the GROUPS - -root.create_group('entry') -root['/entry'].attrs['NX_class'] = 'NXentry' -root['/entry'].attrs['EX_required'] = 'true' - -root['/entry/'].create_group('instrument') -root['/entry/instrument'].attrs['NX_class'] = 'NXinstrument' -root['/entry/instrument'].attrs['EX_required'] = 'true' - -root['/entry/instrument/'].create_group('source') -root['/entry/instrument/source'].attrs['NX_class'] = 'NXsource' -root['/entry/instrument/source'].attrs['EX_required'] = 'true' - -root['/entry/instrument/'].create_group('monochromator') -root['/entry/instrument/monochromator'].attrs['NX_class'] = 'NXcrystal' -root['/entry/instrument/monochromator'].attrs['EX_required'] = 'true' - -root['/entry/instrument/'].create_group('analyser') -root['/entry/instrument/analyser'].attrs['NX_class'] = 'NXcrystal' -root['/entry/instrument/analyser'].attrs['EX_required'] = 'true' - -root['/entry/instrument/'].create_group('detector') -root['/entry/instrument/detector'].attrs['NX_class'] = 'NXdetector' -root['/entry/instrument/detector'].attrs['EX_required'] = 'true' - -root['/entry/'].create_group('sample') -root['/entry/sample'].attrs['NX_class'] = 'NXsample' -root['/entry/sample'].attrs['EX_required'] = 'true' - -root['/entry/'].create_group('monitor') -root['/entry/monitor'].attrs['NX_class'] = 'NXmonitor' -root['/entry/monitor'].attrs['EX_required'] = 'true' - -root['/entry/'].create_group('data') -root['/entry/data'].attrs['NX_class'] = 'NXdata' -root['/entry/data'].attrs['EX_required'] = 'true' - -# Create the FIELDS - -root['/entry'].create_dataset(name='title', data='SAMPLE-CHAR-DATA', maxshape=None) -root['/entry/title'].attrs['type'] = 'NX_CHAR' -root['/entry/title'].attrs['EX_required'] = 'true' - -root['/entry'].create_dataset(name='start_time', data='2021-03-29T15:51:43.263179', maxshape=None) -root['/entry/start_time'].attrs['type'] = 'NX_DATE_TIME' -root['/entry/start_time'].attrs['EX_required'] = 'true' - -# Valid enumeration values for root['/entry']['definition'] are: -# NXtas - -root['/entry'].create_dataset(name='definition', data='NXtas', maxshape=None) -root['/entry/definition'].attrs['type'] = 'NX_CHAR' -root['/entry/definition'].attrs['EX_required'] = 'true' - -root['/entry/instrument/source'].create_dataset(name='name', data='SAMPLE-CHAR-DATA', maxshape=None) -root['/entry/instrument/source/name'].attrs['type'] = 'NX_CHAR' -root['/entry/instrument/source/name'].attrs['EX_required'] = 'true' - -# Valid enumeration values for root['/entry/instrument/source']['probe'] are: -# neutron -# x-ray - -root['/entry/instrument/source'].create_dataset(name='probe', data='neutron', maxshape=None) -root['/entry/instrument/source/probe'].attrs['type'] = 'NX_CHAR' -root['/entry/instrument/source/probe'].attrs['EX_required'] = 'true' - -root['/entry/instrument/monochromator'].create_dataset(name='ei', data=1.0, maxshape=None) -root['/entry/instrument/monochromator/ei'].attrs['type'] = 'NX_FLOAT' -root['/entry/instrument/monochromator/ei'].attrs['EX_required'] = 'true' -root['/entry/instrument/monochromator/ei'].attrs['axis'] = '1' -root['/entry/instrument/monochromator/ei'].attrs['units'] = 'NX_ENERGY' - -root['/entry/instrument/monochromator'].create_dataset(name='rotation_angle', data=1.0, maxshape=None) -root['/entry/instrument/monochromator/rotation_angle'].attrs['type'] = 'NX_FLOAT' -root['/entry/instrument/monochromator/rotation_angle'].attrs['EX_required'] = 'true' -root['/entry/instrument/monochromator/rotation_angle'].attrs['units'] = 'NX_ANGLE' - -root['/entry/instrument/analyser'].create_dataset(name='ef', data=1.0, maxshape=None) -root['/entry/instrument/analyser/ef'].attrs['type'] = 'NX_FLOAT' -root['/entry/instrument/analyser/ef'].attrs['EX_required'] = 'true' -root['/entry/instrument/analyser/ef'].attrs['axis'] = '1' -root['/entry/instrument/analyser/ef'].attrs['units'] = 'NX_ENERGY' - -root['/entry/instrument/analyser'].create_dataset(name='rotation_angle', data=1.0, maxshape=None) -root['/entry/instrument/analyser/rotation_angle'].attrs['type'] = 'NX_FLOAT' -root['/entry/instrument/analyser/rotation_angle'].attrs['EX_required'] = 'true' -root['/entry/instrument/analyser/rotation_angle'].attrs['units'] = 'NX_ANGLE' - -root['/entry/instrument/analyser'].create_dataset(name='polar_angle', data=1.0, maxshape=None) -root['/entry/instrument/analyser/polar_angle'].attrs['type'] = 'NX_FLOAT' -root['/entry/instrument/analyser/polar_angle'].attrs['EX_required'] = 'true' -root['/entry/instrument/analyser/polar_angle'].attrs['units'] = 'NX_ANGLE' - -root['/entry/instrument/detector'].create_dataset(name='data', data=1, maxshape=None) -root['/entry/instrument/detector/data'].attrs['type'] = 'NX_INT' -root['/entry/instrument/detector/data'].attrs['EX_required'] = 'true' -root['/entry/instrument/detector/data'].attrs['signal'] = '1' - -root['/entry/instrument/detector'].create_dataset(name='polar_angle', data=1.0, maxshape=None) -root['/entry/instrument/detector/polar_angle'].attrs['type'] = 'NX_FLOAT' -root['/entry/instrument/detector/polar_angle'].attrs['EX_required'] = 'true' -root['/entry/instrument/detector/polar_angle'].attrs['units'] = 'NX_ANGLE' - -root['/entry/sample'].create_dataset(name='name', data='SAMPLE-CHAR-DATA', maxshape=None) -root['/entry/sample/name'].attrs['type'] = 'NX_CHAR' -root['/entry/sample/name'].attrs['EX_required'] = 'true' - -root['/entry/sample'].create_dataset(name='qh', data=1.0, maxshape=None) -root['/entry/sample/qh'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/qh'].attrs['EX_required'] = 'true' -root['/entry/sample/qh'].attrs['axis'] = '1' -root['/entry/sample/qh'].attrs['units'] = 'NX_DIMENSIONLESS' - -root['/entry/sample'].create_dataset(name='qk', data=1.0, maxshape=None) -root['/entry/sample/qk'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/qk'].attrs['EX_required'] = 'true' -root['/entry/sample/qk'].attrs['axis'] = '1' -root['/entry/sample/qk'].attrs['units'] = 'NX_DIMENSIONLESS' - -root['/entry/sample'].create_dataset(name='ql', data=1.0, maxshape=None) -root['/entry/sample/ql'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/ql'].attrs['EX_required'] = 'true' -root['/entry/sample/ql'].attrs['axis'] = '1' -root['/entry/sample/ql'].attrs['units'] = 'NX_DIMENSIONLESS' - -root['/entry/sample'].create_dataset(name='en', data=1.0, maxshape=None) -root['/entry/sample/en'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/en'].attrs['EX_required'] = 'true' -root['/entry/sample/en'].attrs['axis'] = '1' -root['/entry/sample/en'].attrs['units'] = 'NX_ENERGY' - -root['/entry/sample'].create_dataset(name='rotation_angle', data=1.0, maxshape=None) -root['/entry/sample/rotation_angle'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/rotation_angle'].attrs['EX_required'] = 'true' -root['/entry/sample/rotation_angle'].attrs['units'] = 'NX_ANGLE' - -root['/entry/sample'].create_dataset(name='polar_angle', data=1.0, maxshape=None) -root['/entry/sample/polar_angle'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/polar_angle'].attrs['EX_required'] = 'true' -root['/entry/sample/polar_angle'].attrs['units'] = 'NX_ANGLE' - -root['/entry/sample'].create_dataset(name='sgu', data=1.0, maxshape=None) -root['/entry/sample/sgu'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/sgu'].attrs['EX_required'] = 'true' -root['/entry/sample/sgu'].attrs['units'] = 'NX_ANGLE' - -root['/entry/sample'].create_dataset(name='sgl', data=1.0, maxshape=None) -root['/entry/sample/sgl'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/sgl'].attrs['EX_required'] = 'true' -root['/entry/sample/sgl'].attrs['units'] = 'NX_ANGLE' - -root['/entry/sample'].create_dataset(name='unit_cell', data=1.0, maxshape=None) -root['/entry/sample/unit_cell'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/unit_cell'].attrs['EX_required'] = 'true' -root['/entry/sample/unit_cell'].attrs['units'] = 'NX_LENGTH' - -root['/entry/sample'].create_dataset(name='orientation_matrix', data=1.0, maxshape=None) -root['/entry/sample/orientation_matrix'].attrs['type'] = 'NX_FLOAT' -root['/entry/sample/orientation_matrix'].attrs['EX_required'] = 'true' -root['/entry/sample/orientation_matrix'].attrs['units'] = 'NX_DIMENSIONLESS' - -# Valid enumeration values for root['/entry/monitor']['mode'] are: -# monitor -# timer - -root['/entry/monitor'].create_dataset(name='mode', data='monitor', maxshape=None) -root['/entry/monitor/mode'].attrs['type'] = 'NX_CHAR' -root['/entry/monitor/mode'].attrs['EX_required'] = 'true' - -root['/entry/monitor'].create_dataset(name='preset', data=1.0, maxshape=None) -root['/entry/monitor/preset'].attrs['type'] = 'NX_FLOAT' -root['/entry/monitor/preset'].attrs['EX_required'] = 'true' - -root['/entry/monitor'].create_dataset(name='data', data=1.0, maxshape=None) -root['/entry/monitor/data'].attrs['type'] = 'NX_FLOAT' -root['/entry/monitor/data'].attrs['EX_required'] = 'true' -root['/entry/monitor/data'].attrs['units'] = 'NX_ANY' - -# Create the LINKS -root['/entry/data/ei'] = h5py.SoftLink('/entry/instrument/monochromator/ei') -root['/entry/data/ei/'].attrs['target'] = '/entry/instrument/monochromator/ei' - -# Create the LINKS -root['/entry/data/ef'] = h5py.SoftLink('/entry/title') -root['/entry/data/ef/'].attrs['target'] = '/entry/instrument/analyzer/ef' - -# Create the LINKS -root['/entry/data/en'] = h5py.SoftLink('/entry/sample/en') -root['/entry/data/en/'].attrs['target'] = '/entry/sample/en' - -# Create the LINKS -root['/entry/data/qh'] = h5py.SoftLink('/entry/sample/qh') -root['/entry/data/qh/'].attrs['target'] = '/entry/sample/qh' - -# Create the LINKS -root['/entry/data/qk'] = h5py.SoftLink('/entry/sample/qk') -root['/entry/data/qk/'].attrs['target'] = '/entry/sample/qk' - -# Create the LINKS -root['/entry/data/ql'] = h5py.SoftLink('/entry/sample/ql') -root['/entry/data/ql/'].attrs['target'] = '/entry/sample/ql' - -# Create the LINKS -root['/entry/data/data'] = h5py.SoftLink('/entry/instrument/detector/data') -root['/entry/data/data/'].attrs['target'] = '/entry/instrument/detector/data' - -# Create the DOC strings -root['/entry/definition'].attrs['EX_doc'] = 'Official NeXus NXDL schema to which this file conforms ' -root['/entry/sample/name'].attrs['EX_doc'] = 'Descriptive name of sample ' -root['/entry/monitor/mode'].attrs['EX_doc'] = 'Count to a preset value based on either clock time (timer) or received monitor counts (monitor). ' -root['/entry/monitor/preset'].attrs['EX_doc'] = 'preset value for time or monitor ' -root['/entry/monitor/data'].attrs['EX_doc'] = 'Total integral monitor counts ' -root['/entry/data'].attrs['EX_doc'] = 'One of the ei,ef,qh,qk,ql,en should get a primary=1 attribute to denote the main scan axis ' - - -# Create the ATTRIBUTES -root['/'].attrs['default'] = 'entry' -root['/entry'].attrs['default'] = 'data' -root['/entry/data'].attrs['signal'] = 'data' -root['/entry/data/data'].attrs['signal'] = '1' -root.attrs['file_name'] = os.path.abspath('NXtas') -root.attrs['file_time'] = datetime.datetime.now().isoformat() -root.attrs['h5py_version'] = h5py.version.version -root.attrs['HDF5_Version'] = h5py.version.hdf5_version -# Close the file -root.close() +import h5py + +# Note this example script was generated by nxdl_to_hdf5.py using the current +# installed version of the NEXUS definitions ver[v2020.10] + +root = h5py.File("NXtas.h5", "w") + +# Create the GROUPS + +root.create_group("entry") +root["/entry"].attrs["NX_class"] = "NXentry" +root["/entry"].attrs["EX_required"] = "true" + +root["/entry/"].create_group("instrument") +root["/entry/instrument"].attrs["NX_class"] = "NXinstrument" +root["/entry/instrument"].attrs["EX_required"] = "true" + +root["/entry/instrument/"].create_group("source") +root["/entry/instrument/source"].attrs["NX_class"] = "NXsource" +root["/entry/instrument/source"].attrs["EX_required"] = "true" + +root["/entry/instrument/"].create_group("monochromator") +root["/entry/instrument/monochromator"].attrs["NX_class"] = "NXcrystal" +root["/entry/instrument/monochromator"].attrs["EX_required"] = "true" + +root["/entry/instrument/"].create_group("analyser") +root["/entry/instrument/analyser"].attrs["NX_class"] = "NXcrystal" +root["/entry/instrument/analyser"].attrs["EX_required"] = "true" + +root["/entry/instrument/"].create_group("detector") +root["/entry/instrument/detector"].attrs["NX_class"] = "NXdetector" +root["/entry/instrument/detector"].attrs["EX_required"] = "true" + +root["/entry/"].create_group("sample") +root["/entry/sample"].attrs["NX_class"] = "NXsample" +root["/entry/sample"].attrs["EX_required"] = "true" + +root["/entry/"].create_group("monitor") +root["/entry/monitor"].attrs["NX_class"] = "NXmonitor" +root["/entry/monitor"].attrs["EX_required"] = "true" + +root["/entry/"].create_group("data") +root["/entry/data"].attrs["NX_class"] = "NXdata" +root["/entry/data"].attrs["EX_required"] = "true" + +# Create the FIELDS + +root["/entry"].create_dataset(name="title", data="SAMPLE-CHAR-DATA", maxshape=None) +root["/entry/title"].attrs["type"] = "NX_CHAR" +root["/entry/title"].attrs["EX_required"] = "true" + +root["/entry"].create_dataset(name="start_time", data="2021-03-29T15:51:43.263179", maxshape=None) +root["/entry/start_time"].attrs["type"] = "NX_DATE_TIME" +root["/entry/start_time"].attrs["EX_required"] = "true" + +# Valid enumeration values for root['/entry']['definition'] are: +# NXtas + +root["/entry"].create_dataset(name="definition", data="NXtas", maxshape=None) +root["/entry/definition"].attrs["type"] = "NX_CHAR" +root["/entry/definition"].attrs["EX_required"] = "true" + +root["/entry/instrument/source"].create_dataset(name="name", data="SAMPLE-CHAR-DATA", maxshape=None) +root["/entry/instrument/source/name"].attrs["type"] = "NX_CHAR" +root["/entry/instrument/source/name"].attrs["EX_required"] = "true" + +# Valid enumeration values for root['/entry/instrument/source']['probe'] are: +# neutron +# x-ray + +root["/entry/instrument/source"].create_dataset(name="probe", data="neutron", maxshape=None) +root["/entry/instrument/source/probe"].attrs["type"] = "NX_CHAR" +root["/entry/instrument/source/probe"].attrs["EX_required"] = "true" + +root["/entry/instrument/monochromator"].create_dataset(name="ei", data=1.0, maxshape=None) +root["/entry/instrument/monochromator/ei"].attrs["type"] = "NX_FLOAT" +root["/entry/instrument/monochromator/ei"].attrs["EX_required"] = "true" +root["/entry/instrument/monochromator/ei"].attrs["axis"] = "1" +root["/entry/instrument/monochromator/ei"].attrs["units"] = "NX_ENERGY" + +root["/entry/instrument/monochromator"].create_dataset(name="rotation_angle", data=1.0, maxshape=None) +root["/entry/instrument/monochromator/rotation_angle"].attrs["type"] = "NX_FLOAT" +root["/entry/instrument/monochromator/rotation_angle"].attrs["EX_required"] = "true" +root["/entry/instrument/monochromator/rotation_angle"].attrs["units"] = "NX_ANGLE" + +root["/entry/instrument/analyser"].create_dataset(name="ef", data=1.0, maxshape=None) +root["/entry/instrument/analyser/ef"].attrs["type"] = "NX_FLOAT" +root["/entry/instrument/analyser/ef"].attrs["EX_required"] = "true" +root["/entry/instrument/analyser/ef"].attrs["axis"] = "1" +root["/entry/instrument/analyser/ef"].attrs["units"] = "NX_ENERGY" + +root["/entry/instrument/analyser"].create_dataset(name="rotation_angle", data=1.0, maxshape=None) +root["/entry/instrument/analyser/rotation_angle"].attrs["type"] = "NX_FLOAT" +root["/entry/instrument/analyser/rotation_angle"].attrs["EX_required"] = "true" +root["/entry/instrument/analyser/rotation_angle"].attrs["units"] = "NX_ANGLE" + +root["/entry/instrument/analyser"].create_dataset(name="polar_angle", data=1.0, maxshape=None) +root["/entry/instrument/analyser/polar_angle"].attrs["type"] = "NX_FLOAT" +root["/entry/instrument/analyser/polar_angle"].attrs["EX_required"] = "true" +root["/entry/instrument/analyser/polar_angle"].attrs["units"] = "NX_ANGLE" +root["/entry/instrument/detector"].create_dataset(name="data", data=1, maxshape=None) +root["/entry/instrument/detector/data"].attrs["type"] = "NX_INT" +root["/entry/instrument/detector/data"].attrs["EX_required"] = "true" +root["/entry/instrument/detector/data"].attrs["signal"] = "1" +root["/entry/instrument/detector"].create_dataset(name="polar_angle", data=1.0, maxshape=None) +root["/entry/instrument/detector/polar_angle"].attrs["type"] = "NX_FLOAT" +root["/entry/instrument/detector/polar_angle"].attrs["EX_required"] = "true" +root["/entry/instrument/detector/polar_angle"].attrs["units"] = "NX_ANGLE" + +root["/entry/sample"].create_dataset(name="name", data="SAMPLE-CHAR-DATA", maxshape=None) +root["/entry/sample/name"].attrs["type"] = "NX_CHAR" +root["/entry/sample/name"].attrs["EX_required"] = "true" + +root["/entry/sample"].create_dataset(name="qh", data=1.0, maxshape=None) +root["/entry/sample/qh"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/qh"].attrs["EX_required"] = "true" +root["/entry/sample/qh"].attrs["axis"] = "1" +root["/entry/sample/qh"].attrs["units"] = "NX_DIMENSIONLESS" + +root["/entry/sample"].create_dataset(name="qk", data=1.0, maxshape=None) +root["/entry/sample/qk"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/qk"].attrs["EX_required"] = "true" +root["/entry/sample/qk"].attrs["axis"] = "1" +root["/entry/sample/qk"].attrs["units"] = "NX_DIMENSIONLESS" + +root["/entry/sample"].create_dataset(name="ql", data=1.0, maxshape=None) +root["/entry/sample/ql"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/ql"].attrs["EX_required"] = "true" +root["/entry/sample/ql"].attrs["axis"] = "1" +root["/entry/sample/ql"].attrs["units"] = "NX_DIMENSIONLESS" + +root["/entry/sample"].create_dataset(name="en", data=1.0, maxshape=None) +root["/entry/sample/en"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/en"].attrs["EX_required"] = "true" +root["/entry/sample/en"].attrs["axis"] = "1" +root["/entry/sample/en"].attrs["units"] = "NX_ENERGY" + +root["/entry/sample"].create_dataset(name="rotation_angle", data=1.0, maxshape=None) +root["/entry/sample/rotation_angle"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/rotation_angle"].attrs["EX_required"] = "true" +root["/entry/sample/rotation_angle"].attrs["units"] = "NX_ANGLE" + +root["/entry/sample"].create_dataset(name="polar_angle", data=1.0, maxshape=None) +root["/entry/sample/polar_angle"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/polar_angle"].attrs["EX_required"] = "true" +root["/entry/sample/polar_angle"].attrs["units"] = "NX_ANGLE" + +root["/entry/sample"].create_dataset(name="sgu", data=1.0, maxshape=None) +root["/entry/sample/sgu"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/sgu"].attrs["EX_required"] = "true" +root["/entry/sample/sgu"].attrs["units"] = "NX_ANGLE" + +root["/entry/sample"].create_dataset(name="sgl", data=1.0, maxshape=None) +root["/entry/sample/sgl"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/sgl"].attrs["EX_required"] = "true" +root["/entry/sample/sgl"].attrs["units"] = "NX_ANGLE" + +root["/entry/sample"].create_dataset(name="unit_cell", data=1.0, maxshape=None) +root["/entry/sample/unit_cell"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/unit_cell"].attrs["EX_required"] = "true" +root["/entry/sample/unit_cell"].attrs["units"] = "NX_LENGTH" + +root["/entry/sample"].create_dataset(name="orientation_matrix", data=1.0, maxshape=None) +root["/entry/sample/orientation_matrix"].attrs["type"] = "NX_FLOAT" +root["/entry/sample/orientation_matrix"].attrs["EX_required"] = "true" +root["/entry/sample/orientation_matrix"].attrs["units"] = "NX_DIMENSIONLESS" + +# Valid enumeration values for root['/entry/monitor']['mode'] are: +# monitor +# timer + +root["/entry/monitor"].create_dataset(name="mode", data="monitor", maxshape=None) +root["/entry/monitor/mode"].attrs["type"] = "NX_CHAR" +root["/entry/monitor/mode"].attrs["EX_required"] = "true" + +root["/entry/monitor"].create_dataset(name="preset", data=1.0, maxshape=None) +root["/entry/monitor/preset"].attrs["type"] = "NX_FLOAT" +root["/entry/monitor/preset"].attrs["EX_required"] = "true" + +root["/entry/monitor"].create_dataset(name="data", data=1.0, maxshape=None) +root["/entry/monitor/data"].attrs["type"] = "NX_FLOAT" +root["/entry/monitor/data"].attrs["EX_required"] = "true" +root["/entry/monitor/data"].attrs["units"] = "NX_ANY" + +# Create the LINKS +root["/entry/data/ei"] = h5py.SoftLink("/entry/instrument/monochromator/ei") +root["/entry/data/ei/"].attrs["target"] = "/entry/instrument/monochromator/ei" + +# Create the LINKS +root["/entry/data/ef"] = h5py.SoftLink("/entry/title") +root["/entry/data/ef/"].attrs["target"] = "/entry/instrument/analyzer/ef" + +# Create the LINKS +root["/entry/data/en"] = h5py.SoftLink("/entry/sample/en") +root["/entry/data/en/"].attrs["target"] = "/entry/sample/en" + +# Create the LINKS +root["/entry/data/qh"] = h5py.SoftLink("/entry/sample/qh") +root["/entry/data/qh/"].attrs["target"] = "/entry/sample/qh" + +# Create the LINKS +root["/entry/data/qk"] = h5py.SoftLink("/entry/sample/qk") +root["/entry/data/qk/"].attrs["target"] = "/entry/sample/qk" + +# Create the LINKS +root["/entry/data/ql"] = h5py.SoftLink("/entry/sample/ql") +root["/entry/data/ql/"].attrs["target"] = "/entry/sample/ql" + +# Create the LINKS +root["/entry/data/data"] = h5py.SoftLink("/entry/instrument/detector/data") +root["/entry/data/data/"].attrs["target"] = "/entry/instrument/detector/data" + +# Create the DOC strings +root["/entry/definition"].attrs["EX_doc"] = "Official NeXus NXDL schema to which this file conforms " +root["/entry/sample/name"].attrs["EX_doc"] = "Descriptive name of sample " +root["/entry/monitor/mode"].attrs["EX_doc"] = ( + "Count to a preset value based on either clock time (timer) or received monitor counts (monitor). " +) +root["/entry/monitor/preset"].attrs["EX_doc"] = "preset value for time or monitor " +root["/entry/monitor/data"].attrs["EX_doc"] = "Total integral monitor counts " +root["/entry/data"].attrs["EX_doc"] = ( + "One of the ei,ef,qh,qk,ql,en should get a primary=1 attribute to denote the main scan axis " +) + + +# Create the ATTRIBUTES +root["/"].attrs["default"] = "entry" +root["/entry"].attrs["default"] = "data" +root["/entry/data"].attrs["signal"] = "data" +root["/entry/data/data"].attrs["signal"] = "1" +root.attrs["file_name"] = os.path.abspath("NXtas") +root.attrs["file_time"] = datetime.datetime.now().isoformat() +root.attrs["h5py_version"] = h5py.version.version +root.attrs["HDF5_Version"] = h5py.version.hdf5_version + +# Close the file +root.close() diff --git a/scripts/test_plotter.py b/scripts/test_plotter.py index 0a1cab55..280013a9 100644 --- a/scripts/test_plotter.py +++ b/scripts/test_plotter.py @@ -1,5 +1,4 @@ import matplotlib.pylab as plt - from tavi.data.tavi import TAVI from tavi.instrument.resolution.cooper_nathans import CN from tavi.plotter import Plot1DManager, Plot2DManager diff --git a/scripts/test_rez.py b/scripts/test_rez.py index 09e096d2..2cb5ca9f 100644 --- a/scripts/test_rez.py +++ b/scripts/test_rez.py @@ -1,7 +1,6 @@ # from tavi.instrument.instrument_params.python_dicts.takin_test import instrument_params # from tests.test_data_folder.test_samples.python_samples.sample_test import test_xtal import matplotlib.pylab as plt - from tavi.instrument.resolution.cooper_nathans import CN from tavi.plotter import Plot1DManager, Plot2DManager diff --git a/scripts/test_scan.py b/scripts/test_scan.py index 08133c5c..97a98f4c 100644 --- a/scripts/test_scan.py +++ b/scripts/test_scan.py @@ -1,5 +1,4 @@ import matplotlib.pyplot as plt - from tavi.data.tavi import TAVI diff --git a/src/tavi/configuration.py b/src/tavi/configuration.py index 828cb5bb..e0de8627 100644 --- a/src/tavi/configuration.py +++ b/src/tavi/configuration.py @@ -4,9 +4,9 @@ import os import shutil - from configparser import ConfigParser from pathlib import Path + from mantid.kernel import Logger logger = Logger("PACKAGENAME") diff --git a/src/tavi/data/scan_group.py b/src/tavi/data/scan_group.py index 1e109875..50ef2efd 100644 --- a/src/tavi/data/scan_group.py +++ b/src/tavi/data/scan_group.py @@ -31,7 +31,6 @@ def __init__( signal_axes=(None, None, None), background_axes=(None, None, None), ): - self.signals = signals self.backgrounds = backgrounds self.signal_axes = list(signal_axes) @@ -165,7 +164,6 @@ def plot_waterfall(self, contour_plot, shifts=None, ylim=None, xlim=None, fmt="o fig, ax = plt.subplots() shift = 0 for i in range(num): - if np.isnan(z[:, i]).all(): # all nan continue else: diff --git a/src/tavi/data/spice_to_nexus.py b/src/tavi/data/spice_to_nexus.py index 3d0fcd41..7ca3d385 100644 --- a/src/tavi/data/spice_to_nexus.py +++ b/src/tavi/data/spice_to_nexus.py @@ -1,8 +1,9 @@ -import numpy as np -import h5py import os -from pathlib import Path from datetime import datetime +from pathlib import Path + +import h5py +import numpy as np # from tavi.instrument.instrument_params.takin_test import instrument_params @@ -421,7 +422,6 @@ def spicelogs_to_nexus(nxentry): # mcu if spice_logs.attrs["preset_type"] == "normal": - preset_channel = spice_logs.attrs["preset_channel"] nxentry["monitor"].create_dataset(name="mode", data=preset_channel, maxshape=None) @@ -458,7 +458,6 @@ def spicelogs_to_nexus(nxentry): # --------------------------- data links --------------------------- def find_val(val, grp, prefix=""): - for obj_name, obj in grp.items(): if obj_name in ("SPICElogs", "data"): continue @@ -749,7 +748,6 @@ def convert_spice_to_nexus(path_to_spice_folder, path_to_hdf5): p = Path(path_to_spice_folder) with h5py.File(path_to_hdf5, "w") as root: - # ----------------------------- ub info ------------------------------------ ub_files = sorted((p / "UBConf").glob("*.ini")) tmp_ub_files = sorted((p / "UBConf/tmp").glob("*.ini")) @@ -797,7 +795,6 @@ def convert_spice_to_nexus(path_to_spice_folder, path_to_hdf5): # metadata to attibutes exp_str = ["scan_title", "users", "local_contact", "experiment"] for k, v in headers.items(): - if "," in v and k not in exp_str: # vectors spice_logs.attrs[k] = np.array([float(v0) for v0 in v.split(",")]) elif v.replace(".", "").isnumeric(): # numebrs only diff --git a/src/tavi/instrument/instrument_params/cg4c.json b/src/tavi/instrument/instrument_params/cg4c.json index 0252decc..46fcaaaa 100644 --- a/src/tavi/instrument/instrument_params/cg4c.json +++ b/src/tavi/instrument/instrument_params/cg4c.json @@ -70,4 +70,4 @@ "v_post_sample": 600, "v_post_ana": 600 } -} \ No newline at end of file +} diff --git a/src/tavi/instrument/instrument_params/hb3.json b/src/tavi/instrument/instrument_params/hb3.json index 1f9a1f00..24d6213d 100644 --- a/src/tavi/instrument/instrument_params/hb3.json +++ b/src/tavi/instrument/instrument_params/hb3.json @@ -73,4 +73,4 @@ "v_post_sample": 300, "v_post_ana": 600 } -} \ No newline at end of file +} diff --git a/src/tavi/instrument/instrument_params/python_dicts/hb3.py b/src/tavi/instrument/instrument_params/python_dicts/hb3.py index 093ca322..05307e1d 100644 --- a/src/tavi/instrument/instrument_params/python_dicts/hb3.py +++ b/src/tavi/instrument/instrument_params/python_dicts/hb3.py @@ -1,5 +1,4 @@ import numpy as np - from tavi.utilities import * source = { diff --git a/src/tavi/instrument/instrument_params/takin_test.json b/src/tavi/instrument/instrument_params/takin_test.json index 95638b4f..c289dc7c 100644 --- a/src/tavi/instrument/instrument_params/takin_test.json +++ b/src/tavi/instrument/instrument_params/takin_test.json @@ -72,4 +72,4 @@ "v_post_sample": 30, "v_post_ana": 30 } -} \ No newline at end of file +} diff --git a/src/tavi/instrument/resolution/backups/cooper_nathans_bak.py b/src/tavi/instrument/resolution/backups/cooper_nathans_bak.py index 53b4c756..1e6bbc2c 100755 --- a/src/tavi/instrument/resolution/backups/cooper_nathans_bak.py +++ b/src/tavi/instrument/resolution/backups/cooper_nathans_bak.py @@ -1,8 +1,8 @@ import numpy as np import numpy.linalg as la -from tavi.utilities import * -from tavi.instrument.tas import TAS from tavi.instrument.resolution.reso_ellipses import ResoEllipsoid +from tavi.instrument.tas import TAS +from tavi.utilities import * class CN(TAS): diff --git a/src/tavi/instrument/resolution/backups/reso_ellipses_bak.py b/src/tavi/instrument/resolution/backups/reso_ellipses_bak.py index 5a4423f8..7db7bb09 100755 --- a/src/tavi/instrument/resolution/backups/reso_ellipses_bak.py +++ b/src/tavi/instrument/resolution/backups/reso_ellipses_bak.py @@ -1,11 +1,9 @@ -import numpy as np -import numpy.linalg as la -import mpl_toolkits.mplot3d as mplot3d import matplotlib import matplotlib.pyplot as plt +import numpy as np +import numpy.linalg as la from tavi.utilities import * - np.set_printoptions(floatmode="fixed", precision=4) @@ -25,7 +23,6 @@ class ResoEllipsoid(object): g_eps = 1e-8 def __init__(self): - self.q = None self.en = None self.frame = None @@ -279,9 +276,9 @@ def ellfkt(rad, vecs, phi): labelQup = "Qup (1/A)" if use_tex: - labelQpara = "$Q_{\parallel}$ (\AA$^{-1}$)" - labelQperp = "$Q_{\perp}$ (\AA$^{-1}$)" - labelQup = "$Q_{up}$ (\AA$^{-1}$)" + labelQpara = r"$Q_{\parallel}$ (\AA$^{-1}$)" + labelQperp = r"$Q_{\perp}$ (\AA$^{-1}$)" + labelQup = r"$Q_{up}$ (\AA$^{-1}$)" # Qpara, E axis diff --git a/src/tavi/instrument/resolution/cooper_nathans.py b/src/tavi/instrument/resolution/cooper_nathans.py index f08a19cd..351d2a0e 100755 --- a/src/tavi/instrument/resolution/cooper_nathans.py +++ b/src/tavi/instrument/resolution/cooper_nathans.py @@ -1,6 +1,5 @@ import numpy as np import numpy.linalg as la - from tavi.instrument.resolution.reso_ellipses import ResoEllipsoid from tavi.instrument.tas import TAS from tavi.utilities import * diff --git a/src/tavi/instrument/resolution/reso_ellipses.py b/src/tavi/instrument/resolution/reso_ellipses.py index 60a856b7..875ba59b 100755 --- a/src/tavi/instrument/resolution/reso_ellipses.py +++ b/src/tavi/instrument/resolution/reso_ellipses.py @@ -1,7 +1,7 @@ +import matplotlib.pyplot as plt import numpy as np import numpy.linalg as la -import matplotlib.pyplot as plt -from mpl_toolkits.axisartist import Subplot, Axes +from mpl_toolkits.axisartist import Axes, Subplot from mpl_toolkits.axisartist.grid_finder import MaxNLocator from mpl_toolkits.axisartist.grid_helper_curvelinear import GridHelperCurveLinear from tavi.utilities import * @@ -141,7 +141,6 @@ def generate_plot(self, ax, c="black", linestyle="solid"): pts = self.generate_ellipse() if self.grid_helper is None: - s = ax.plot( pts[0], pts[1], @@ -196,7 +195,6 @@ class ResoEllipsoid(object): g_eps = 1e-8 def __init__(self): - self.STATUS = None self.q = None self.hkl = None diff --git a/src/tavi/instrument/tas_cmponents.py b/src/tavi/instrument/tas_cmponents.py index 8f954092..876f2157 100644 --- a/src/tavi/instrument/tas_cmponents.py +++ b/src/tavi/instrument/tas_cmponents.py @@ -1,5 +1,4 @@ import numpy as np - from tavi.utilities import * diff --git a/src/tavi/plotter.py b/src/tavi/plotter.py index 0c957562..7ab025ed 100644 --- a/src/tavi/plotter.py +++ b/src/tavi/plotter.py @@ -1,13 +1,12 @@ import matplotlib.pylab as plt -from mpl_toolkits.axisartist import Axes import numpy as np +from mpl_toolkits.axisartist import Axes class Plot1DManager(object): """Manage a plot""" def __init__(self) -> None: - _, self.ax = plt.subplots() self.title = None self.xlim = None @@ -16,7 +15,6 @@ def __init__(self) -> None: self.ylabel = None def set_labels(self): - if self.xlim is not None: self.ax.set_xlim(left=self.xlim[0], right=self.xlim[1]) if self.ylim is not None: @@ -29,7 +27,6 @@ def set_labels(self): self.ax.legend() def rez_plot_1D(self, tas, projection, hkl, en, ef, R0, axis): - rez = tas.cooper_nathans( ei=ef + en, ef=ef, @@ -61,7 +58,6 @@ class Plot2DManager(object): """Manage a plot""" def __init__(self, grid_helper=None) -> None: - self.fig = plt.figure(figsize=(10, 6)) self.ax = self.fig.add_subplot(111, axes_class=Axes, grid_helper=grid_helper) @@ -76,7 +72,6 @@ def __init__(self, grid_helper=None) -> None: self.cmap = "turbo" def set_labels(self): - if self.xlim is not None: self.ax.set_xlim(left=self.xlim[0], right=self.xlim[1]) if self.ylim is not None: @@ -122,7 +117,6 @@ def plot_contour( self.set_labels() def rez_plot(self, tas, projection, q1, q2, q3, en, ef, R0): - qe_list = np.empty((4,), dtype=object) plot_axes = [] perp_axes = [] @@ -142,7 +136,6 @@ def rez_plot(self, tas, projection, q1, q2, q3, en, ef, R0): for q2 in qe_list[1]: for q3 in qe_list[2]: for ei0 in qe_list[3]: - h, k, l = tuple(np.array(p1) * q1 + np.array(p2) * q2 + np.array(p3) * q3) rez = tas.cooper_nathans( diff --git a/src/tavi/sample/sample.py b/src/tavi/sample/sample.py index c3814515..c702b080 100755 --- a/src/tavi/sample/sample.py +++ b/src/tavi/sample/sample.py @@ -1,5 +1,4 @@ import numpy as np - from tavi.utilities import * np.set_printoptions(floatmode="fixed", precision=4) diff --git a/src/tavi/sample/xtal.py b/src/tavi/sample/xtal.py index 100bec1a..e3d565a7 100755 --- a/src/tavi/sample/xtal.py +++ b/src/tavi/sample/xtal.py @@ -1,5 +1,4 @@ import numpy as np - from tavi.sample.sample import Sample from tavi.utilities import * diff --git a/tests/test_sample.py b/tests/test_sample.py index 9ff94f1e..cb683c82 100644 --- a/tests/test_sample.py +++ b/tests/test_sample.py @@ -1,6 +1,5 @@ import numpy as np import pytest - from tavi.sample.xtal import Xtal