diff --git a/.gitignore b/.gitignore index b94c060a..bd3214c1 100644 --- a/.gitignore +++ b/.gitignore @@ -161,4 +161,4 @@ cython_debug/ # MacOS -.DS_Store \ No newline at end of file +.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ec5d3dfb..6f6252e4 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 d7338ad7..6fbbf1ba 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/notebooks/La2Ni7_HB1A_resolution.ipynb b/notebooks/La2Ni7_HB1A_resolution.ipynb index 2bd6eecd..6af95676 100644 --- a/notebooks/La2Ni7_HB1A_resolution.ipynb +++ b/notebooks/La2Ni7_HB1A_resolution.ipynb @@ -27,7 +27,7 @@ "# load data\n", "tavi = TAVI()\n", "path_to_spice_folder = \"../test_data/IPTS9879_HB1A_exp978/exp978/\"\n", - "tavi.load_spice_data_from_disk(path_to_spice_folder)\n" + "tavi.load_spice_data_from_disk(path_to_spice_folder)" ] }, { @@ -82,7 +82,7 @@ } ], "source": [ - "# generate a contour of all scans \n", + "# generate a contour of all scans\n", "scans = list(range(132, 198 + 1))\n", "\n", "scan_group = tavi.combine_scans(scans, name=\"La2Ni7_40-40-40-80\")\n", @@ -114,7 +114,7 @@ "\n", "sample_json_path = \"../test_data/IPTS9879_HB1A_exp978/La2Ni7.json\"\n", "sample = Xtal.from_json(sample_json_path)\n", - "ub_json=sample.ub_mat\n", + "ub_json = sample.ub_mat\n", "tas.mount_sample(sample)\n", "\n", "# check UB calculation\n", @@ -128,7 +128,7 @@ "peak2 = Peak(hkl=(1, 1, 0), angles=angles2, ei=ei, ef=ef)\n", "\n", "tas.calculate_ub_matrix(peaks=(peak1, peak2))\n", - "assert np.allclose(tas.sample.ub_mat,ub_json,atol=1e-4)" + "assert np.allclose(tas.sample.ub_mat, ub_json, atol=1e-4)" ] }, { @@ -173,8 +173,7 @@ } ], "source": [ - "\n", - "projection=((1, 1, 0), (-2, 1, 0),(0, 0, 1))\n", + "projection = ((1, 1, 0), (-2, 1, 0), (0, 0, 1))\n", "\n", "# overplot with resoluytion ellipses\n", "\n", @@ -182,12 +181,12 @@ "hkl_list.pop(0)\n", "\n", "rez_list = tas.cooper_nathans(\n", - " hkl_list=hkl_list,\n", - " ei=ei,\n", - " ef=ef,\n", - " projection=projection,\n", - " R0=False,\n", - " )\n", + " hkl_list=hkl_list,\n", + " ei=ei,\n", + " ef=ef,\n", + " projection=projection,\n", + " R0=False,\n", + ")\n", "\n", "contour = Plot2D()\n", "contour.add_contour(scan_group_data, cmap=\"turbo\", vmin=0, vmax=5e3)\n", @@ -199,7 +198,6 @@ " contour.add_reso(e_inco, c=\"k\", linestyle=\"dashed\")\n", "\n", "\n", - "\n", "fig, ax = plt.subplots()\n", "im1 = contour.plot(ax)\n", "fig.colorbar(im1)" @@ -217,20 +215,20 @@ "\n", "\n", "def analyze_in_q(hkl, scans, fit_ranges):\n", - " scan1, scan2=scans\n", - " fit_range1,fit_range2=fit_ranges\n", - " \n", + " scan1, scan2 = scans\n", + " fit_range1, fit_range2 = fit_ranges\n", + "\n", " # ------------------------- th2th -------------------------\n", "\n", " th2th = Scan.from_spice(path_to_spice_folder, scan_num=scan1)\n", - " scan_th2th = th2th.get_data(axes=(\"del_q\",\"detector\"),norm_to=(1, \"mcu\"))\n", + " scan_th2th = th2th.get_data(axes=(\"del_q\", \"detector\"), norm_to=(1, \"mcu\"))\n", " # perform fit\n", " scan_th2th_fit = Fit1D(scan_th2th, fit_range=fit_range1)\n", " scan_th2th_fit.add_signal(model=\"Gaussian\")\n", " scan_th2th_fit.add_background(model=\"Constant\")\n", " pars_th2th = scan_th2th_fit.guess()\n", " pars_th2th[\"b1_c\"].set(min=0)\n", - " result_th2th = scan_th2th_fit.fit(pars_th2th,USE_ERRORBAR=False)\n", + " result_th2th = scan_th2th_fit.fit(pars_th2th, USE_ERRORBAR=False)\n", " # print(scan_th2th_fit.result.fit_report())\n", "\n", " rez = tas.cooper_nathans(hkl_list=hkl, ei=ei, ef=ef, R0=False, projection=None)\n", @@ -238,65 +236,71 @@ " p1 = Plot1D()\n", " # data\n", " p1.add_scan(scan_th2th, fmt=\"o\", label=\"#{} ({},{},{}) th2th scan\".format(scan1, *hkl))\n", - " # fits \n", + " # fits\n", " p1.add_fit(\n", - " scan_th2th_fit,x=scan_th2th_fit.x_to_plot(),\n", - " label=f\"FWHM={result_th2th.params[\"s1_fwhm\"].value:.4f}+/-{result_th2th.params[\"s1_fwhm\"].stderr:.4f}\",\n", + " scan_th2th_fit,\n", + " x=scan_th2th_fit.x_to_plot(),\n", + " label=f\"FWHM={result_th2th.params['s1_fwhm'].value:.4f}+/-{result_th2th.params['s1_fwhm'].stderr:.4f}\",\n", " )\n", - " # resolution \n", + " # resolution\n", " x_th2th = scan_th2th_fit.result.params[\"s1_center\"].value\n", " components_th2th = result_th2th.eval_components(result_th2th.params, x=x_th2th)\n", " y_th2th = components_th2th[\"s1_\"] / 2 + components_th2th[\"b1_\"]\n", " p1.add_reso_bar(\n", - " pos=(x_th2th, y_th2th), fwhm=rez.coh_fwhms(axis=0), c=\"C3\", \\\n", + " pos=(x_th2th, y_th2th),\n", + " fwhm=rez.coh_fwhms(axis=0),\n", + " c=\"C3\",\n", " label=f\"Resolution FWHM={rez.coh_fwhms(axis=0):.04f}\",\n", " )\n", "\n", " # ------------------------- s1 -------------------------\n", "\n", " s1 = Scan.from_spice(path_to_spice_folder, scan_num=scan2)\n", - " scan_s1= s1.get_data(axes=(\"del_q\",\"detector\"),norm_to=(1, \"mcu\"))\n", + " scan_s1 = s1.get_data(axes=(\"del_q\", \"detector\"), norm_to=(1, \"mcu\"))\n", " # perform fit\n", - " scan_s1_fit = Fit1D(scan_s1,fit_range2)\n", + " scan_s1_fit = Fit1D(scan_s1, fit_range2)\n", " scan_s1_fit.add_signal(model=\"Gaussian\")\n", " scan_s1_fit.add_background(model=\"Constant\")\n", " pars_s1 = scan_s1_fit.guess()\n", - " #pars_s1[\"b1_c\"].set(min=0)\n", + " # pars_s1[\"b1_c\"].set(min=0)\n", " result_s1 = scan_s1_fit.fit(pars_s1, USE_ERRORBAR=False)\n", - " #print(scan_s1_fit.result.fit_report())\n", - "\n", + " # print(scan_s1_fit.result.fit_report())\n", "\n", " p2 = Plot1D()\n", " # data\n", " p2.add_scan(scan_s1, fmt=\"o\", label=\"#{} ({},{},{}) s1 scan\".format(scan2, *hkl))\n", - " # fits \n", + " # fits\n", " p2.add_fit(\n", - " scan_s1_fit,x=scan_s1_fit.x_to_plot(),\n", - " label=f\"FWHM={result_s1.params[\"s1_fwhm\"].value:.4f}+/-{result_s1.params[\"s1_fwhm\"].stderr:.4f}\",\n", + " scan_s1_fit,\n", + " x=scan_s1_fit.x_to_plot(),\n", + " label=f\"FWHM={result_s1.params['s1_fwhm'].value:.4f}+/-{result_s1.params['s1_fwhm'].stderr:.4f}\",\n", " )\n", "\n", - " # resolution \n", + " # resolution\n", " x_s1 = result_s1.params[\"s1_center\"].value\n", " components_s1 = result_s1.eval_components(result_s1.params, x=x_s1)\n", " y_s1 = components_s1[\"s1_\"] / 2 + components_s1[\"b1_\"]\n", " p2.add_reso_bar(\n", - " pos=(x_s1, y_s1), fwhm=rez.coh_fwhms(axis=1), c=\"C3\", \\\n", + " pos=(x_s1, y_s1),\n", + " fwhm=rez.coh_fwhms(axis=1),\n", + " c=\"C3\",\n", " label=f\"Resolution FWHM={rez.coh_fwhms(axis=1):.04f}\",\n", " )\n", - " p2.ylim=(-np.max(scan_s1.y)*0.1,np.max(scan_s1.y)*1.3)\n", + " p2.ylim = (-np.max(scan_s1.y) * 0.1, np.max(scan_s1.y) * 1.3)\n", "\n", " # make plot\n", - " fig, axes = plt.subplots(ncols=2,sharey=True,figsize=(10,5))\n", + " fig, axes = plt.subplots(ncols=2, sharey=True, figsize=(10, 5))\n", " p1.plot(axes[0])\n", " p2.plot(axes[1])\n", "\n", - " return (np.mean(s1.data.get(\"q\")),\n", - " np.mean(s1.data.get(\"s1\")),\n", - " result_th2th,\n", - " result_s1,\n", - " rez.coh_fwhms(axis=0),\n", - " rez.coh_fwhms(axis=1))\n", - "\n" + " return (\n", + " np.mean(s1.data.get(\"q\")),\n", + " np.mean(s1.data.get(\"s1\")),\n", + " result_th2th,\n", + " result_s1,\n", + " rez.coh_fwhms(axis=0),\n", + " rez.coh_fwhms(axis=1),\n", + " )" ] }, { @@ -481,16 +485,17 @@ } ], "source": [ - "# bad peaks \n", + "# bad peaks\n", "# scan_info = (hkl, (th2th scan num, s1, scan num), (fit ranges in del_q))\n", - "scan_info=(((0,0,9), (146,147),(None,None)), # double peaks\n", - " ((0,0,11), (150,151),((-0.08,0.07),None)), #triple pekas\n", - " ((0,0,13), (154,155),((-0.1,0.15),None)), # double peaks\n", - " ((1,1,3), (172,173),((-0.13,0.05),None)), # double\n", - " ((1,1,4), (174,175),((-0.13,0.05),None)),# on a powder line\n", - " ((1,1,5), (176,177),((-0.06,0.15),None)),# double\n", - " ((1,1,7), (180,181),((-0.10,0.15),None)), # double peak\n", - " )\n", + "scan_info = (\n", + " ((0, 0, 9), (146, 147), (None, None)), # double peaks\n", + " ((0, 0, 11), (150, 151), ((-0.08, 0.07), None)), # triple pekas\n", + " ((0, 0, 13), (154, 155), ((-0.1, 0.15), None)), # double peaks\n", + " ((1, 1, 3), (172, 173), ((-0.13, 0.05), None)), # double\n", + " ((1, 1, 4), (174, 175), ((-0.13, 0.05), None)), # on a powder line\n", + " ((1, 1, 5), (176, 177), ((-0.06, 0.15), None)), # double\n", + " ((1, 1, 7), (180, 181), ((-0.10, 0.15), None)), # double peak\n", + ")\n", "\n", "for info in scan_info:\n", " hkl, scans, fit_ranges = info\n", @@ -930,46 +935,47 @@ ], "source": [ "# scan_info = (hkl, (th2th scan num, s1, scan num), (fit ranges in del_q))\n", - "scan_info=(((0,0,2), (132,133),(None,None)),\n", - " ((0,0,3), (134,135),(None,None)),\n", - " ((0,0,4), (136,137),(None,None)),\n", - " ((0,0,5), (138,139),(None,None)),\n", - " ((0,0,6), (140,141),(None,None)),\n", - " ((0,0,7), (142,143),(None,None)),\n", - " ((0,0,8), (144,145),(None,None)),\n", - " # ((0,0,9), (146,147),(None,None)), # double peaks\n", - " ((0,0,10), (148,149),((-0.15,0.09),None)),\n", - " #((0,0,11), (150,151),((-0.08,0.07),None)),\n", - " ((0,0,12), (152,153),(None,None)), # having issues if use errorbar\n", - " #((0,0,13), (154,155),((-0.1,0.15),None)),\n", - " ((0,0,16), (160,161),(None,None)),\n", - " # ((1,1,0), (166,167),(None,None)),# ?????? cannot be fit?????\n", - " ((1,1,1), (168,169),((-0.16,0.12),None)),\n", - " ((1,1,2), (170,171),((-0.16,0.12),None)),\n", - " #((1,1,3), (172,173),((-0.13,0.05),None)),\n", - " #((1,1,4), (174,175),((-0.13,0.05),None)),# on a powder line\n", - " #((1,1,5), (176,177),((-0.06,0.15),None)),\n", - " ((1,1,6), (178,179),((-0.06,0.15),None)),\n", - " # ((1,1,7), (180,181),((-0.10,0.15),None)), # double peak\n", - " ((1,1,8), (182,183),(None,None)),\n", - " ((1,1,10), (186,187),(None,None)),\n", - " ((1,1,12), (190,191),(None,None)),\n", - " ((1,1,14), (194,195),(None,None)),\n", - " )\n", + "scan_info = (\n", + " ((0, 0, 2), (132, 133), (None, None)),\n", + " ((0, 0, 3), (134, 135), (None, None)),\n", + " ((0, 0, 4), (136, 137), (None, None)),\n", + " ((0, 0, 5), (138, 139), (None, None)),\n", + " ((0, 0, 6), (140, 141), (None, None)),\n", + " ((0, 0, 7), (142, 143), (None, None)),\n", + " ((0, 0, 8), (144, 145), (None, None)),\n", + " # ((0,0,9), (146,147),(None,None)), # double peaks\n", + " ((0, 0, 10), (148, 149), ((-0.15, 0.09), None)),\n", + " # ((0,0,11), (150,151),((-0.08,0.07),None)),\n", + " ((0, 0, 12), (152, 153), (None, None)), # having issues if use errorbar\n", + " # ((0,0,13), (154,155),((-0.1,0.15),None)),\n", + " ((0, 0, 16), (160, 161), (None, None)),\n", + " # ((1,1,0), (166,167),(None,None)),# ?????? cannot be fit?????\n", + " ((1, 1, 1), (168, 169), ((-0.16, 0.12), None)),\n", + " ((1, 1, 2), (170, 171), ((-0.16, 0.12), None)),\n", + " # ((1,1,3), (172,173),((-0.13,0.05),None)),\n", + " # ((1,1,4), (174,175),((-0.13,0.05),None)),# on a powder line\n", + " # ((1,1,5), (176,177),((-0.06,0.15),None)),\n", + " ((1, 1, 6), (178, 179), ((-0.06, 0.15), None)),\n", + " # ((1,1,7), (180,181),((-0.10,0.15),None)), # double peak\n", + " ((1, 1, 8), (182, 183), (None, None)),\n", + " ((1, 1, 10), (186, 187), (None, None)),\n", + " ((1, 1, 12), (190, 191), (None, None)),\n", + " ((1, 1, 14), (194, 195), (None, None)),\n", + ")\n", "\n", "\n", "# ------------------------ outputs to be collected --------------------\n", - "q_list=[]\n", - "s1_list=[]\n", - "hkl_list=[]\n", - "exp_th2th=[]\n", - "exp_s1=[]\n", - "cn_fwhm_th2th=[]\n", - "cn_fwhm_s1=[]\n", + "q_list = []\n", + "s1_list = []\n", + "hkl_list = []\n", + "exp_th2th = []\n", + "exp_s1 = []\n", + "cn_fwhm_th2th = []\n", + "cn_fwhm_s1 = []\n", "\n", "for info in scan_info:\n", " hkl, scans, fit_ranges = info\n", - " q, _,th2th, s1, cn_th2th, cn_s1= analyze_in_q(hkl, scans, fit_ranges)\n", + " q, _, th2th, s1, cn_th2th, cn_s1 = analyze_in_q(hkl, scans, fit_ranges)\n", " # ------------------ collect output ---------------------------\n", " hkl_list.append(hkl)\n", " q_list.append(q)\n", @@ -1012,16 +1018,26 @@ } ], "source": [ - "fig, ax=plt.subplots()\n", + "fig, ax = plt.subplots()\n", "ax.set_xlabel(\"Q (A)\")\n", "ax.set_ylabel(\"FWHM/Q\")\n", - "ax.set_ylim([0,0.07])\n", - "ax.errorbar(q_list,np.array([s1.params[\"s1_fwhm\"].value for s1 in exp_s1])/np.array(q_list),\\\n", - " yerr=np.array([s1.params[\"s1_fwhm\"].stderr for s1 in exp_s1])/np.array(q_list), fmt=\"s\",label=\"exp s1\")\n", - "ax.errorbar(q_list,np.array([th2th.params[\"s1_fwhm\"].value for th2th in exp_th2th])/np.array(q_list),\\\n", - " yerr=np.array([th2th.params[\"s1_fwhm\"].stderr for th2th in exp_th2th])/np.array(q_list), fmt ='o',label=\"exp th2th\")\n", - "ax.plot(q_list,np.array(cn_fwhm_s1)/np.array(q_list),'s', markerfacecolor='none',label=\"CN s1\",c=\"C0\")\n", - "ax.plot(q_list,np.array(cn_fwhm_th2th)/np.array(q_list),'o', markerfacecolor='none',label=\"CN th2th\",c=\"C1\")\n", + "ax.set_ylim([0, 0.07])\n", + "ax.errorbar(\n", + " q_list,\n", + " np.array([s1.params[\"s1_fwhm\"].value for s1 in exp_s1]) / np.array(q_list),\n", + " yerr=np.array([s1.params[\"s1_fwhm\"].stderr for s1 in exp_s1]) / np.array(q_list),\n", + " fmt=\"s\",\n", + " label=\"exp s1\",\n", + ")\n", + "ax.errorbar(\n", + " q_list,\n", + " np.array([th2th.params[\"s1_fwhm\"].value for th2th in exp_th2th]) / np.array(q_list),\n", + " yerr=np.array([th2th.params[\"s1_fwhm\"].stderr for th2th in exp_th2th]) / np.array(q_list),\n", + " fmt=\"o\",\n", + " label=\"exp th2th\",\n", + ")\n", + "ax.plot(q_list, np.array(cn_fwhm_s1) / np.array(q_list), \"s\", markerfacecolor=\"none\", label=\"CN s1\", c=\"C0\")\n", + "ax.plot(q_list, np.array(cn_fwhm_th2th) / np.array(q_list), \"o\", markerfacecolor=\"none\", label=\"CN th2th\", c=\"C1\")\n", "\n", "ax.legend()\n", "ax.grid(alpha=0.6)" @@ -1059,32 +1075,36 @@ } ], "source": [ - "fig, ax=plt.subplots()\n", + "fig, ax = plt.subplots()\n", "ax.set_xlabel(\"Q (A)\")\n", "ax.set_ylabel(\"FWHM (A)\")\n", - "ax.set_ylim([0,0.1])\n", - "ax.set_xlim([0,5])\n", - "exp_fwhm_s1=np.array([s1.params[\"s1_fwhm\"].value for s1 in exp_s1])\n", - "exp_fwhm_th2th=np.array([th2th.params[\"s1_fwhm\"].value for th2th in exp_th2th])\n", - "ax.errorbar(q_list,exp_fwhm_s1,\\\n", - " yerr=np.array([s1.params[\"s1_fwhm\"].stderr for s1 in exp_s1]), fmt=\"s\",label=\"exp s1\")\n", - "ax.plot(q_list,cn_fwhm_s1,'s', markerfacecolor='none',label=\"CN s1\",c=\"C0\")\n", - "ax.errorbar(q_list,exp_fwhm_th2th,\\\n", - " yerr=np.array([th2th.params[\"s1_fwhm\"].stderr for th2th in exp_th2th]), fmt ='o',label=\"exp th2th\")\n", - "ax.plot(q_list,cn_fwhm_th2th,'o', markerfacecolor='none',label=\"CN th2th\",c=\"C1\")\n", + "ax.set_ylim([0, 0.1])\n", + "ax.set_xlim([0, 5])\n", + "exp_fwhm_s1 = np.array([s1.params[\"s1_fwhm\"].value for s1 in exp_s1])\n", + "exp_fwhm_th2th = np.array([th2th.params[\"s1_fwhm\"].value for th2th in exp_th2th])\n", + "ax.errorbar(q_list, exp_fwhm_s1, yerr=np.array([s1.params[\"s1_fwhm\"].stderr for s1 in exp_s1]), fmt=\"s\", label=\"exp s1\")\n", + "ax.plot(q_list, cn_fwhm_s1, \"s\", markerfacecolor=\"none\", label=\"CN s1\", c=\"C0\")\n", + "ax.errorbar(\n", + " q_list,\n", + " exp_fwhm_th2th,\n", + " yerr=np.array([th2th.params[\"s1_fwhm\"].stderr for th2th in exp_th2th]),\n", + " fmt=\"o\",\n", + " label=\"exp th2th\",\n", + ")\n", + "ax.plot(q_list, cn_fwhm_th2th, \"o\", markerfacecolor=\"none\", label=\"CN th2th\", c=\"C1\")\n", "for i, hkl in enumerate(hkl_list):\n", - " x=q_list[i]\n", - " y= exp_fwhm_th2th[i]+0.002\n", + " x = q_list[i]\n", + " y = exp_fwhm_th2th[i] + 0.002\n", " # mannual ajdjust position\n", - " if hkl ==(1,1,0):\n", - " x-=0.15\n", - " if hkl ==(1,1,1):\n", - " x-=0.2\n", - " y-=0.012\n", - " if hkl==(1,1,2):\n", - " x+=0.1\n", - " y-=0.012\n", - " ax.annotate(hkl, (x,y),rotation=90,fontsize=8)\n", + " if hkl == (1, 1, 0):\n", + " x -= 0.15\n", + " if hkl == (1, 1, 1):\n", + " x -= 0.2\n", + " y -= 0.012\n", + " if hkl == (1, 1, 2):\n", + " x += 0.1\n", + " y -= 0.012\n", + " ax.annotate(hkl, (x, y), rotation=90, fontsize=8)\n", "\n", "ax.legend(loc=2)\n", "ax.grid(alpha=0.6)\n", @@ -1124,32 +1144,37 @@ } ], "source": [ - "fig, ax=plt.subplots()\n", + "fig, ax = plt.subplots()\n", "ax.set_xlabel(\"integ. intent. s1\")\n", "ax.set_ylabel(\"integ. intent. th2th\")\n", "# ax.set_xlim([-100,2000])\n", "# ax.set_ylim([-300,6000])\n", "\n", - "x_array=np.array([s1.params[\"s1_amplitude\"].value for s1 in exp_s1])\n", - "y_array=np.array([th2th.params[\"s1_amplitude\"].value for th2th in exp_th2th])\n", - "ax.errorbar(x=x_array,y=y_array,\\\n", - " xerr=np.array([s1.params[\"s1_amplitude\"].stderr for s1 in exp_s1]),\\\n", - " yerr=np.array([th2th.params[\"s1_amplitude\"].stderr for th2th in exp_th2th]), fmt=\"o\",label=\"exp integ. intent. in Q\")\n", + "x_array = np.array([s1.params[\"s1_amplitude\"].value for s1 in exp_s1])\n", + "y_array = np.array([th2th.params[\"s1_amplitude\"].value for th2th in exp_th2th])\n", + "ax.errorbar(\n", + " x=x_array,\n", + " y=y_array,\n", + " xerr=np.array([s1.params[\"s1_amplitude\"].stderr for s1 in exp_s1]),\n", + " yerr=np.array([th2th.params[\"s1_amplitude\"].stderr for th2th in exp_th2th]),\n", + " fmt=\"o\",\n", + " label=\"exp integ. intent. in Q\",\n", + ")\n", "\n", "\n", - "slope=2.7\n", - "ax.plot([0,6000],[0,6000*slope],'r',label=f\"y = {slope} x\")\n", + "slope = 2.7\n", + "ax.plot([0, 6000], [0, 6000 * slope], \"r\", label=f\"y = {slope} x\")\n", "\n", "for i, hkl in enumerate(hkl_list):\n", - " x=x_array[i]\n", - " y= y_array[i]*1.5\n", + " x = x_array[i]\n", + " y = y_array[i] * 1.5\n", " # mannual ajdjust position\n", " # if hkl ==(1,1,0):\n", " # x-=0.15\n", - " ax.annotate(hkl, (x,y),rotation=90,fontsize=8)\n", + " ax.annotate(hkl, (x, y), rotation=90, fontsize=8)\n", "\n", - "plt.xscale('log')\n", - "plt.yscale('log')\n", + "plt.xscale(\"log\")\n", + "plt.yscale(\"log\")\n", "\n", "ax.legend(loc=2)\n", "ax.grid(alpha=0.6)\n", @@ -1163,72 +1188,66 @@ "metadata": {}, "outputs": [], "source": [ - "from tavi.data.fit import Fit1D\n", - "from tavi.data.scan import Scan\n", - "from tavi.plotter import Plot1D\n", - "\n", - "\n", "def analyze_in_angles(hkl, scans, fit_ranges):\n", - " scan1, scan2=scans\n", - " fit_range1,fit_range2=fit_ranges\n", - " \n", + " scan1, scan2 = scans\n", + " fit_range1, fit_range2 = fit_ranges\n", + "\n", " # ------------------------- th2th -------------------------\n", "\n", " th2th = Scan.from_spice(path_to_spice_folder, scan_num=scan1)\n", - " scan_th2th = th2th.get_data(axes=(\"s1\",\"detector\"),norm_to=(1, \"mcu\"))\n", + " scan_th2th = th2th.get_data(axes=(\"s1\", \"detector\"), norm_to=(1, \"mcu\"))\n", " # perform fit\n", " scan_th2th_fit = Fit1D(scan_th2th, fit_range=fit_range1)\n", " scan_th2th_fit.add_signal(model=\"Gaussian\")\n", " scan_th2th_fit.add_background(model=\"Constant\")\n", " pars_th2th = scan_th2th_fit.guess()\n", " pars_th2th[\"b1_c\"].set(min=0)\n", - " result_th2th = scan_th2th_fit.fit(pars_th2th,USE_ERRORBAR=False)\n", + " result_th2th = scan_th2th_fit.fit(pars_th2th, USE_ERRORBAR=False)\n", " # print(scan_th2th_fit.result.fit_report())\n", "\n", - "\n", " p1 = Plot1D()\n", " # data\n", " p1.add_scan(scan_th2th, fmt=\"o\", label=\"#{} ({},{},{}) th2th scan\".format(scan1, *hkl))\n", - " # fits \n", + " # fits\n", " if result_th2th.success:\n", " p1.add_fit(\n", - " scan_th2th_fit,x=scan_th2th_fit.x_to_plot(),\n", - " label=f\"FWHM={result_th2th.params[\"s1_fwhm\"].value:.4f}+/-{result_th2th.params[\"s1_fwhm\"].stderr:.4f}\",\n", + " scan_th2th_fit,\n", + " x=scan_th2th_fit.x_to_plot(),\n", + " label=f\"FWHM={result_th2th.params['s1_fwhm'].value:.4f}+/-{result_th2th.params['s1_fwhm'].stderr:.4f}\",\n", " )\n", "\n", " # ------------------------- s1 -------------------------\n", "\n", " s1 = Scan.from_spice(path_to_spice_folder, scan_num=scan2)\n", - " scan_s1= s1.get_data(axes=(\"s1\",\"detector\"),norm_to=(1, \"mcu\"))\n", + " scan_s1 = s1.get_data(axes=(\"s1\", \"detector\"), norm_to=(1, \"mcu\"))\n", " # perform fit\n", - " scan_s1_fit = Fit1D(scan_s1,fit_range2)\n", + " scan_s1_fit = Fit1D(scan_s1, fit_range2)\n", " scan_s1_fit.add_signal(model=\"Gaussian\")\n", " scan_s1_fit.add_background(model=\"Constant\")\n", " pars_s1 = scan_s1_fit.guess()\n", - " #pars_s1[\"b1_c\"].set(min=0)\n", + " # pars_s1[\"b1_c\"].set(min=0)\n", " result_s1 = scan_s1_fit.fit(pars_s1, USE_ERRORBAR=False)\n", - " #print(scan_s1_fit.result.fit_report())\n", - "\n", + " # print(scan_s1_fit.result.fit_report())\n", "\n", " p2 = Plot1D()\n", " # data\n", " p2.add_scan(scan_s1, fmt=\"o\", label=\"#{} ({},{},{}) s1 scan\".format(scan2, *hkl))\n", - " # fits \n", + " # fits\n", " if result_s1.success:\n", " p2.add_fit(\n", - " scan_s1_fit,x=scan_s1_fit.x_to_plot(),\n", - " label=f\"FWHM={result_s1.params[\"s1_fwhm\"].value:.4f}+/-{result_s1.params[\"s1_fwhm\"].stderr:.4f}\",\n", + " scan_s1_fit,\n", + " x=scan_s1_fit.x_to_plot(),\n", + " label=f\"FWHM={result_s1.params['s1_fwhm'].value:.4f}+/-{result_s1.params['s1_fwhm'].stderr:.4f}\",\n", " )\n", "\n", - " p2.ylim=(-np.max(scan_s1.y)*0.1,np.max(scan_s1.y)*1.3)\n", + " p2.ylim = (-np.max(scan_s1.y) * 0.1, np.max(scan_s1.y) * 1.3)\n", "\n", " # make plot\n", - " fig, axes = plt.subplots(ncols=2,sharey=True,figsize=(10,5))\n", + " fig, axes = plt.subplots(ncols=2, sharey=True, figsize=(10, 5))\n", " p1.plot(axes[0])\n", " p2.plot(axes[1])\n", "\n", - " return (result_th2th,\n", - " result_s1)" + " return (result_th2th, result_s1)" ] }, { @@ -1650,48 +1669,48 @@ } ], "source": [ - "scan_info=(((0,0,2), (132,133),(None,None)),\n", - " ((0,0,3), (134,135),(None,None)),\n", - " ((0,0,4), (136,137),(None,None)),\n", - " ((0,0,5), (138,139),(None,None)),\n", - " ((0,0,6), (140,141),(None,None)),\n", - " ((0,0,7), (142,143),(None,None)),\n", - " ((0,0,8), (144,145),(None,None)),\n", - " # ((0,0,9), (146,147),(None,None)), # double peaks\n", - " ((0,0,10), (148,149),((-27.5,-24),None)),\n", - " #((0,0,11), (150,151),((-0.08,0.07),None)),\n", - " ((0,0,12), (152,153),(None,None)), # having issues if use errorbar\n", - " #((0,0,13), (154,155),((-0.1,0.15),None)),\n", - " ((0,0,16), (160,161),(None,None)),\n", - " # ((1,1,0), (166,167),(None,None)),# ?????? cannot be fit?????\n", - " ((1,1,1), (168,169),((57,61),None)),\n", - " ((1,1,2), (170,171),((51,55),None)),\n", - " #((1,1,3), (172,173),((-0.13,0.05),None)),\n", - " #((1,1,4), (174,175),((-0.13,0.05),None)),# on a powder line\n", - " #((1,1,5), (176,177),((-0.06,0.15),None)),\n", - " ((1,1,6), (178,179),(None,None)),\n", - " # ((1,1,7), (180,181),((-0.10,0.15),None)), # double peak\n", - " ((1,1,8), (182,183),(None,None)),\n", - " ((1,1,10), (186,187),(None,None)),\n", - " ((1,1,12), (190,191),(None,None)),\n", - " ((1,1,14), (194,195),(None,None)),\n", - " )\n", + "scan_info = (\n", + " ((0, 0, 2), (132, 133), (None, None)),\n", + " ((0, 0, 3), (134, 135), (None, None)),\n", + " ((0, 0, 4), (136, 137), (None, None)),\n", + " ((0, 0, 5), (138, 139), (None, None)),\n", + " ((0, 0, 6), (140, 141), (None, None)),\n", + " ((0, 0, 7), (142, 143), (None, None)),\n", + " ((0, 0, 8), (144, 145), (None, None)),\n", + " # ((0,0,9), (146,147),(None,None)), # double peaks\n", + " ((0, 0, 10), (148, 149), ((-27.5, -24), None)),\n", + " # ((0,0,11), (150,151),((-0.08,0.07),None)),\n", + " ((0, 0, 12), (152, 153), (None, None)), # having issues if use errorbar\n", + " # ((0,0,13), (154,155),((-0.1,0.15),None)),\n", + " ((0, 0, 16), (160, 161), (None, None)),\n", + " # ((1,1,0), (166,167),(None,None)),# ?????? cannot be fit?????\n", + " ((1, 1, 1), (168, 169), ((57, 61), None)),\n", + " ((1, 1, 2), (170, 171), ((51, 55), None)),\n", + " # ((1,1,3), (172,173),((-0.13,0.05),None)),\n", + " # ((1,1,4), (174,175),((-0.13,0.05),None)),# on a powder line\n", + " # ((1,1,5), (176,177),((-0.06,0.15),None)),\n", + " ((1, 1, 6), (178, 179), (None, None)),\n", + " # ((1,1,7), (180,181),((-0.10,0.15),None)), # double peak\n", + " ((1, 1, 8), (182, 183), (None, None)),\n", + " ((1, 1, 10), (186, 187), (None, None)),\n", + " ((1, 1, 12), (190, 191), (None, None)),\n", + " ((1, 1, 14), (194, 195), (None, None)),\n", + ")\n", "\n", "\n", "# ------------------------ outputs to be collected --------------------\n", - "hkl_list=[]\n", - "exp_th2th=[]\n", - "exp_s1=[]\n", + "hkl_list = []\n", + "exp_th2th = []\n", + "exp_s1 = []\n", "\n", "\n", "for info in scan_info:\n", " hkl, scans, fit_ranges = info\n", - " th2th, s1= analyze_in_angles(hkl, scans, fit_ranges)\n", + " th2th, s1 = analyze_in_angles(hkl, scans, fit_ranges)\n", " # ------------------ collect output ---------------------------\n", " hkl_list.append(hkl)\n", " exp_th2th.append(th2th)\n", - " exp_s1.append(s1)\n", - " " + " exp_s1.append(s1)" ] }, { @@ -1726,32 +1745,37 @@ } ], "source": [ - "fig, ax=plt.subplots()\n", + "fig, ax = plt.subplots()\n", "ax.set_xlabel(\"integ. intent. s1\")\n", "ax.set_ylabel(\"integ. intent. th2th\")\n", "# ax.set_xlim([-100,2000])\n", "# ax.set_ylim([-300,6000])\n", "\n", - "x_array=np.array([s1.params[\"s1_amplitude\"].value for s1 in exp_s1])\n", - "y_array=np.array([th2th.params[\"s1_amplitude\"].value for th2th in exp_th2th])\n", - "ax.errorbar(x=x_array,y=y_array,\\\n", - " xerr=np.array([s1.params[\"s1_amplitude\"].stderr for s1 in exp_s1]),\\\n", - " yerr=np.array([th2th.params[\"s1_amplitude\"].stderr for th2th in exp_th2th]), fmt=\"o\",label=\"exp integ. intent. in angles\")\n", + "x_array = np.array([s1.params[\"s1_amplitude\"].value for s1 in exp_s1])\n", + "y_array = np.array([th2th.params[\"s1_amplitude\"].value for th2th in exp_th2th])\n", + "ax.errorbar(\n", + " x=x_array,\n", + " y=y_array,\n", + " xerr=np.array([s1.params[\"s1_amplitude\"].stderr for s1 in exp_s1]),\n", + " yerr=np.array([th2th.params[\"s1_amplitude\"].stderr for th2th in exp_th2th]),\n", + " fmt=\"o\",\n", + " label=\"exp integ. intent. in angles\",\n", + ")\n", "\n", "\n", - "slope=2.7\n", - "ax.plot([0,1e5],[0,1e5*slope],'r',label=f\"y = {slope} x\")\n", + "slope = 2.7\n", + "ax.plot([0, 1e5], [0, 1e5 * slope], \"r\", label=f\"y = {slope} x\")\n", "\n", "for i, hkl in enumerate(hkl_list):\n", - " x=x_array[i]\n", - " y= y_array[i]*1.2\n", + " x = x_array[i]\n", + " y = y_array[i] * 1.2\n", " # mannual ajdjust position\n", " # if hkl ==(1,1,0):\n", " # x-=0.15\n", - " ax.annotate(hkl, (x,y),rotation=90,fontsize=8)\n", + " ax.annotate(hkl, (x, y), rotation=90, fontsize=8)\n", "\n", - "plt.xscale('log')\n", - "plt.yscale('log')\n", + "plt.xscale(\"log\")\n", + "plt.yscale(\"log\")\n", "\n", "ax.legend(loc=2)\n", "ax.grid(alpha=0.6)\n", diff --git a/scripts/HB1A_resolution/FeSn_film_HB1A.py b/scripts/HB1A_resolution/FeSn_film_HB1A.py index ea777386..8d1041ba 100644 --- a/scripts/HB1A_resolution/FeSn_film_HB1A.py +++ b/scripts/HB1A_resolution/FeSn_film_HB1A.py @@ -49,7 +49,7 @@ p1.add_scan(fesn000p5_lscan, fmt="o") p1.add_fit( f1_lscan, - label=f"FWHM={f1_lscan.result.params["s1_fwhm"].value:.4f}+/-{f1_lscan.result.params["s1_fwhm"].stderr:.4f}", + label=f"FWHM={f1_lscan.result.params['s1_fwhm'].value:.4f}+/-{f1_lscan.result.params['s1_fwhm'].stderr:.4f}", ) x = f1_lscan.result.params["s1_center"].value components = result.eval_components(result.params, x=x) @@ -74,7 +74,7 @@ p1_2.add_scan(fesn000p5_qscan, fmt="o") p1_2.add_fit( f1_qscan, - label=f"FWHM={f1_qscan.result.params["s1_fwhm"].value:.4f}+/-{f1_qscan.result.params["s1_fwhm"].stderr:.4f}", + label=f"FWHM={f1_qscan.result.params['s1_fwhm'].value:.4f}+/-{f1_qscan.result.params['s1_fwhm'].stderr:.4f}", ) x = f1_qscan.result.params["s1_center"].value components = result.eval_components(result.params, x=x) @@ -103,7 +103,7 @@ p2.add_scan(substrate006_lscan, fmt="o") p2.add_fit( f2_lscan, - label=f"FWHM={f2_lscan.result.params["s1_fwhm"].value:.4f}+/-{f2_lscan.result.params["s1_fwhm"].stderr:.4f}", + label=f"FWHM={f2_lscan.result.params['s1_fwhm'].value:.4f}+/-{f2_lscan.result.params['s1_fwhm'].stderr:.4f}", ) x = f2_lscan.result.params["s1_center"].value components = result.eval_components(result.params, x=x) @@ -130,7 +130,7 @@ p2_2.add_scan(substrate006_qscan, fmt="o") p2_2.add_fit( f2_qscan, - label=f"FWHM={f2_qscan.result.params["s1_fwhm"].value:.4f}+/-{f2_qscan.result.params["s1_fwhm"].stderr:.4f}", + label=f"FWHM={f2_qscan.result.params['s1_fwhm'].value:.4f}+/-{f2_qscan.result.params['s1_fwhm'].stderr:.4f}", ) x = f2_qscan.result.params["s1_center"].value components = result.eval_components(result.params, x=x) @@ -169,7 +169,7 @@ p3.add_scan(fesn000p5_lscan_2, fmt="o") p3.add_fit( f3_lscan, - label=f"FWHM={result.params["s1_fwhm"].value:.4f}+/-{result.params["s1_fwhm"].stderr:.4f}", + label=f"FWHM={result.params['s1_fwhm'].value:.4f}+/-{result.params['s1_fwhm'].stderr:.4f}", ) x = result.params["s1_center"].value components = result.eval_components(result.params, x=x) diff --git a/scripts/HB1A_resolution/La2Ni7_resolution_in_Q.py b/scripts/HB1A_resolution/La2Ni7_resolution_in_Q.py index 6a4b0cc5..0605cd7d 100644 --- a/scripts/HB1A_resolution/La2Ni7_resolution_in_Q.py +++ b/scripts/HB1A_resolution/La2Ni7_resolution_in_Q.py @@ -36,7 +36,7 @@ def analyze_in_q(hkl, scans, fit_ranges): p1.add_fit( scan_th2th_fit, x=scan_th2th_fit.x_to_plot(), - label=f"FWHM={result_th2th.params["s1_fwhm"].value:.4f}+/-{result_th2th.params["s1_fwhm"].stderr:.4f}", + label=f"FWHM={result_th2th.params['s1_fwhm'].value:.4f}+/-{result_th2th.params['s1_fwhm'].stderr:.4f}", ) # resolution x_th2th = scan_th2th_fit.result.params["s1_center"].value @@ -69,7 +69,7 @@ def analyze_in_q(hkl, scans, fit_ranges): p2.add_fit( scan_s1_fit, x=scan_s1_fit.x_to_plot(), - label=f"FWHM={result_s1.params["s1_fwhm"].value:.4f}+/-{result_s1.params["s1_fwhm"].stderr:.4f}", + label=f"FWHM={result_s1.params['s1_fwhm'].value:.4f}+/-{result_s1.params['s1_fwhm'].stderr:.4f}", ) # resolution diff --git a/scripts/HB1A_resolution/rez_HB1A.py b/scripts/HB1A_resolution/rez_HB1A.py index c221436e..d50d75cc 100644 --- a/scripts/HB1A_resolution/rez_HB1A.py +++ b/scripts/HB1A_resolution/rez_HB1A.py @@ -84,7 +84,7 @@ p4.add_fit( hh1_fit, x=hh1_fit.x_to_plot(), - label=f"FWHM={result.params["s1_fwhm"].value:.5f}+/-{result.params["s1_fwhm"].stderr:.5f}", + label=f"FWHM={result.params['s1_fwhm'].value:.5f}+/-{result.params['s1_fwhm'].stderr:.5f}", ) x = hh1_fit.result.params["s1_center"].value @@ -148,7 +148,7 @@ p5.add_fit( hh1_fit_2, x=hh1_fit.x_to_plot(), - label=f"FWHM={result.params["s1_fwhm"].value:.5f}+/-{result.params["s1_fwhm"].stderr:.5f}", + label=f"FWHM={result.params['s1_fwhm'].value:.5f}+/-{result.params['s1_fwhm'].stderr:.5f}", ) x = hh1_fit_2.result.params["s1_center"].value diff --git a/scripts/Sunny_enabler/rez_loader.jl b/scripts/Sunny_enabler/rez_loader.jl index 32a22531..6463ec72 100644 --- a/scripts/Sunny_enabler/rez_loader.jl +++ b/scripts/Sunny_enabler/rez_loader.jl @@ -6,4 +6,4 @@ scan0042 = pdata["scan0042"] rez_mat = read(scan0042, "rez_mat") scan0001 = fid["data"]["IPTS32124_CG4C_exp0424"]["scan0001"] -read(scan0001["sample"], "unit_cell") \ No newline at end of file +read(scan0001["sample"], "unit_cell") diff --git a/scripts/Sunny_enabler/scans_rez.py b/scripts/Sunny_enabler/scans_rez.py index 46b9cb6b..91b539c8 100644 --- a/scripts/Sunny_enabler/scans_rez.py +++ b/scripts/Sunny_enabler/scans_rez.py @@ -35,7 +35,6 @@ rez_r0_list = [] for i in range(len(ei_list)): - rez = tas.rez( ei=ei_list[i], ef=ef_list[i], 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/fit.py b/src/tavi/data/fit.py index 57b0e3f1..21a86b9d 100644 --- a/src/tavi/data/fit.py +++ b/src/tavi/data/fit.py @@ -172,7 +172,6 @@ def eval(self, pars: Parameters, x: np.ndarray) -> np.ndarray: return self.model.eval(pars, x=x) def fit(self, pars: Parameters, USE_ERRORBAR=True) -> ModelResult: - if USE_ERRORBAR: result = self.model.fit(self.y, pars, x=self.x, weights=self.err) else: diff --git a/src/tavi/data/nexus_builder.py b/src/tavi/data/nexus_builder.py index 9010e888..47adfd59 100644 --- a/src/tavi/data/nexus_builder.py +++ b/src/tavi/data/nexus_builder.py @@ -251,8 +251,8 @@ def spice_scan_to_nxdict( EX_required="true", ) for i in range(8): # CG4C horizontal focusing - nxana.add_dataset(key=f"qm{i+1}", ds=NXdataset(ds=spicelogs.get(f"qm{i+1}"), type="NX_FLOAT")) - nxana.add_dataset(key=f"xm{i+1}", ds=NXdataset(ds=spicelogs.get(f"xm{i+1}"), type="NX_FLOAT")) + nxana.add_dataset(key=f"qm{i + 1}", ds=NXdataset(ds=spicelogs.get(f"qm{i + 1}"), type="NX_FLOAT")) + nxana.add_dataset(key=f"xm{i + 1}", ds=NXdataset(ds=spicelogs.get(f"xm{i + 1}"), type="NX_FLOAT")) if instrument_config_params is not None: if (ana_params := instrument_config_params.get("analyzer")) is not None: @@ -308,7 +308,6 @@ def spice_scan_to_nxdict( if instrument_config_params is not None: if (coll_params := instrument_config_params.get("collimators")) is not None: - try: div_x = [ coll_params["h_pre_mono"], diff --git a/src/tavi/data/scan.py b/src/tavi/data/scan.py index aa0f6f7f..a23a48ad 100644 --- a/src/tavi/data/scan.py +++ b/src/tavi/data/scan.py @@ -74,7 +74,6 @@ class Scan(object): """ def __init__(self, name: str, nexus_dict: NexusEntry) -> None: - self.name: str = name self._nexus_dict: NexusEntry = nexus_dict self.data: dict = self.get_data_columns() diff --git a/src/tavi/data/scan_data.py b/src/tavi/data/scan_data.py index 6eb20b87..66facaeb 100644 --- a/src/tavi/data/scan_data.py +++ b/src/tavi/data/scan_data.py @@ -15,7 +15,6 @@ def __init__( y: np.ndarray, norm: Optional[np.ndarray] = None, ) -> None: - # ind = np.argsort(x) # self.x = x[ind] # self.y = y[ind] @@ -198,7 +197,6 @@ def rebin_grid(self, rebin_params: tuple): counts = np.zeros_like(x) for i, x0 in enumerate(self.x): - # Return the indices of the maximum values in the specified axis ignoring NaNs. idx = np.nanargmax(x_boundary - ZERO > x0) if idx > 0: # ignore first and last bin box @@ -246,7 +244,6 @@ def rebin_grid_renorm(self, rebin_params: tuple, norm_col: Optional[np.ndarray] class ScanData2D(object): - ZEROS = 1e-6 def __init__( diff --git a/src/tavi/data/scan_group.py b/src/tavi/data/scan_group.py index dbb21758..8c2bce9b 100644 --- a/src/tavi/data/scan_group.py +++ b/src/tavi/data/scan_group.py @@ -61,7 +61,6 @@ def _get_data_1d( norm_to: Optional[tuple[float, str]], **rebin_params_dict: Optional[tuple], ) -> ScanData1D: - x_axis, y_axis = axes x_array = np.array([]) y_array = np.array([]) diff --git a/src/tavi/instrument/instrument_params/cg4c.json b/src/tavi/instrument/instrument_params/cg4c.json index ffe46d84..9ce15585 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/hb1a.json b/src/tavi/instrument/instrument_params/hb1a.json index c7c5a4f8..7dc5d8db 100644 --- a/src/tavi/instrument/instrument_params/hb1a.json +++ b/src/tavi/instrument/instrument_params/hb1a.json @@ -69,4 +69,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 bf665f64..739e2ba8 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/hb3_mnte.json b/src/tavi/instrument/instrument_params/hb3_mnte.json index 1f99950d..57f64450 100644 --- a/src/tavi/instrument/instrument_params/hb3_mnte.json +++ b/src/tavi/instrument/instrument_params/hb3_mnte.json @@ -73,4 +73,4 @@ "v_post_sample": 120, "v_post_ana": 120 } -} \ No newline at end of file +} diff --git a/src/tavi/instrument/instrument_params/takin_test.json b/src/tavi/instrument/instrument_params/takin_test.json index 9af60ea2..5056e5b9 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/cooper_nathans.py b/src/tavi/instrument/resolution/cooper_nathans.py index 74eab3ff..3321d471 100755 --- a/src/tavi/instrument/resolution/cooper_nathans.py +++ b/src/tavi/instrument/resolution/cooper_nathans.py @@ -198,7 +198,6 @@ def rez( rez_list = [] for hkl, ei, ef in hkle_list: - # q_lab = conv_mat @ hkl # q_mod = np.linalg.norm(q_lab) q_mod = np.linalg.norm(self.sample.b_mat @ hkl) * 2 * np.pi @@ -212,7 +211,7 @@ def rez( two_theta = get_angle_from_triangle(ki, kf, q_mod) * self.goniometer._sense except TypeError: rez.STATUS = False - print(f"Cannot close triangle for ei={ei}, ef={ef}, hkl={np.round(hkl,3)}.") + print(f"Cannot close triangle for ei={ei}, ef={ef}, hkl={np.round(hkl, 3)}.") rez._set_labels() rez_list.append(rez) diff --git a/src/tavi/instrument/resolution/ellipsoid.py b/src/tavi/instrument/resolution/ellipsoid.py index e6b1281f..61243098 100755 --- a/src/tavi/instrument/resolution/ellipsoid.py +++ b/src/tavi/instrument/resolution/ellipsoid.py @@ -39,7 +39,6 @@ def __init__( sample: Xtal, projection: Optional[tuple] = ((1, 0, 0), (0, 1, 0), (0, 0, 1)), ) -> None: - self.STATUS: bool self.q: tuple[float, float, float] @@ -278,7 +277,6 @@ def plot_ellipses(self): fig = plt.figure(figsize=(10, 6)) for i, indices in enumerate([(0, 3), (1, 3), (2, 3), (0, 1), (1, 2), (0, 2)]): - ellipse_co = self.get_ellipse(axes=indices, PROJECTION=False) ellipse_inco = self.get_ellipse(axes=indices, PROJECTION=True) @@ -292,7 +290,7 @@ def plot_ellipses(self): p.add_reso(ellipse_inco, c="k", linestyle="dashed") ax = fig.add_subplot( - int(f"23{i+1}"), + int(f"23{i + 1}"), axes_class=Axes, grid_helper=p.grid_helper(ellipse_co.angle), ) diff --git a/src/tavi/instrument/tas.py b/src/tavi/instrument/tas.py index 232fab78..ca2fa477 100644 --- a/src/tavi/instrument/tas.py +++ b/src/tavi/instrument/tas.py @@ -73,7 +73,7 @@ def get_two_theta( q_norm = np.sqrt(q_sq) two_theta_radian = get_angle_from_triangle(ki, kf, q_norm) if two_theta_radian is None: - print(f"Triangle cannot be closed at q=({qh}, {qk}, {ql}), en={ei-ef} meV.") + print(f"Triangle cannot be closed at q=({qh}, {qk}, {ql}), en={ei - ef} meV.") return None # elif np.rad2deg(two_theta_radian) < S2_MIN_DEG: # pass @@ -86,7 +86,7 @@ def calculate_ub_matrix(self, peaks: tuple[Peak, ...]): if not isinstance(self.sample, Xtal): raise ValueError("sample needs to be Xtal class for UB calculation.") - match (num_of_peaks := len(peaks)): + match num_of_peaks := len(peaks): case 2: ubconf = self._find_u_from_two_peaks(peaks) self.sample.set_orientation(ubconf) @@ -261,7 +261,7 @@ def calculate_motor_angles(self, peak: tuple, ei: float, ef: Optional[float] = N two_theta = get_angle_from_triangle(ki, kf, q_norm) if two_theta is None: - print(f"Triangle cannot be closed at q={hkl}, en={ei-ef} meV.") + print(f"Triangle cannot be closed at q={hkl}, en={ei - ef} meV.") return None if np.rad2deg(two_theta) < S2_MIN_DEG: print(f"s2 is smaller than {S2_MIN_DEG} deg at q={hkl}.") diff --git a/src/tavi/plotter.py b/src/tavi/plotter.py index eaedbeab..c1c066d9 100644 --- a/src/tavi/plotter.py +++ b/src/tavi/plotter.py @@ -12,18 +12,14 @@ class FitData1D(object): - def __init__(self, x: np.ndarray, y: np.ndarray) -> None: - self.x = x self.y = y self.fmt: dict = {} class ResoBar(object): - def __init__(self, pos: tuple[float, float], fwhm: float) -> None: - self.pos = pos self.fwhm = fwhm self.fmt: dict = {} @@ -167,7 +163,6 @@ def plot(self, ax): class Plot2D(object): - def __init__(self) -> None: # self.ax = None self.contour_data: list[ScanData2D] = [] @@ -186,19 +181,16 @@ def __init__(self) -> None: self.LOG_Z = False def add_contour(self, contour_data: ScanData2D, **kwargs): - for key, val in kwargs.items(): contour_data.fmt.update({key: val}) self.contour_data.append(contour_data) def add_curve(self, curve_data: ScanData1D, **kwargs): - for key, val in kwargs.items(): curve_data.fmt.update({key: val}) self.curve_data.append(curve_data) def add_reso(self, reso_data: ResoEllipse, **kwargs): - if reso_data is not None: for key, val in kwargs.items(): reso_data.fmt.update({key: val}) diff --git a/tests/test_fit.py b/tests/test_fit.py index ba0b8200..a79a98a1 100644 --- a/tests/test_fit.py +++ b/tests/test_fit.py @@ -20,7 +20,6 @@ def fit_data(): def test_fit_single_peak_external_model(fit_data): - s1_scan, PLOT = fit_data f1 = Fit1D(s1_scan, fit_range=(0.5, 4.0)) @@ -86,7 +85,6 @@ def test_guess_initial(fit_data): def test_fit_single_peak_internal_model(fit_data): - s1_scan, PLOT = fit_data f1 = Fit1D(s1_scan, fit_range=(0.5, 4.0)) @@ -109,7 +107,6 @@ def test_fit_single_peak_internal_model(fit_data): def test_fit_two_peak(fit_data): - s1_scan, PLOT = fit_data f1 = Fit1D(s1_scan, fit_range=(0.0, 4.0), name="scan42_fit2peaks") diff --git a/tests/test_nexus_entry.py b/tests/test_nexus_entry.py index 664bd511..6d20e7a3 100644 --- a/tests/test_nexus_entry.py +++ b/tests/test_nexus_entry.py @@ -144,7 +144,6 @@ def test_get_from_daslogs(): def test_spice_to_nexus_one(): - path_to_spice_folder = "./test_data/exp424" path_to_nexus = "./test_data/spice_to_nxdict_test_scan0034.h5" scan0034 = NexusEntry.from_spice(path_to_spice_folder, 34) @@ -157,7 +156,6 @@ def test_spice_to_nexus_one(): def test_spice_to_nexus_empty(): - path_to_spice_folder = "./test_data/exp815" path_to_nexus = "./test_data/spice_to_nxdict_test_empty.h5" scan0002 = NexusEntry.from_spice(path_to_spice_folder, 2) @@ -191,7 +189,6 @@ def test_get_dataset_names(): @pytest.fixture def nexus_entries(): - analyser = { "attrs": {"EX_required": "true", "NX_class": "NXcrystal", "type": "NX_CHAR"}, "a1": { diff --git a/tests/test_plotter.py b/tests/test_plotter.py index 24ac2dfd..9a4cb9c5 100644 --- a/tests/test_plotter.py +++ b/tests/test_plotter.py @@ -11,7 +11,6 @@ def test_plot2d(): - # load data tavi = TAVI("./test_data/tavi_exp424.h5") scan_list = list(range(42, 49, 1)) + list(range(70, 76, 1)) diff --git a/tests/test_scan.py b/tests/test_scan.py index 4e49a93a..1e5aac90 100644 --- a/tests/test_scan.py +++ b/tests/test_scan.py @@ -53,7 +53,6 @@ def test_scan_from_nexus(): def test_get_scan_data(): - path_to_spice_folder = "./test_data/exp424" scan = Scan.from_spice(path_to_spice_folder, scan_num=42) diff --git a/tests/test_tavi_data.py b/tests/test_tavi_data.py index 5b017fab..9b6177ae 100644 --- a/tests/test_tavi_data.py +++ b/tests/test_tavi_data.py @@ -79,7 +79,6 @@ def tavi_exp0424(): def test_get_scan(tavi_exp0424): - scan0034 = tavi_exp0424.get_scan(scan_num=("IPTS32124_CG4C_exp0424", 34)) assert scan0034.name == "scan0034" assert scan0034.scan_info.scan_num == 34