Skip to content

Commit

Permalink
test: fix tests for interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed May 15, 2024
1 parent 5cab279 commit 57403f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 96 deletions.
96 changes: 2 additions & 94 deletions src/erlab/interactive/imagetool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def itool(
gc.collect()

return None
if len(itool_list) == 1:
return itool_list[0]
return itool_list


Expand Down Expand Up @@ -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, "<frozen importlib._bootstrap>"),
# tracemalloc.Filter(False, "<unknown>"),
# )
# )
# 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()
4 changes: 2 additions & 2 deletions tests/plotting/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 57403f7

Please sign in to comment.