From 55adc6ac5a3aefe77537b28cbed42c4a28d84a17 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Mon, 7 Oct 2024 18:16:52 -0500 Subject: [PATCH] Testing:Expand Test coverage --- rsciio/dm5/_api.py | 31 +++++++++++++++++++------------ rsciio/tests/test_dm5.py | 30 ++++++++++++++++++------------ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/rsciio/dm5/_api.py b/rsciio/dm5/_api.py index 623c5fb6..e5bab3b4 100644 --- a/rsciio/dm5/_api.py +++ b/rsciio/dm5/_api.py @@ -337,9 +337,6 @@ def __init__(self, image_group, tags=None, unique_id=None, file=None): self.unique_id = image_group["UniqueID"] self.file = file - def __str__(self): - return f"Image: {self.image_data['Data'].shape}" - @property def ndim(self): return len(self.image_data["Data"].shape) @@ -380,9 +377,6 @@ def signal_dimensions(self): "Meta Data.Format attribute in the ImageTags group." ) - def navigation_dimensions(self): - return self.ndim - self.signal_dimensions() - def get_axis_dict(self, axis): """ Get the calibration data for a given axis. @@ -596,13 +590,26 @@ def update_metadata( dict2group(formatted_metadata, self.image_tags) # Update Microscope Info - if "Acquisition_instrument" in metadata and "TEM" in metadata["Acquisition_instrument"]: + if ( + "Acquisition_instrument" in metadata + and "TEM" in metadata["Acquisition_instrument"] + ): self.image_tags.create_group("Microscope Info") - microscope_info_dict = {"Voltage": metadata["Acquisition_instrument"]["TEM"].get("beam_energy",0) * 1000, - "Illumination Mode": metadata["Acquisition_instrument"]["TEM"].get("acquisition_mode", "Unknown"), - "Indicated Magnification": metadata["Acquisition_instrument"]["TEM"].get("magnification", 0), - "STEM Camera Length": metadata["Acquisition_instrument"]["TEM"].get("camera_length", 0)} - + microscope_info_dict = { + "Voltage": metadata["Acquisition_instrument"]["TEM"].get( + "beam_energy", 0 + ) + * 1000, + "Illumination Mode": metadata["Acquisition_instrument"]["TEM"].get( + "acquisition_mode", "Unknown" + ), + "Indicated Magnification": metadata["Acquisition_instrument"][ + "TEM" + ].get("magnification", 0), + "STEM Camera Length": metadata["Acquisition_instrument"]["TEM"].get( + "camera_length", 0 + ), + } dict2group(microscope_info_dict, self.image_tags["Microscope Info"]) diff --git a/rsciio/tests/test_dm5.py b/rsciio/tests/test_dm5.py index bb85c255..bddfcf35 100644 --- a/rsciio/tests/test_dm5.py +++ b/rsciio/tests/test_dm5.py @@ -24,6 +24,7 @@ from pathlib import Path +import dask.array as da import numpy as np import pytest @@ -84,10 +85,8 @@ def test_save_load_files( assert s.axes_manager[i].scale == 0.1 assert s.axes_manager[i].size == int(original[i][-2:]) - def test_save_load_undefined_axes( - self, tmp_path - ): - fname = tmp_path/ f"test_save_undefined.dm5" + def test_save_load_undefined_axes(self, tmp_path): + fname = tmp_path / "test_save_undefined.dm5" data_shape = [10, 11, 12, 13] data = np.ones(data_shape, dtype=np.float32) @@ -98,23 +97,30 @@ def test_save_load_undefined_axes( assert s.axes_manager[i].name == "" assert s.axes_manager[i].units == "" - def test_save_load_metadata( - self, tmp_path - ): - fname = tmp_path/ f"test_save_undefined.dm5" + def test_save_load_metadata(self, tmp_path): + fname = tmp_path / "test_save_undefined.dm5" data_shape = [10, 11, 12, 13] data = np.ones(data_shape, dtype=np.float32) signal = hs.signals.Signal2D(data) signal.metadata.General.title = "test" signal.metadata.add_node("Acquisition_instrument.TEM") - signal.metadata.Acquisition_instrument.TEM.beam_energy = 200 + signal.metadata.Acquisition_instrument.TEM.beam_energy = 200 signal.metadata.Acquisition_instrument.TEM.magnification = 100 signal.metadata.Acquisition_instrument.TEM.camera_length = 10 signal.save(fname, overwrite=True) s = hs.load(fname) - assert s.metadata.Acquisition_instrument.TEM.beam_energy == 200 - assert s.metadata.Acquisition_instrument.TEM.camera_length == 10 - assert s.metadata.Acquisition_instrument.TEM.magnification == 100 + assert s.metadata.Acquisition_instrument.TEM.beam_energy == 200 + assert s.metadata.Acquisition_instrument.TEM.camera_length == 10 + assert s.metadata.Acquisition_instrument.TEM.magnification == 100 + def test_save_load_lazy(self, tmp_path): + fname = tmp_path / "test_save_lazy.dm5" + + data_shape = [10, 11, 12, 13] + data = np.ones(data_shape, dtype=np.float32) + signal = hs.signals.Signal2D(data) + signal.save(fname, overwrite=True) + s = hs.load(fname, lazy=True) + assert isinstance(s.data, da.Array)