From 57403f70f61500e248d57584962c1a0df3a2defc Mon Sep 17 00:00:00 2001 From: Kimoon Han Date: Wed, 15 May 2024 20:45:27 +0900 Subject: [PATCH] test: fix tests for interactive --- src/erlab/interactive/imagetool/__init__.py | 96 +-------------------- tests/plotting/test_general.py | 4 +- 2 files changed, 4 insertions(+), 96 deletions(-) diff --git a/src/erlab/interactive/imagetool/__init__.py b/src/erlab/interactive/imagetool/__init__.py index 6967bf93..c2e7bfba 100644 --- a/src/erlab/interactive/imagetool/__init__.py +++ b/src/erlab/interactive/imagetool/__init__.py @@ -143,6 +143,8 @@ def itool( gc.collect() return None + if len(itool_list) == 1: + return itool_list[0] return itool_list @@ -478,97 +480,3 @@ def _export_file(self): files = dialog.selectedFiles() fn, kargs = valid_savers[dialog.selectedNameFilter()] fn(self.slicer_area._data, files[0], **kargs) - - -if __name__ == "__main__": - # import gc - # import linecache - # import tracemalloc - - # def display_top(snapshot: tracemalloc.Snapshot, limit=10): - # snapshot = snapshot.filter_traces( - # ( - # tracemalloc.Filter(False, ""), - # tracemalloc.Filter(False, ""), - # ) - # ) - # top_stats = snapshot.statistics("traceback") - - # print(f"\nTop {limit} lines") - # for index, stat in enumerate(top_stats[:limit], 1): - # frame = stat.traceback[0] - # print( - # f"#{index} {stat.traceback.total_nframe}: " - # f"{frame.filename}:{frame.lineno}: {stat.size/1024:.1f} KiB" - # ) - # line = linecache.getline(frame.filename, frame.lineno).strip() - # if line: - # print(" %s" % line) - - # other = top_stats[limit:] - # if other: - # size = sum(stat.size for stat in other) - # print(f"{len(other)} other: {size/1024:.1f} KiB") - # total = sum(stat.size for stat in top_stats) - # print(f"Total allocated size: {total/1024:.1f} KiB") - - # while True: - # try: - # idx = int(input("Index: ")) - # stat = top_stats[idx - 1] - # except (IndexError, ValueError): - # break - # print("%s memory blocks: %.1f KiB" % (stat.count, stat.size / 1024)) - # for line in stat.traceback.format(): - # print(line) - - # tracemalloc.start() - data = xr.load_dataarray( - # # "~/Documents/ERLab/TiSe2/kxy10.nc", - # # "~/Documents/ERLab/TiSe2/221213_SSRL_BL5-2/fullmap_kconv_.h5", - "~/Documents/ERLab/CsV3Sb5/2021_Dec_ALS_CV3Sb5/Data/cvs_kxy_small.nc", - # "~/Documents/ERLab/CsV3Sb5/2021_Dec_ALS_CV3Sb5/Data/cvs_kxy.nc", - # "~/Documents/ERLab/TiSe2/220410_ALS_BL4/map_mm_4d_.nc", - # engine="h5netcdf", - ) - - # win = itool(data, bench=True) - # win = itool(data) - # del data - - # gc.collect() - # data = xr.load_dataarray( - # "~/Documents/ERLab/CsV3Sb5/2021_Dec_ALS_CV3Sb5/Data/cvs_kxy.nc", - # engine="h5netcdf", - # ) - - # from erlab.io.exampledata import generate_data - - # data = generate_data() - - # win = itool([data, data], link=True, link_colors=False) - # win = itool(data.sel(eV=0, method='nearest')) - win = itool(data) - - # snapshot = tracemalloc.take_snapshot() - # print( - # *[ - # f"{n} {m * 2**-20:.2f} MB\t" - # for n, m in zip(("Current", "Max"), tracemalloc.get_traced_memory()) - # ], - # sep="", - # ) - # tracemalloc.stop() - # display_top(snapshot) - # print(win.array_slicer._nanmeancalls) - - # qapp: QtWidgets.QApplication = QtWidgets.QApplication.instance() - # if not qapp: - # qapp = QtWidgets.QApplication(sys.argv) - # qapp.setStyle("Fusion") - # import numpy as np - # win = ImageTool(np.ones((2,2))) - # win.show() - # win.raise_() - # win.activateWindow() - # qapp.exec() diff --git a/tests/plotting/test_general.py b/tests/plotting/test_general.py index 96182b75..f894f3c4 100644 --- a/tests/plotting/test_general.py +++ b/tests/plotting/test_general.py @@ -23,8 +23,8 @@ def test_plot_slices(): assert isinstance(axes, np.ndarray) assert axes.shape == (2, 1) - # Test line plots - fig, axes = plot_slices(maps, y=[0.1, 0.2, 0.3], transpose=True) + # Test line plots with gradient + fig, axes = plot_slices(maps, y=[0.1, 0.2, 0.3], transpose=True, gradient=True) assert axes[0, 0].lines[0].get_ydata().tolist() == x.tolist() assert axes.shape == (2, 3)