diff --git a/scripts/HoV6Sn6_contour.py b/scripts/HoV6Sn6_contour.py index 64c746d..530a114 100644 --- a/scripts/HoV6Sn6_contour.py +++ b/scripts/HoV6Sn6_contour.py @@ -14,7 +14,7 @@ tavi.new_file(tavi_file_name) nexus_file_name = "./test_data/nexus_exp1031.h5" -tavi.get_nexus_data_from_disk(nexus_file_name) +tavi.load_nexus_data_from_disk(nexus_file_name) dataset = tavi.data["IPTS32912_HB1A_exp1031"] # -------------- 001 s1 scans ------------ diff --git a/scripts/MnTe_contour.py b/scripts/MnTe_contour.py index dd96a00..e1bfea8 100644 --- a/scripts/MnTe_contour.py +++ b/scripts/MnTe_contour.py @@ -15,7 +15,7 @@ tavi_file_name = "./test_data/tavi_test_exp0813.h5" tavi.new_file(tavi_file_name) -tavi.get_nexus_data_from_disk(nexus_folder) +tavi.load_nexus_data_from_disk(nexus_folder) dataset = tavi.data["IPTS34735_HB3_exp0813"] # -------------- H0L const Q scans ------------ diff --git a/scripts/test_fit_group.py b/scripts/test_fit_group.py index 09befe4..2146a83 100644 --- a/scripts/test_fit_group.py +++ b/scripts/test_fit_group.py @@ -45,7 +45,7 @@ def test_fit_group(tavi): tavi.new_file(tavi_file_name) nexus_file_name = "./test_data/nexus_exp1031.h5" - tavi.get_nexus_data_from_disk(nexus_file_name) + tavi.load_nexus_data_from_disk(nexus_file_name) dataset = tavi.data["IPTS32912_HB1A_exp1031"] test_fit_group(tavi) diff --git a/scripts/test_scan.py b/scripts/test_scan.py index e89020a..39c9ee5 100644 --- a/scripts/test_scan.py +++ b/scripts/test_scan.py @@ -25,7 +25,7 @@ def test_scan_group_contour_exp710(): tavi.new_file(tavi_file_name) nexus_file_name = "./tests/test_data_folder/nexus_exp710.h5" - tavi.get_nexus_data_from_disk(nexus_file_name) + tavi.load_nexus_data_from_disk(nexus_file_name) scan_list = ( [tavi.data[f"scan{i:04}"] for i in range(214, 225, 1)] diff --git a/src/tavi/data/fit.py b/src/tavi/data/fit.py index 52c623c..338e07d 100644 --- a/src/tavi/data/fit.py +++ b/src/tavi/data/fit.py @@ -1,9 +1,16 @@ +from typing import Optional + import numpy as np from lmfit import Parameters, models +from tavi.data.plotter import Plot1D + + +class Fit1D(object): + """Fit a 1d curve -class Fit(object): - """Save information about fits""" + Attributes: + NUM_PTS (int): number of points for the fit curve""" models = { # ---------- peak models --------------- @@ -25,47 +32,35 @@ class Fit(object): "Spline": models.SplineModel, } - def __init__(self, x, y, err=None, fit_range=None): - """ - initialize a fit model + def __init__(self, plot1d: Plot1D): + """initialize a fit model""" + self.NUM_PTS: int = 100 + self.x = plot1d.x + self.y = plot1d.y + self.yerr = plot1d.yerr - Args: - x (list) - y (list) - err (list | None) - fit_range (tuple) - NUM_PTS (int): number of points for the fit curve - """ - self.NUM_PTS = 100 - self.range = fit_range - self.x = np.array(x) - self.y = np.array(y) - self.err = err - - # trim the range - if fit_range is not None: - fit_min, fit_max = fit_range - mask = np.bitwise_and(x >= fit_min, x <= fit_max) - self.x = self.x[mask] - self.y = self.y[mask] - if self.err is not None: - self.err = self.err[mask] - - self.x_plot = np.linspace( - self.x.min(), - self.x.max(), - num=self.NUM_PTS, - ) - self.y_plot = None - - self.background_models = [] - self.signal_models = [] + self.background_models: models = [] + self.signal_models: models = [] self.pars = Parameters() self.num_backgrounds = 0 self.num_signals = 0 self.fit_result = None self.PLOT_SEPARATELY = False + self.fit_plot: Optional[Plot1D] = None + + def set_range(self, fit_min, fit_max): + """set the range used for fitting""" + + mask = np.bitwise_and(self.x >= fit_min, self.x <= fit_max) + self.x = self.x[mask] + self.y = self.y[mask] + if self.yerr is not None: + self.yerr = self.yerr[mask] + + @property + def x_plot(self): + return np.linspace(self.x.min(), self.x.max(), num=self.NUM_PTS) def add_background( self, @@ -94,7 +89,7 @@ def add_background( prefix = f"b{self.num_backgrounds}_" else: prefix = "" - model = Fit.models[model](prefix=prefix, nan_policy="propagate") + model = Fit1D.models[model](prefix=prefix, nan_policy="propagate") param_names = model.param_names # guess initials pars = model.guess(self.y, x=self.x) @@ -150,7 +145,7 @@ def add_signal( """ self.num_signals += 1 prefix = f"s{self.num_signals}_" - model = Fit.models[model](prefix=prefix, nan_policy="propagate") + model = Fit1D.models[model](prefix=prefix, nan_policy="propagate") param_names = model.param_names # guess initials pars = model.guess(self.y, x=self.x) @@ -184,19 +179,19 @@ def add_signal( self.pars.add(pars[param_name]) self.signal_models.append(model) - def perform_fit(self): + def perform_fit(self) -> None: model = np.sum(self.signal_models) if self.num_backgrounds > 0: model += np.sum(self.background_models) - if self.err is None: + if self.yerr is None: out = model.fit(self.y, self.pars, x=self.x) else: - out = model.fit(self.y, self.pars, x=self.x, weights=self.err) + out = model.fit(self.y, self.pars, x=self.x, weights=self.yerr) self.result = out self.y_plot = model.eval(out.params, x=self.x_plot) - fit_report = out.fit_report(min_correl=0.25) - return fit_report + self.fit_report = out.fit_report(min_correl=0.25) + self.fit_plot = Plot1D(x=self.x_plot, y=self.y_plot) diff --git a/src/tavi/data/tavi.py b/src/tavi/data/tavi.py index 2d437dc..00350f4 100644 --- a/src/tavi/data/tavi.py +++ b/src/tavi/data/tavi.py @@ -52,7 +52,7 @@ def new_file(self, file_path: Optional[str] = None) -> None: except OSError: print(f"Cannot create tavi file at {self.file_path}") - def get_nexus_data_from_disk(self, path_to_hdf5_folder): + def load_nexus_data_from_disk(self, path_to_hdf5_folder): """Copy hdf5 data from path_to_hdf5_folder into tavi.""" # validate path if path_to_hdf5_folder[-1] != "/": @@ -63,6 +63,7 @@ def get_nexus_data_from_disk(self, path_to_hdf5_folder): scan_list.sort() with h5py.File(self.file_path, "r+", track_order=True) as tavi_file: + scans = {} for scan in scan_list: scan_name = scan.split(".")[0] # e.g. "scan0001" scan_path = path_to_hdf5_folder + scan @@ -73,11 +74,13 @@ def get_nexus_data_from_disk(self, path_to_hdf5_folder): scan_file.copy( source=scan_file["/" + scan_name], dest=tavi_file["/data/" + dataset_name], expand_soft=True ) - - self.load_data() + nexus_entry = scan_file[scan_name] + _, scan_entry = Scan.from_nexus_entry(nexus_entry) + scans.update({scan_name: scan_entry}) + self.data.update({dataset_name: scans}) # TODO - def get_spice_data_from_disk(self, path_to_spice_folder): + def load_spice_data_from_disk(self, path_to_spice_folder): """Load hdf5 data from path_to_hdf5. Args: @@ -89,7 +92,7 @@ def get_spice_data_from_disk(self, path_to_spice_folder): self.load_data() # TODO - def get_data_from_oncat(self, user_credentials, ipts_info, OVERWRITE=True): + def load_data_from_oncat(self, user_credentials, ipts_info, OVERWRITE=True): """Load data from ONCat based on user_credentials and ipts_info. Args: @@ -100,8 +103,9 @@ def get_data_from_oncat(self, user_credentials, ipts_info, OVERWRITE=True): """ self.load_data() + # TODO load processed_data def load_data(self): - """Load tavi data into memory""" + """Load data, processed_data, fits and plots in a tavi file into memory""" with h5py.File(self.file_path, "r") as tavi_file: for dataset_name in (tavi_data := tavi_file["data"]): @@ -110,7 +114,6 @@ def load_data(self): nexus_entry = dataset[scan_name] _, scan_entry = Scan.from_nexus_entry(nexus_entry) scans.update({scan_name: scan_entry}) - self.data.update({dataset_name: scans}) def open_file(self, tavi_file_path): @@ -121,7 +124,6 @@ def open_file(self, tavi_file_path): # TODO load processed_data fits, and plots - # TODO def save_file(self, path_to_hdf5: Optional[str] = None): """Save current data to a hdf5 on disk at path_to_hdf5 @@ -131,37 +133,24 @@ def save_file(self, path_to_hdf5: Optional[str] = None): if path_to_hdf5 is not None: self.file_path = path_to_hdf5 - # TODO save processed_data fits and plots - - def delete_data_entry(self, entry_id): - """Delete a date entry from file based on entry_id. - - If an data entry if deleted, also delete the fits, scan_groups, plots - that contains the conresponding entry. - - Args: - entry_id (str): ID of entry to be deteled. - """ - pass - - def select_entries(self, conditions): - """Return a list of data entry IDs which satisfis the conditions. - - All data points in a scan have to satisfy all conditions. + try: # mode a: Read/write if exists, create otherwise + with h5py.File(self.file_path, "a", track_order=True) as tavi_file: + if "/data" not in tavi_file: + tavi_file.create_group("data", track_order=True) + pass - Args: - conditions (dict): scan[key] equals value - or in the range of (vaule[0], value[1]) - for example: {"IPTS":1234, "temperature":(2,5)} + if "/processed_data" not in tavi_file: + tavi_file.create_group("processed_data", track_order=True) - Returns: - tuple: entry IDs + # TODO save processed_data fits and plots + if "/fits" not in tavi_file: + tavi_file.create_group("fits", track_order=True) - """ - pass + if "/plots" not in tavi_file: + tavi_file.create_group("plots", track_order=True) - def get_selected(self): - return "scan0001" + except OSError: + print(f"Cannot create tavi file at {self.file_path}") def generate_scan_group( self, diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0001.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0001.h5 index 812d697..f0a2185 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0001.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0001.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0002.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0002.h5 index e64aa26..520bb51 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0002.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0002.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0003.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0003.h5 index 47597d5..5b4dbf7 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0003.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0003.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0004.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0004.h5 index 57f9f1f..293ad3a 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0004.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0004.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0005.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0005.h5 index 75f0a44..1678603 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0005.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0005.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0006.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0006.h5 index 2d11e0a..32b3b45 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0006.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0006.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0007.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0007.h5 index 4e9630a..e95d6eb 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0007.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0007.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0008.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0008.h5 index 533235a..6d9f52c 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0008.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0008.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0009.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0009.h5 index 6f24b96..878a1ff 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0009.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0009.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0010.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0010.h5 index 5484549..e151e08 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0010.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0010.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0011.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0011.h5 index 43c20e1..6152d77 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0011.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0011.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0012.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0012.h5 index c3621ad..ff65c9b 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0012.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0012.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0013.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0013.h5 index 1f34c3b..20a5fcf 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0013.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0013.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0014.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0014.h5 index a5993d1..41b3ddc 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0014.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0014.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0015.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0015.h5 index 7392c1a..df40412 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0015.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0015.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0016.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0016.h5 index abb7d6f..353ccbe 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0016.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0016.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0017.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0017.h5 index 289a16b..f729f73 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0017.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0017.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0018.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0018.h5 index cc47f5a..7caa049 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0018.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0018.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0019.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0019.h5 index 144f7c4..5f4ef97 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0019.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0019.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0020.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0020.h5 index 19c1928..d9e0cc1 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0020.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0020.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0021.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0021.h5 index 36360c1..be2869f 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0021.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0021.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0022.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0022.h5 index 3dcb60b..4feac4d 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0022.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0022.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0023.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0023.h5 index 3b15a13..8500c6b 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0023.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0023.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0024.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0024.h5 index ab53a01..148a640 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0024.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0024.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0025.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0025.h5 index 0f83655..b3a892b 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0025.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0025.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0026.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0026.h5 index 6a8b500..c25ecd8 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0026.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0026.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0027.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0027.h5 index 291c674..bc43470 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0027.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0027.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0028.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0028.h5 index 327816f..ba5204c 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0028.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0028.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0029.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0029.h5 index 0529af9..66ac4b5 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0029.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0029.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0030.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0030.h5 index 7949ea3..658246d 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0030.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0030.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0031.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0031.h5 index 83cbcb8..66cfd8c 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0031.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0031.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0032.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0032.h5 index bbb282c..da2f4c6 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0032.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0032.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0033.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0033.h5 index ccf429c..3b57a87 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0033.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0033.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0034.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0034.h5 index b8e37a7..6200a12 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0034.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0034.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0035.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0035.h5 index 4934814..d07e162 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0035.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0035.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0036.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0036.h5 index dc44c9b..947a9b3 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0036.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0036.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0037.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0037.h5 index 8748fb1..7966a32 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0037.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0037.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0038.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0038.h5 index ef5c236..6487da1 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0038.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0038.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0039.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0039.h5 index fa04c7a..f284e9e 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0039.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0039.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0040.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0040.h5 index 9d3d3a5..070fe8f 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0040.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0040.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0041.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0041.h5 index f2fb433..51ee626 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0041.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0041.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0042.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0042.h5 index 8e8724e..aef1f54 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0042.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0042.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0043.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0043.h5 index 43d13ed..39b8593 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0043.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0043.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0044.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0044.h5 index 46b3655..cbb0017 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0044.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0044.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0045.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0045.h5 index 63da5bb..31d6e1c 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0045.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0045.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0046.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0046.h5 index 2e50556..72ce8f1 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0046.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0046.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0047.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0047.h5 index fd97be0..be37de4 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0047.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0047.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0048.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0048.h5 index 331f459..30d1709 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0048.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0048.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0049.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0049.h5 index df125c9..5b66bdf 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0049.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0049.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0050.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0050.h5 index 01a6dbd..3cec208 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0050.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0050.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0051.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0051.h5 index 4756cf1..9471492 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0051.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0051.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0052.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0052.h5 index 4b1b331..49b0659 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0052.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0052.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0053.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0053.h5 index 79f8d41..0806624 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0053.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0053.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0054.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0054.h5 index 542d02e..50a09a9 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0054.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0054.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0055.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0055.h5 index e28e80e..c9e13ac 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0055.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0055.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0056.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0056.h5 index 0c1a2eb..1692ab8 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0056.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0056.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0057.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0057.h5 index ae4fa86..03a1a7d 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0057.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0057.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0058.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0058.h5 index b40c2db..a74b13e 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0058.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0058.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0059.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0059.h5 index d40cc3b..da1c53d 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0059.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0059.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0060.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0060.h5 index 8d36438..304143e 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0060.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0060.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0061.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0061.h5 index 132fddc..e4518bf 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0061.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0061.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0062.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0062.h5 index 2379f9c..579a7d9 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0062.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0062.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0063.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0063.h5 index 54079ba..1b619bc 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0063.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0063.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0064.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0064.h5 index d4abf52..d44d2b2 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0064.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0064.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0065.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0065.h5 index 2569e15..599aab3 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0065.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0065.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0066.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0066.h5 index d518611..047e52b 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0066.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0066.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0067.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0067.h5 index 3b46cf5..ad66968 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0067.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0067.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0068.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0068.h5 index af8142f..fd2dbf6 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0068.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0068.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0069.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0069.h5 index 950a6a6..fc8a7b7 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0069.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0069.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0070.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0070.h5 index f97a472..0381057 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0070.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0070.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0071.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0071.h5 index 8968674..52a31f3 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0071.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0071.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0072.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0072.h5 index 8482314..015d440 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0072.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0072.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0073.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0073.h5 index 9920a4e..bec6764 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0073.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0073.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0074.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0074.h5 index c77c416..586990f 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0074.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0074.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0075.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0075.h5 index a6bb365..035eaf6 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0075.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0075.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0076.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0076.h5 index 5a82910..f248caa 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0076.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0076.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0077.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0077.h5 index eb8a5e3..d44afc2 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0077.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0077.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0078.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0078.h5 index 008508d..3039b3a 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0078.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0078.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0079.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0079.h5 index 6585fe4..e4c53b8 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0079.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0079.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0080.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0080.h5 index 619a8fa..f38fd8c 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0080.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0080.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0081.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0081.h5 index 4651e81..fce3bc4 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0081.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0081.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0082.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0082.h5 index 5bfc2a7..b4a8a4c 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0082.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0082.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0083.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0083.h5 index 94b9391..8314ba8 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0083.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0083.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0084.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0084.h5 index e753ee9..9433fef 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0084.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0084.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0085.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0085.h5 index 03bb72e..1fb59b8 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0085.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0085.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0086.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0086.h5 index c6ae7e7..6fb8258 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0086.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0086.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0087.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0087.h5 index 281c3c3..c897d0e 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0087.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0087.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0088.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0088.h5 index 4e9f42b..9d911e5 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0088.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0088.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0089.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0089.h5 index c2cd98d..7c535b8 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0089.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0089.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0090.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0090.h5 index 57f5c15..8addc5d 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0090.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0090.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0091.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0091.h5 index b568c50..bb8d2c9 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0091.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0091.h5 differ diff --git a/test_data/IPTS32124_CG4C_exp0424/scan0092.h5 b/test_data/IPTS32124_CG4C_exp0424/scan0092.h5 index a9c197e..bdb7037 100644 Binary files a/test_data/IPTS32124_CG4C_exp0424/scan0092.h5 and b/test_data/IPTS32124_CG4C_exp0424/scan0092.h5 differ diff --git a/test_data/IPTS9865_HB1_exp0815/scan0001.h5 b/test_data/IPTS9865_HB1_exp0815/scan0001.h5 index 5510972..7099451 100644 Binary files a/test_data/IPTS9865_HB1_exp0815/scan0001.h5 and b/test_data/IPTS9865_HB1_exp0815/scan0001.h5 differ diff --git a/test_data/IPTS9865_HB1_exp0815/scan0002.h5 b/test_data/IPTS9865_HB1_exp0815/scan0002.h5 index 40c53a7..f8b6c22 100644 Binary files a/test_data/IPTS9865_HB1_exp0815/scan0002.h5 and b/test_data/IPTS9865_HB1_exp0815/scan0002.h5 differ diff --git a/test_data/IPTS9865_HB1_exp0815/scan0003.h5 b/test_data/IPTS9865_HB1_exp0815/scan0003.h5 index e106713..3a06a25 100644 Binary files a/test_data/IPTS9865_HB1_exp0815/scan0003.h5 and b/test_data/IPTS9865_HB1_exp0815/scan0003.h5 differ diff --git a/test_data/IPTS9865_HB1_exp0815/scan0004.h5 b/test_data/IPTS9865_HB1_exp0815/scan0004.h5 index 3e72251..24ceec6 100644 Binary files a/test_data/IPTS9865_HB1_exp0815/scan0004.h5 and b/test_data/IPTS9865_HB1_exp0815/scan0004.h5 differ diff --git a/test_data/IPTS9865_HB1_exp0815/scan0005.h5 b/test_data/IPTS9865_HB1_exp0815/scan0005.h5 index 2e62f73..5892401 100644 Binary files a/test_data/IPTS9865_HB1_exp0815/scan0005.h5 and b/test_data/IPTS9865_HB1_exp0815/scan0005.h5 differ diff --git a/test_data/IPTS9865_HB1_exp0815/scan0006.h5 b/test_data/IPTS9865_HB1_exp0815/scan0006.h5 index 309e13d..96be50b 100644 Binary files a/test_data/IPTS9865_HB1_exp0815/scan0006.h5 and b/test_data/IPTS9865_HB1_exp0815/scan0006.h5 differ diff --git a/test_data/tavi_test_exp424.h5 b/test_data/tavi_test_exp424.h5 index f07c6a7..8b6cba5 100644 Binary files a/test_data/tavi_test_exp424.h5 and b/test_data/tavi_test_exp424.h5 differ diff --git a/tests/test_fit.py b/tests/test_fit.py index bdedfbe..d95623f 100644 --- a/tests/test_fit.py +++ b/tests/test_fit.py @@ -2,8 +2,7 @@ import matplotlib.pyplot as plt import numpy as np -from tavi.data.fit import Fit -from tavi.data.plotter import Plot1DManager +from tavi.data.fit import Fit1D from tavi.data.scan import Scan @@ -13,14 +12,16 @@ def test_fit_single_peak(): _, s1 = Scan.from_nexus_file(nexus_file_name) plot1d = s1.generate_curve(norm_channel="mcu", norm_val=30) - f1 = Fit(x=plot1d.x, y=plot1d.y, err=plot1d.yerr, fit_range=(0.5, 4.0)) + f1 = Fit1D(plot1d) + f1.set_range(0.5, 4.0) f1.add_background(values=(0.7,)) f1.add_signal(values=(None, 3.5, None), vary=(True, True, True)) - fit_report = f1.perform_fit() - # assert np.allclose(f1.result.params["s1_center"].value, 3.54, atol=0.01) - # assert np.allclose(f1.result.params["s1_fwhm"].value, 0.39, atol=0.01) + f1.perform_fit() + assert np.allclose(f1.result.params["s1_center"].value, 3.54, atol=0.01) + assert np.allclose(f1.result.params["s1_fwhm"].value, 0.39, atol=0.01) fig, ax = plt.subplots() plot1d.plot_curve(ax) + f1.fit_plot.plot_curve(ax) plt.show() @@ -29,8 +30,9 @@ def test_fit_two_peak(): nexus_file_name = "./test_data/IPTS32124_CG4C_exp0424/scan0042.h5" _, s1 = Scan.from_nexus_file(nexus_file_name) - x, y, yerr, xlabel, ylabel, title, label = s1.generate_curve(norm_channel="mcu", norm_val=30) - f1 = Fit(x=x, y=y, err=yerr, fit_range=(0.0, 4.0)) + plot1d = s1.generate_curve(norm_channel="mcu", norm_val=30) + f1 = Fit1D(plot1d) + f1.set_range(0.0, 4.0) f1.add_background(values=(0.7,)) f1.add_signal(values=(None, 3.5, 0.29), vary=(True, True, True)) f1.add_signal( @@ -40,11 +42,11 @@ def test_fit_two_peak(): mins=(0, 0, 0.1), maxs=(None, 0.1, 0.3), ) - fit_report = f1.perform_fit() + f1.perform_fit() assert np.allclose(f1.result.params["s1_center"].value, 3.54, atol=0.01) assert np.allclose(f1.result.params["s1_fwhm"].value, 0.40, atol=0.01) - p1 = Plot1DManager() - p1.plot_curve(x, y, yerr, xlabel, ylabel, title, label) - p1.plot_curve(f1.x_plot, f1.y_plot, fmt="-", xlabel=xlabel, ylabel=ylabel, title=title) + fig, ax = plt.subplots() + plot1d.plot_curve(ax) + f1.fit_plot.plot_curve(ax) plt.show() diff --git a/tests/test_scan.py b/tests/test_scan.py index 28c3ada..ac583d1 100644 --- a/tests/test_scan.py +++ b/tests/test_scan.py @@ -12,7 +12,7 @@ def test_load_scan_from_tavi(): tavi_file_name = "./test_data/tavi_test_exp424.h5" tavi.new_file(tavi_file_name) nexus_data_folder = "./test_data/IPTS32124_CG4C_exp0424" - tavi.get_nexus_data_from_disk(nexus_data_folder) + tavi.load_nexus_data_from_disk(nexus_data_folder) with h5py.File(tavi.file_path, "r") as tavi_file: dataset_name, scan = Scan.from_nexus_entry(tavi_file["/data/IPTS32124_CG4C_exp0424/scan0042"]) diff --git a/tests/test_scan_group.py b/tests/test_scan_group.py index e988104..e01ef15 100644 --- a/tests/test_scan_group.py +++ b/tests/test_scan_group.py @@ -12,7 +12,7 @@ def test_contour_plot(): tavi_file = Path(tavi_file_name) if not tavi_file.is_file(): nexus_data_folder = "./test_data/IPTS32124_CG4C_exp0424" - tavi.get_nexus_data_from_disk(nexus_data_folder) + tavi.load_nexus_data_from_disk(nexus_data_folder) tavi.load_data() else: tavi.open_file(tavi_file_name) diff --git a/tests/test_tavi_data.py b/tests/test_tavi_data.py index 9d8ac57..1c17beb 100644 --- a/tests/test_tavi_data.py +++ b/tests/test_tavi_data.py @@ -10,6 +10,7 @@ def test_new_tavi_file_at_given_path(): tavi = TAVI() tavi_file_name = "./test_data/tavi_empty_test.h5" tavi.new_file(tavi_file_name) + tavi.save_file() with h5py.File(tavi_file_name, "r") as f: keys = [key for key in f["/"].keys()] @@ -23,47 +24,28 @@ def test_new_tavi_file_at_given_path(): os.remove(tavi_file_name) -def test_new_tavi_file_without_path(): - tavi = TAVI() - tavi.new_file() - - with h5py.File(tavi.file_path, "r") as f: - keys = [key for key in f["/"].keys()] - # check if groups preserves the order - assert keys[0] == "data" - assert keys[1] == "processed_data" - assert keys[2] == "fits" - assert keys[3] == "plots" - - # delete file - os.remove(tavi.file_path) - - -def test_get_nexus_data_from_disk(): +def test_load_nexus_data_from_disk(): tavi = TAVI() tavi_file_name = "./test_data/tavi_test_exp424.h5" tavi.new_file(tavi_file_name) nexus_data_folder = "./test_data/IPTS32124_CG4C_exp0424" - tavi.get_nexus_data_from_disk(nexus_data_folder) - - with h5py.File(tavi.file_path, "r") as tavi_file: - assert len(tavi_file["/data/IPTS32124_CG4C_exp0424"]) == 92 + tavi.load_nexus_data_from_disk(nexus_data_folder) + assert len(tavi.data["IPTS32124_CG4C_exp0424"]) == 92 # os.remove(tavi.file_path) -def test_load_data(): - +def test_save_tavi_file(): tavi = TAVI() tavi_file_name = "./test_data/tavi_test_exp424.h5" tavi.new_file(tavi_file_name) nexus_data_folder = "./test_data/IPTS32124_CG4C_exp0424" - tavi.get_nexus_data_from_disk(nexus_data_folder) - - tavi.load_data() + tavi.load_nexus_data_from_disk(nexus_data_folder) + tavi.save_file() - assert len(tavi.data["IPTS32124_CG4C_exp0424"]) == 92 + with h5py.File(tavi.file_path, "r") as tavi_file: + assert len(tavi_file["/data/IPTS32124_CG4C_exp0424"]) == 92 def test_open_tavi_file(): @@ -73,3 +55,16 @@ def test_open_tavi_file(): assert len(scans := tavi.data["IPTS32124_CG4C_exp0424"]) == 92 assert scans["scan0001"].scan_info.scan_num == 1 + + +def test_new_tavi_file_without_path(): + tavi = TAVI() + tavi.new_file() + tavi.save_file() + + with h5py.File(tavi.file_path, "r") as f: + keys = [key for key in f["/"].keys()] + # check if groups preserves the order + assert keys[1] == "processed_data" + # delete file + os.remove(tavi.file_path)