diff --git a/.DS_Store b/.DS_Store index 43cbe8d5..79f7a158 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/scripts/HoV6Sn6_contour.py b/scripts/HoV6Sn6_contour.py index de8d270f..6cb8261e 100644 --- a/scripts/HoV6Sn6_contour.py +++ b/scripts/HoV6Sn6_contour.py @@ -1,8 +1,8 @@ import matplotlib.pyplot as plt -from tavi.data.plotter import Plot2DManager from tavi.data.scan_old.spice_to_nexus import convert_spice_to_nexus from tavi.data.tavi import TAVI +from tavi.plotter import Plot2DManager spice_folder = "./test_data/exp1031/" nexus_file_name = "./test_data/nexus_exp1031.h5" diff --git a/scripts/MnTe_contour.py b/scripts/MnTe_contour.py index c01330ce..ecdb65b6 100644 --- a/scripts/MnTe_contour.py +++ b/scripts/MnTe_contour.py @@ -1,148 +1,75 @@ -import matplotlib.pylab as plt +import matplotlib.pyplot as plt -from tavi.data.plotter import Plot2DManager -from tavi.data.scan_old.spice_to_nexus import convert_spice_to_nexus from tavi.data.tavi import TAVI -from tavi.instrument.resolution.cooper_nathans import CN -from tavi.sample.xtal import Xtal - -spice_folder = "./test_data/exp813" -nexus_folder = "./test_data/IPTS34735_HB3_exp0813" -if False: - convert_spice_to_nexus(spice_folder, nexus_folder) +from tavi.plotter import Plot2D tavi = TAVI() -tavi_file_name = "./test_data/tavi_test_exp0813.h5" -tavi.new(tavi_file_name) -tavi.load_nexus_data_from_disk(nexus_folder) -dataset = tavi.data["IPTS34735_HB3_exp0813"] +# load two experiments from SPICE the first time +if False: + tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp813/") + tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp823/") + tavi.save("./test_data/tavi_MnTe.h5") + +tavi.open_file("./test_data/tavi_MnTe.h5") # -------------- H0L const Q scans ------------ -scan_nums = [37, 39, 40] + list(range(44, 64)) + list(range(65, 69)) + list(range(84, 97)) -scan_list1 = [dataset[f"scan{i:04}"] for i in scan_nums] -sg1 = tavi.generate_scan_group( - signals=scan_list1, - signal_axes=("qh", "en", "detector"), -) -contour1 = sg1.generate_contour(rebin_steps=(0.025, 0.25), norm_channel="mcu", norm_val=1) - -plt2d1 = Plot2DManager() -plt2d1.zlim = [0, 0.5] -plt2d1.ylim = [0, 55] -plt2d1.title = "" -plt2d1.plot_contour(*contour1) -# --------------------------------------------------------- -# resolution calculation -# --------------------------------------------------------- -R0 = False -hb3 = CN() -instrument_config_json_path = "./src/tavi/instrument/instrument_params/hb3_mnte.json" -hb3.load_instrument_params_from_json(instrument_config_json_path) -sample_json_path = "./test_data/test_samples/mnte.json" -mnte = Xtal.from_json(sample_json_path) -hb3.mount_sample(mnte) - -# ----------------------------------------------- -# generate rez plot for point (1.3, 0, 1.3) -# ----------------------------------------------- -rez_q = hb3.cooper_nathans( - ei=35 + 14.7, - ef=14.7, - hkl=(1.3, 0, 1.3), - projection=None, - R0=R0, -) -rez_q.plot() -print(rez_q.mat) -# ------------------------------------- -rez_hkl = hb3.cooper_nathans( - ei=35 + 14.7, - ef=14.7, - hkl=(1.3, 0, 1.3), - R0=R0, -) -rez_hkl.plot() -print(rez_hkl.mat) -# -------------------------------------- -projection = ((1, 0, 1), (-1, 2, 0), (-0.2776, 0, 0.9607)) - -rez = hb3.cooper_nathans( - ei=35 + 14.7, - ef=14.7, - hkl=(1.3, 0, 1.3), - projection=projection, - R0=R0, +# scan_list1 = [37, 39, 40] + list(range(44, 64)) + list(range(65, 69)) + list(range(84, 97)) +# sg1 = tavi.combine_scans(scan_list1, name="dispH") + + +# scan_data_2d = sg1.get_data( +# axes=("qh", "en", "detector"), +# norm_to=(1, "mcu"), +# grid=(0.025, 0.3), +# ) + +# p1 = Plot2D() +# p1.add_contour(scan_data_2d, cmap="turbo", vmax=1) +# p1.zlim = [0, 0.5] +# p1.ylim = [0, 50] +# fig, ax = plt.subplots() +# p1.plot(ax) + + +# -------------- (H, 0. 2-H) Ef = 14.7 const Q scans ------------ + +scans = list(range(88, 133)) + +scan_list2 = [("IPTS34735_HB3_exp0823", scan) for scan in scans] +sg2 = tavi.combine_scans(scan_list2, name="dispH (H,0,2-H) Ef=14.7 meV") +scan_data_2 = sg2.get_data( + axes=("qh", "en", "detector"), + norm_to=(1, "mcu"), + grid=(0.025, 0.5), ) -rez.plot() -# ----------------------------------------------- -# generate 2D rez plot -# ----------------------------------------------- -# projection = ((1, 0, 1), (-1, 2, 0), (-1, 0, 1)) -projection = ((1, 0, 1), (-1, 2, 0), (-0.2776, 0, 0.9607)) -q1 = [1, 1.5, 0.1] # start, stop, step -q2 = 0 -q3 = 0 -en = [-1, 45, 5] # start, stop, step -ef = 14.7 +p2 = Plot2D() +p2.add_contour(scan_data_2, cmap="turbo", vmin=0, vmax=1) +p2.title = sg2.name +p2.ylim = [0, 50] +fig, ax = plt.subplots() +im = p2.plot(ax) +fig.colorbar(im) -plt2d1.rez_plot(hb3, projection, q1, q2, q3, en, ef, R0) +# -------------- (H, 0. 2-H) Ef = 30.5 meV const Q scans ------------ -plt.show() +scans = list(range(133, 167)) -# ----------------- -# s1 = dataset["scan0045"] -# # x, y, xerr, yerr, xlabel, ylabel, title, label -# curve1 = s1.generate_curve(norm_channel="mcu", norm_val=1) -# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve1 -# label += " H/L=1.15" -# curve1 = (x, y, xerr, yerr, xlabel, ylabel, title, label) - -# s2 = dataset["scan0046"] -# curve2 = s2.generate_curve(norm_channel="mcu", norm_val=1) -# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve2 -# label += " H/L=1.20" -# curve2 = (x, y, xerr, yerr, xlabel, ylabel, title, label) - -# ----------------- -# s1 = dataset["scan0049"] -# # x, y, xerr, yerr, xlabel, ylabel, title, label -# curve1 = s1.generate_curve(norm_channel="mcu", norm_val=1) -# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve1 -# label += " H/L=1.3" -# curve1 = (x, y, xerr, yerr, xlabel, ylabel, title, label) - -# s2 = dataset["scan0050"] -# curve2 = s2.generate_curve(norm_channel="mcu", norm_val=1) -# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve2 -# label += " H/L=1.3" -# curve2 = (x, y, xerr, yerr, xlabel, ylabel, title, label) - -# s3 = dataset["scan0051"] -# # x, y, xerr, yerr, xlabel, ylabel, title, label -# curve3 = s3.generate_curve(norm_channel="mcu", norm_val=1) -# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve3 -# label += " H/L=1.325" -# curve3 = (x, y, xerr, yerr, xlabel, ylabel, title, label) - -# s4 = dataset["scan0052"] -# curve4 = s4.generate_curve(norm_channel="mcu", norm_val=1) -# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve4 -# label += " H/L=1.325" -# curve4 = (x, y, xerr, yerr, xlabel, ylabel, title, label) - -# p1 = Plot1DManager() -# p1.plot_curve(*curve1) - -# p1.plot_curve(*curve3) -# p1.plot_curve(*curve2) -# p1.plot_curve(*curve4) - -# ----------------- -# s1 = dataset["scan0062"] -# # x, y, xerr, yerr, xlabel, ylabel, title, label -# curve1 = s1.generate_curve(norm_channel="mcu", norm_val=1) -# p1 = Plot1DManager() -# p1.plot_curve(*curve1) -# plt.show() +scan_list3 = [("IPTS34735_HB3_exp0823", scan) for scan in scans] +sg3 = tavi.combine_scans(scan_list3, name="dispH (H,0,2-H) Ef=30.5 meV") +scan_data_3 = sg3.get_data( + axes=("qh", "en", "detector"), + norm_to=(1, "mcu"), + grid=(0.025, 0.5), +) + +p3 = Plot2D() +p3.add_contour(scan_data_3, cmap="turbo", vmin=0, vmax=1) +p3.title = sg3.name +p3.ylim = [0, 50] + +fig, ax = plt.subplots() +im = p3.plot(ax) +fig.colorbar(im) +plt.show() diff --git a/scripts/MnTe_lines.py b/scripts/MnTe_lines.py new file mode 100644 index 00000000..77f86f53 --- /dev/null +++ b/scripts/MnTe_lines.py @@ -0,0 +1,32 @@ +import matplotlib.pyplot as plt + +from tavi.data.tavi import TAVI +from tavi.plotter import Plot1D + +tavi = TAVI() + +# load two experiments from SPICE the first time +if False: + tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp813/") + tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp823/") + tavi.save("./test_data/tavi_MnTe.h5") + +tavi.open_file("./test_data/tavi_MnTe.h5") + + +# overplot two curves with different Ei's +# 120,121, 145 +scan1 = [("IPTS34735_HB3_exp0823", scan) for scan in [120, 121]] +sg4 = tavi.combine_scans(scan1, name="Ef=14.7 meV") +l1 = sg4.get_data(norm_to=(1, "mcu")) + +scan2 = tavi.get_scan(("IPTS34735_HB3_exp0823", 145)) +l2 = scan2.get_data(norm_to=(1, "mcu")) + +p4 = Plot1D() +p4.add_scan(l1, fmt="o") +p4.add_scan(l2, fmt="s") +fig, ax = plt.subplots() +p4.plot(ax) + +plt.show() diff --git a/scripts/MnTe_new.py b/scripts/MnTe_new.py deleted file mode 100644 index dcb8f06f..00000000 --- a/scripts/MnTe_new.py +++ /dev/null @@ -1,75 +0,0 @@ -import matplotlib.pyplot as plt - -from tavi.data.plotter import Plot2D -from tavi.data.tavi import TAVI - -tavi = TAVI() - -# load two experiments from SPICE the first time -# tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp813/") -# tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp823/") -# tavi.save("./test_data/tavi_MnTe.h5") - -tavi.open_file("./test_data/tavi_MnTe.h5") - -# -------------- H0L const Q scans ------------ -# scan_list1 = [37, 39, 40] + list(range(44, 64)) + list(range(65, 69)) + list(range(84, 97)) -# sg1 = tavi.combine_scans(scan_list1, name="dispH") - - -# scan_data_2d = sg1.get_data( -# axes=("qh", "en", "detector"), -# norm_to=(1, "mcu"), -# grid=(0.025, 0.3), -# ) - -# p1 = Plot2D() -# p1.add_contour(scan_data_2d, cmap="turbo", vmax=1) -# p1.zlim = [0, 0.5] -# p1.ylim = [0, 50] -# fig, ax = plt.subplots() -# p1.plot(ax) - - -# -------------- (H, 0. 2-H) Ef = 14.7 const Q scans ------------ - -scans = list(range(88, 133)) - -scan_list2 = [("IPTS34735_HB3_exp0823", scan) for scan in scans] -sg2 = tavi.combine_scans(scan_list2, name="dispH (H,0,2-H) Ef=14.7 meV") -scan_data_2 = sg2.get_data( - axes=("qh", "en", "detector"), - norm_to=(1, "mcu"), - grid=(0.025, 0.5), -) - -p2 = Plot2D() -p2.add_contour(scan_data_2, cmap="turbo", vmin=0, vmax=1) -p2.title = sg2.name -p2.ylim = [0, 50] -fig, ax = plt.subplots() -im = p2.plot(ax) -fig.colorbar(im) - -# -------------- (H, 0. 2-H) Ef = 30.5 meV const Q scans ------------ - -scans = list(range(133, 167)) - -scan_list3 = [("IPTS34735_HB3_exp0823", scan) for scan in scans] -sg3 = tavi.combine_scans(scan_list3, name="dispH_ H,0,2-H) Ef=30.5 meV") -scan_data_3 = sg3.get_data( - axes=("qh", "en", "detector"), - norm_to=(1, "mcu"), - grid=(0.025, 0.5), -) - -p3 = Plot2D() -p3.add_contour(scan_data_3, cmap="turbo", vmin=0, vmax=1) -p3.title = sg3.name -p3.ylim = [0, 50] - -fig, ax = plt.subplots() -im = p3.plot(ax) - -fig.colorbar(im) -plt.show() diff --git a/scripts/rez_loader.jl b/scripts/rez_loader.jl new file mode 100644 index 00000000..32a22531 --- /dev/null +++ b/scripts/rez_loader.jl @@ -0,0 +1,9 @@ +using HDF5 +filename = "./test_data/tavi_rez.h5" +fid = h5open(filename, "r") +pdata = fid["processed_data"] +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 diff --git a/scripts/scans_rez.py b/scripts/scans_rez.py index e2f0d67d..8c0e7941 100644 --- a/scripts/scans_rez.py +++ b/scripts/scans_rez.py @@ -28,7 +28,7 @@ qk_list = scan.data["qk"] ql_list = scan.data["ql"] - projection = ((1, 1, 0), (0, 0, 1), (1, -1, 0)) + # projection = ((1, 1, 0), (0, 0, 1), (1, -1, 0)) R0 = True rez_mat_list = [] @@ -40,7 +40,7 @@ ei=ei_list[i], ef=ef_list[i], hkl=(qh_list[i], qk_list[i], ql_list[i]), - projection=projection, + # projection=projection, R0=R0, ) rez_mat_list.append(rez.mat) @@ -56,11 +56,11 @@ err=NXdataset(ds=scan_data.err), rez_mat=NXdataset(ds=rez_mat_list), rez_r0=NXdataset(ds=rez_r0_list), - projection=NXdataset(ds=projection), + # projection=NXdataset(ds=projection), ) tavi.processed_data.update(NexusEntry._dict_to_nexus_entry({scan.name: rez_entry})) -file_path = "./test_data/tavi_rez.h5" +file_path = "./test_data/tavi_rez_HKLE.h5" tavi.save(file_path) diff --git a/scripts/test_fit_group.py b/scripts/test_fit_group.py index 226b94c5..c5bd32d5 100644 --- a/scripts/test_fit_group.py +++ b/scripts/test_fit_group.py @@ -1,7 +1,7 @@ import matplotlib.pyplot as plt -from tavi.data.plotter import Plot1DManager, Plot2DManager from tavi.data.tavi import TAVI +from tavi.plotter import Plot1DManager, Plot2DManager def test_fit_group(tavi): diff --git a/scripts/test_plotter.py b/scripts/test_plotter.py index d03273b5..1c329cbf 100644 --- a/scripts/test_plotter.py +++ b/scripts/test_plotter.py @@ -1,8 +1,8 @@ import matplotlib.pylab as plt -from tavi.data.plotter import Plot1DManager, Plot2DManager from tavi.data.tavi import TAVI from tavi.instrument.resolution.cooper_nathans import CN +from tavi.plotter import Plot1DManager, Plot2DManager # from tavi.instrument.instrument_params.python_dicts.cg4c import cg4c_config_params # from tests.test_data_folder.test_samples.python_samples.nitio3 import nitio3 diff --git a/scripts/test_rez.py b/scripts/test_rez.py index e290603a..644279cb 100644 --- a/scripts/test_rez.py +++ b/scripts/test_rez.py @@ -2,8 +2,8 @@ # from tests.test_data_folder.test_samples.python_samples.sample_test import test_xtal import matplotlib.pylab as plt -from tavi.data.plotter import Plot1DManager, Plot2DManager from tavi.instrument.resolution.cooper_nathans import CN +from tavi.plotter import Plot1DManager, Plot2DManager def test_l_vs_en(tas): diff --git a/src/tavi/data/fit.py b/src/tavi/data/fit.py index 338e07de..37d1d30f 100644 --- a/src/tavi/data/fit.py +++ b/src/tavi/data/fit.py @@ -3,7 +3,7 @@ import numpy as np from lmfit import Parameters, models -from tavi.data.plotter import Plot1D +from tavi.plotter import Plot1D class Fit1D(object): diff --git a/src/tavi/data/scan.py b/src/tavi/data/scan.py index a07895f4..8e199238 100644 --- a/src/tavi/data/scan.py +++ b/src/tavi/data/scan.py @@ -6,8 +6,8 @@ import numpy as np from tavi.data.nxentry import NexusEntry -from tavi.data.plotter import Plot1D from tavi.data.scan_data import ScanData1D +from tavi.plotter import Plot1D from tavi.sample.xtal import Xtal from tavi.utilities import spice_to_mantid diff --git a/src/tavi/instrument/resolution/ellipsoid.py b/src/tavi/instrument/resolution/ellipsoid.py index 4cc78be8..baa7576e 100755 --- a/src/tavi/instrument/resolution/ellipsoid.py +++ b/src/tavi/instrument/resolution/ellipsoid.py @@ -34,7 +34,7 @@ class ResoEllipsoid(object): """ - EPS = 1e-8 + ZERO = 1e-8 def __init__( self, @@ -60,7 +60,8 @@ def __init__( case None: # Local Q frame self.frame = "q" self.angles = (90.0, 90.0, 90.0) - self.q = (np.linalg.norm(sample.b_mat @ hkl) * 2 * np.pi, 0.0, 0.0) + q_norm = np.linalg.norm(sample.b_mat @ hkl) * 2 * np.pi + self.q = (q_norm, 0.0, 0.0) case ((1, 0, 0), (0, 1, 0), (0, 0, 1)): # HKL self.frame = "hkl" @@ -73,9 +74,9 @@ def __init__( v2 = np.sum([p2[i] * vec for (i, vec) in enumerate(reciprocal_vecs)], axis=0) v3 = np.sum([p3[i] * vec for (i, vec) in enumerate(reciprocal_vecs)], axis=0) - if np.dot(v1, np.cross(v2, v3)) < ResoEllipsoid.EPS: + if np.dot(v1, np.cross(v2, v3)) < ResoEllipsoid.ZERO: raise ValueError("Projection is left handed! Please use right-handed projection") - if np.abs(np.dot(v1, np.cross(v2, v3))) < ResoEllipsoid.EPS: + if np.abs(np.dot(v1, np.cross(v2, v3))) < ResoEllipsoid.ZERO: raise ValueError("Projection vectors need to be non-coplanar.") mat_w_inv = np.array([np.cross(p2, p3), np.cross(p3, p1), np.cross(p1, p2)]) / np.dot( @@ -170,7 +171,7 @@ def incoh_fwhms(self, axis=None): def quadric_proj(quadric, idx): """projects along one axis of the quadric""" - if np.abs(quadric[idx, idx]) < ResoEllipsoid.EPS: + if np.abs(quadric[idx, idx]) < ResoEllipsoid.ZERO: return np.delete(np.delete(quadric, idx, axis=0), idx, axis=1) # row/column along which to perform the orthogonal projection diff --git a/src/tavi/data/plotter.py b/src/tavi/plotter.py similarity index 100% rename from src/tavi/data/plotter.py rename to src/tavi/plotter.py diff --git a/src/tavi/data/plotter_backup.py b/src/tavi/plotter_backup.py similarity index 100% rename from src/tavi/data/plotter_backup.py rename to src/tavi/plotter_backup.py diff --git a/test_data/tavi_rez.h5 b/test_data/tavi_rez.h5 deleted file mode 100644 index 8822585b..00000000 Binary files a/test_data/tavi_rez.h5 and /dev/null differ diff --git a/tests/test_scan_group.py b/tests/test_scan_group.py index c29ead19..9cd042a6 100644 --- a/tests/test_scan_group.py +++ b/tests/test_scan_group.py @@ -2,8 +2,8 @@ import matplotlib.pyplot as plt -from tavi.data.plotter import Plot1D, Plot2D from tavi.data.tavi import TAVI +from tavi.plotter import Plot1D, Plot2D def test_scan_group_default_1d():