Skip to content

Commit

Permalink
updated test data
Browse files Browse the repository at this point in the history
  • Loading branch information
bingli621 committed Aug 13, 2024
1 parent d2fda83 commit d5cb0ec
Show file tree
Hide file tree
Showing 43 changed files with 8,490 additions and 97 deletions.
Binary file modified .DS_Store
Binary file not shown.
60 changes: 53 additions & 7 deletions scripts/HoV6Sn6_contour.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import matplotlib.pyplot as plt
from tavi.data.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"
convert_spice_to_nexus(spice_folder, nexus_file_name)

tavi = TAVI()

Expand All @@ -8,17 +14,57 @@

nexus_file_name = "./test_data/nexus_exp1031.h5"
tavi.load_nexus_data_from_disk(nexus_file_name)
dataset = tavi.data["IPTS32912_HB1A_exp1031"]

# -------------- 001 s1 scans ------------
scan_list1 = [dataset[f"scan{i:04}"] for i in range(90, 121, 5)] + [dataset[f"scan{i:04}"] for i in range(127, 145, 5)]
sg1 = tavi.generate_scan_group(
signals=scan_list1,
signal_axes=("persistent_field", "s1", "detector"),
)
# contour1 = sg1.generate_contour(rebin_steps=(None, 0.001), norm_channel="mcu", norm_val=1)
contour1 = sg1.generate_contour(rebin_steps=(None, None), norm_channel="mcu", norm_val=1)
# sg1.plot_contour(contour1, cmap="turbo", vmax=2e2, vmin=0)

dataset = tavi.data["IPTS32912_HB1A_exp1031"]
plt2d1 = Plot2DManager()
plt2d1.zlim = [0, 5e2]
plt2d1.title = "(0,0,1)"
plt2d1.plot_contour(*contour1)


# -------------- 005 s1 scans ----------
scan_list2 = [dataset[f"scan{i:04}"] for i in range(91, 122, 5)] + [dataset[f"scan{i:04}"] for i in range(128, 144, 5)]
sg2 = tavi.generate_scan_group(signals=scan_list2, signal_axes=("persistent_field", "s1", "detector"))
contour2 = sg2.generate_contour(rebin_steps=(None, None), norm_channel="mcu", norm_val=1)
# sg2.plot_contour(contour1, cmap="turbo", vmax=5e1, vmin=0)

plt2d2 = Plot2DManager()
plt2d2.zlim = [0, 5e1]
plt2d2.title = "(0,0,5)"
plt2d2.plot_contour(*contour2)


# -------------- 100 s1 scans ----------
scan_list3 = [dataset[f"scan{i:04}"] for i in range(93, 124, 5)] + [dataset[f"scan{i:04}"] for i in range(130, 145, 5)]
sg3 = tavi.generate_scan_group(signals=scan_list3, signal_axes=("persistent_field", "s1", "detector"))
contour3 = sg3.generate_contour(rebin_steps=(None, None), norm_channel="mcu", norm_val=1)
# sg2.plot_contour(contour1, cmap="turbo", vmax=5e1, vmin=0)

plt2d3 = Plot2DManager()
plt2d3.zlim = [0, 8e2]
plt2d3.title = "(1,0,0)"
plt2d3.plot_contour(*contour3)

print(len(dataset))
# 001 s1 scans
scan_list = [dataset[f"scan{i:04}"] for i in range(90, 121, 5)]
# -------------- 200 s1 scans ----------
scan_list4 = [dataset[f"scan{i:04}"] for i in range(94, 125, 5)] + [dataset[f"scan{i:04}"] for i in range(131, 145, 5)]
sg4 = tavi.generate_scan_group(signals=scan_list4, signal_axes=("persistent_field", "s1", "detector"))
contour4 = sg4.generate_contour(rebin_steps=(None, None), norm_channel="mcu", norm_val=1)
# sg2.plot_contour(contour1, cmap="turbo", vmax=5e1, vmin=0)

sg1 = tavi.generate_scan_group(signals=scan_list, signal_axes=("persistent_field", "s1", "detector"))
contour1 = sg1.generate_contour(rebin_steps=(None, None))
sg1.plot_contour(contour1, cmap="turbo")
plt2d4 = Plot2DManager()
plt2d4.zlim = [0, 2e2]
plt2d4.title = "(2,0,0)"
plt2d4.plot_contour(*contour4)


plt.show()
6 changes: 3 additions & 3 deletions scripts/test_data_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def test_open_tavi_file(tavi):
if __name__ == "__main__":
tavi = TAVI()
# test_conversion(424)
# test_conversion(710)
test_conversion(1031)
test_load_nexus_to_new_tavi(tavi)
test_conversion(710)
# test_conversion(1031)
# test_load_nexus_to_new_tavi(tavi)

# test_open_exsiting_tavi()
4 changes: 2 additions & 2 deletions scripts/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_fit_scan(tavi):
curve1 = s1.generate_curve(norm_channel="mcu", norm_val=30, rebin_type="grid", rebin_step=0.25)

x, y, xerr, yerr, xlabel, ylabel, title, label = curve1
f1 = Fit(x=x, y=y, fit_range=(0.0, 4))
f1 = Fit(x=x, y=y, err=yerr, fit_range=(0.0, 4))
f1.add_background(values=(0.7,))
f1.add_signal(
values=(None, 3.5, None),
Expand All @@ -28,7 +28,7 @@ def test_fit_scan(tavi):
f1.perform_fit()

p1.plot_curve(*curve1)
p1.plot_curve(f1.x_plot, f1.y_plot, fmt="-")
p1.plot_curve(f1.x_plot, f1.y_plot, fmt="-", xlabel=xlabel, ylabel=ylabel, title=title)

# s2 = tavi.data[datasets]["scan0043"]
# curve2 = s2.generate_curve(norm_channel="mcu", norm_val=30, rebin_type="grid", rebin_step=0.25)
Expand Down
52 changes: 52 additions & 0 deletions scripts/test_fit_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import matplotlib.pyplot as plt
from tavi.data.tavi import TAVI
from tavi.plotter import Plot1DManager, Plot2DManager


def test_fit_group(tavi):
scan_list1 = [dataset[f"scan{i:04}"] for i in range(90, 121, 5)] + [
dataset[f"scan{i:04}"] for i in range(127, 128, 5)
]
sg1 = tavi.generate_scan_group(signals=scan_list1, signal_axes=("persistent_field", "s1", "detector"))

# --------------- plot contour ---------------
contour1 = sg1.generate_contour(rebin_steps=(None, None), norm_channel="mcu", norm_val=1)
plt2d1 = Plot2DManager()
plt2d1.zlim = [0, 5e2]
plt2d1.title = "(0,0,1)"
plt2d1.plot_contour(*contour1)

# x, y, xerr, yerr, xlabel, ylabel, title, label = curve1
# f1 = Fit(x=x, y=y, fit_range=(0.0, 4))
# f1.add_background(values=(0.7,))
# f1.add_signal(
# values=(None, 3.5, None),
# vary=(True, True, True),
# )
# f1.add_signal(
# model="Gaussian",
# values=(None, 0, None),
# vary=(True, False, True),
# mins=(0, 0, 0.1),
# maxs=(None, 0.1, 0.3),
# )
# f1.perform_fit()

p1 = Plot1DManager()
# p1.plot_curve(*curve1)
# p1.plot_curve(f1.x_plot, f1.y_plot, fmt="-")


if __name__ == "__main__":
tavi = TAVI()

tavi_file_name = "./test_data/tavi_test_exp1031.h5"
tavi.new_tavi_file(tavi_file_name)

nexus_file_name = "./test_data/nexus_exp1031.h5"
tavi.load_nexus_data_from_disk(nexus_file_name)
dataset = tavi.data["IPTS32912_HB1A_exp1031"]

test_fit_group(tavi)

plt.show()
30 changes: 21 additions & 9 deletions src/tavi/data/nexus_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def dataset_to_string(ds):
num = np.size(nexus_entry["data/" + scan_info["def_x"]])

data = {
# "Pt.": nexus_entry["sample/Pt."][...],
"Pt.": np.arange(start=1, stop=num + 1, step=1),
# detector
"detector": nexus_entry["instrument/detector/data"][...],
Expand Down Expand Up @@ -100,20 +101,31 @@ def dataset_to_string(ds):

# temprature
temperatue_str = (
"coldtip",
"tsample",
"temp_a",
"temp_2",
"vti",
"sample",
"temp",
"dr_tsample",
"dr_temp",
(
"temp",
"temp_a",
"temp_2",
"coldtip",
"tsample",
"sample",
)
+ (
"vti",
"dr_tsample",
"dr_temp",
)
+ ("lt", "ht", "sorb_temp", "sorb", "sample_ht")
)
for t in nexus_entry["sample"].keys():
if t in temperatue_str:
data.update({t: nexus_entry["sample/" + t][...]})

# field
field_str = ("persistent_field",)
for f in nexus_entry["sample"].keys():
if f in field_str:
data.update({f: nexus_entry["sample/" + f][...]})

return scan_info, sample_ub_info, instrument_info, data


Expand Down
14 changes: 8 additions & 6 deletions src/tavi/data/scan_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ def generate_contour(
# TODO problem if irregular size
x_step, y_step = rebin_steps
if x_step is None:
x_unique = np.unique(np.concatenate([np.unique(np.round(x, 1)) for x in x_array]))
x_diff = np.unique(np.round(np.diff(x_unique), 1))
x_precision = 1
x_unique = np.unique(np.concatenate([np.unique(np.round(x, x_precision)) for x in x_array]))
x_diff = np.unique(np.round(np.diff(x_unique), x_precision))
x_diff = x_diff[x_diff > 0]
x_step = x_diff[0]

if y_step is None:
y_unique = np.unique(np.concatenate([np.unique(np.round(y, 1)) for y in y_array]))
y_diff = np.unique(np.round(np.diff(y_unique), 1))
y_precision = 5
y_unique = np.unique(np.concatenate([np.unique(np.round(y, y_precision)) for y in y_array]))
y_diff = np.unique(np.round(np.diff(y_unique), y_precision))
y_diff = y_diff[y_diff > 0]
y_step = y_diff[0]

Expand Down Expand Up @@ -124,13 +126,13 @@ def generate_contour(

return (xv, yv, z, x_step, y_step, xlabel, ylabel, zlabel, title)

def plot_contour(self, contour_plot, cmap="turbo", vmax=100, ylim=None, xlim=None):
def plot_contour(self, contour_plot, cmap="turbo", vmax=100, vmin=0, ylim=None, xlim=None):
"""Plot contour"""

x, y, z, _, _, xlabel, ylabel, zlabel, title = contour_plot

fig, ax = plt.subplots()
p = ax.pcolormesh(x, y, z, shading="auto", cmap=cmap, vmax=vmax)
p = ax.pcolormesh(x, y, z, shading="auto", cmap=cmap, vmax=vmax, vmin=vmin)
fig.colorbar(p, ax=ax)
ax.set_title(title)
ax.set_xlabel(xlabel)
Expand Down
25 changes: 19 additions & 6 deletions src/tavi/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Plot1DManager(object):

def __init__(self) -> None:
_, self.ax = plt.subplots()
self.title = None
self.title = ""
self.xlim = None
self.ylim = None
self.xlabel = None
Expand Down Expand Up @@ -44,7 +44,18 @@ def rez_plot_1D(self, tas, projection, hkl, en, ef, R0, axis):
self.set_labels()
return rez

def plot_curve(self, x, y, xerr=None, yerr=None, xlabel=None, ylabel=None, title=None, label=None, fmt="o"):
def plot_curve(
self,
x,
y,
xerr=None,
yerr=None,
xlabel=None,
ylabel=None,
title=None,
label=None,
fmt="o",
):
if title is not None:
self.title = title
if xlabel is not None:
Expand All @@ -61,10 +72,11 @@ class Plot2DManager(object):
"""Manage a plot"""

def __init__(self, grid_helper=None) -> None:
self.fig = plt.figure(figsize=(10, 6))
# self.fig = plt.figure(figsize=(10, 6))
self.fig = plt.figure()
self.ax = self.fig.add_subplot(111, axes_class=Axes, grid_helper=grid_helper)

self.title = None
self.title = ""
self.xlim = None
self.ylim = None
self.zlim = None
Expand All @@ -84,7 +96,8 @@ def set_labels(self):
self.ax.set_xlabel(self.xlabel)
self.ax.set_ylabel(self.ylabel)
self.ax.grid(alpha=0.6)
self.ax.legend()

# self.ax.legend()

def plot_contour(
self,
Expand All @@ -104,7 +117,7 @@ def plot_contour(
self.xlabel = xlabel
self.ylabel = ylabel
self.zlabel = zlabel
self.title = title
self.title += title

p = self.ax.pcolormesh(
x,
Expand Down
Binary file modified test_data/.DS_Store
Binary file not shown.
Binary file removed test_data/exp1031/.DS_Store
Binary file not shown.
Loading

0 comments on commit d5cb0ec

Please sign in to comment.