diff --git a/scripts/HoV6Sn6_contour.py b/scripts/HoV6Sn6_contour.py index 64c746d3..530a114e 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 dd96a002..e1bfea8c 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 09befe48..2146a832 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 e89020a1..39c9ee5e 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 52c623c4..338e07de 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 2d437dc4..00350f42 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 812d6970..f0a21859 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 e64aa262..520bb519 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 47597d50..5b4dbf7b 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 57f9f1ff..293ad3aa 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 75f0a44b..16786030 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 2d11e0ad..32b3b458 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 4e9630a5..e95d6ebd 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 533235a7..6d9f52ca 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 6f24b969..878a1ff6 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 54845494..e151e087 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 43c20e1f..6152d77c 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 c3621ad8..ff65c9b3 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 1f34c3b0..20a5fcf2 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 a5993d18..41b3ddcc 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 7392c1a0..df404121 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 abb7d6fb..353ccbe4 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 289a16b0..f729f73c 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 cc47f5a6..7caa0497 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 144f7c4a..5f4ef977 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 19c19282..d9e0cc18 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 36360c16..be2869fc 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 3dcb60b3..4feac4d3 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 3b15a134..8500c6ba 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 ab53a016..148a6401 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 0f836557..b3a892b5 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 6a8b500c..c25ecd82 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 291c674f..bc43470e 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 327816fe..ba5204c5 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 0529af90..66ac4b5d 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 7949ea30..658246de 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 83cbcb85..66cfd8c5 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 bbb282c4..da2f4c64 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 ccf429cc..3b57a877 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 b8e37a7c..6200a125 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 4934814f..d07e162f 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 dc44c9b4..947a9b3d 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 8748fb15..7966a32a 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 ef5c2364..6487da14 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 fa04c7a1..f284e9e2 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 9d3d3a53..070fe8f5 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 f2fb4339..51ee626a 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 8e8724e5..aef1f542 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 43d13ed5..39b85935 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 46b3655b..cbb0017b 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 63da5bbe..31d6e1ca 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 2e50556f..72ce8f1d 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 fd97be06..be37de4d 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 331f4599..30d1709f 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 df125c97..5b66bdf8 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 01a6dbd3..3cec2089 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 4756cf1a..94714928 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 4b1b3311..49b06598 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 79f8d41f..08066244 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 542d02e6..50a09a98 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 e28e80e2..c9e13ac8 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 0c1a2ebd..1692ab85 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 ae4fa866..03a1a7de 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 b40c2dbf..a74b13e7 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 d40cc3ba..da1c53d8 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 8d36438b..304143ed 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 132fddcb..e4518bfe 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 2379f9c2..579a7d97 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 54079bad..1b619bc0 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 d4abf522..d44d2b20 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 2569e15d..599aab33 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 d518611a..047e52bf 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 3b46cf55..ad669684 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 af8142f6..fd2dbf65 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 950a6a6d..fc8a7b7b 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 f97a4724..03810570 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 8968674e..52a31f38 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 8482314b..015d4404 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 9920a4e9..bec6764e 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 c77c4166..586990f2 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 a6bb3657..035eaf6b 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 5a82910c..f248caac 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 eb8a5e36..d44afc28 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 008508d3..3039b3a7 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 6585fe47..e4c53b80 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 619a8fac..f38fd8ca 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 4651e814..fce3bc4f 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 5bfc2a7c..b4a8a4c6 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 94b9391e..8314ba82 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 e753ee92..9433fefa 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 03bb72e3..1fb59b86 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 c6ae7e7f..6fb8258e 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 281c3c3d..c897d0e3 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 4e9f42be..9d911e54 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 c2cd98de..7c535b81 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 57f5c153..8addc5d7 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 b568c507..bb8d2c99 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 a9c197e3..bdb7037a 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 5510972c..70994514 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 40c53a73..f8b6c22f 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 e106713c..3a06a25d 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 3e72251a..24ceec6d 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 2e62f73d..58924014 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 309e13da..96be50bf 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 f07c6a73..8b6cba55 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 bdedfbe9..d95623fc 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 28c3ada3..ac583d1a 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 e988104e..e01ef152 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 9d8ac574..1c17bebe 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)