generated from neutrons/python_project_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
719 changed files
with
173,369 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
|
||
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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import numpy as np | ||
import matplotlib.pylab as plt | ||
from tavi.instrument.resolution.cooper_nathans import CN | ||
|
||
# from tavi.instrument.instrument_params.python_dicts.takin_test import instrument_params | ||
# from test_data_folder.test_samples.python_samples.sample_test import test_xtal | ||
|
||
# from tavi.instrument.instrument_params.python_dicts.cg4c import cg4c_config_params | ||
# from tests.test_data_folder.test_samples.python_samples.nitio3 import nitio3 | ||
|
||
np.set_printoptions(floatmode="fixed", precision=4) | ||
|
||
|
||
def test_copper_nathans_localQ(tas_params): | ||
|
||
tas, ei, ef, hkl, _, R0 = tas_params | ||
|
||
rez = tas.cooper_nathans( | ||
ei=ei, | ||
ef=ef, | ||
hkl=hkl, | ||
projection=None, | ||
R0=R0, | ||
) | ||
print(rez.mat) | ||
print(rez.r0) | ||
|
||
# describe and plot ellipses | ||
# rez.calc_ellipses() | ||
rez.plot() | ||
|
||
|
||
def test_copper_nathans_hkl(tas_params): | ||
|
||
tas, ei, ef, hkl, _, R0 = tas_params | ||
|
||
rez = tas.cooper_nathans( | ||
ei=ei, | ||
ef=ef, | ||
hkl=hkl, | ||
R0=R0, | ||
) | ||
print(rez.mat) | ||
|
||
# describe and plot ellipses | ||
# rez.calc_ellipses() | ||
rez.plot() | ||
|
||
|
||
def test_copper_nathans_projection(tas_params): | ||
|
||
tas, ei, ef, hkl, projection, R0 = tas_params | ||
|
||
rez = tas.cooper_nathans( | ||
ei=ei, | ||
ef=ef, | ||
hkl=hkl, | ||
projection=projection, | ||
R0=R0, | ||
) | ||
print(rez.mat) | ||
|
||
# describe and plot ellipses | ||
# rez.calc_ellipses() | ||
rez.plot() | ||
|
||
|
||
def test_cooper_nathans_compare_3(): | ||
|
||
tas = CN() | ||
|
||
instrument_config_json_path = "./src/tavi/instrument/instrument_params/takin_test.json" | ||
sample_json_path = "./tests/test_data_folder/test_samples/test_xtal.json" | ||
|
||
tas.load_instrument_from_json(instrument_config_json_path) | ||
tas.load_sample_from_json(sample_json_path) | ||
|
||
# tas.load_instrument_from_(instrument_params) | ||
# tas.load_sample(test_xtal) | ||
|
||
if tas.sample.ub_matrix is None: | ||
peak_list = [(0, 0, 2), (0, 2, 0)] | ||
angles_list = [ | ||
(-51.530388, -45.220125, -0.000500, -2.501000), | ||
(-105.358735, 17.790125, -0.000500, -2.501000), | ||
] | ||
tas.find_ub(peaks=peak_list, angles=angles_list, ei=13.500172, ef=13.505137) | ||
|
||
ei = 13.5 | ||
ef = 13.5 | ||
hkl = (0, 0, 2) | ||
# projection = ((1, 0, 0), (-1, 2, 0), (0, 0, 1)) | ||
projection = ((0, 0, 1), (0, -1, 0), (2, -1, 0)) | ||
R0 = False | ||
|
||
tas_params = (tas, ei, ef, hkl, projection, R0) | ||
|
||
test_copper_nathans_localQ(tas_params) | ||
test_copper_nathans_hkl(tas_params) | ||
test_copper_nathans_projection(tas_params) | ||
|
||
plt.show() | ||
|
||
|
||
def test_cooper_nathans_CTAX(): | ||
|
||
tas = CN() | ||
|
||
instrument_config_json_path = "./src/tavi/instrument/instrument_params/cg4c.json" | ||
sample_json_path = "./tests/test_data_folder/test_samples/nitio3.json" | ||
|
||
tas.load_instrument_from_json(instrument_config_json_path) | ||
tas.load_sample_from_json(sample_json_path) | ||
|
||
# tas.load_instrument_from_dicts(cg4c_config_params) | ||
# tas.load_sample(nitio3) | ||
print(f"u={tas.sample.u}") | ||
print(f"v={tas.sample.v}") | ||
|
||
# reset UB | ||
# tas.sample.ub_matrix = tas.sample.uv_to_ub_matrix(u=[1, 1, 0], v=[0, 0, 1]) | ||
# print(f"u={tas.sample.u}") | ||
# print(f"v={tas.sample.v}") | ||
|
||
ei = 4.8 | ||
ef = 4.8 | ||
hkl = (0, 0, 3) | ||
|
||
projection = ((1, 1, 0), (0, 0, 1), (1, -1, 0)) | ||
R0 = True | ||
|
||
tas_params = (tas, ei, ef, hkl, projection, R0) | ||
|
||
test_copper_nathans_localQ(tas_params) | ||
test_copper_nathans_hkl(tas_params) | ||
test_copper_nathans_projection(tas_params) | ||
|
||
plt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
# test_cooper_nathans_compare_3() | ||
|
||
test_cooper_nathans_CTAX() |
Oops, something went wrong.