diff --git a/tomoscan/esrf/scan/edfscan.py b/tomoscan/esrf/scan/edfscan.py index 34daf042dbc2f81e88000d1cab23d7f49bd8e8e9..2b30f59a3cde298fb62b34eac4bffbf1ea7ae0a6 100644 --- a/tomoscan/esrf/scan/edfscan.py +++ b/tomoscan/esrf/scan/edfscan.py @@ -9,6 +9,7 @@ import logging import os import re from typing import Iterable +import warnings import fabio import numpy @@ -822,6 +823,16 @@ class EDFTomoScan(TomoScanBase): return self._count_time + @property + def electric_current(self) -> tuple: + warnings.warn( + "electric_current is deprecated and will be removed in a future version. Use machine_current instead.", + DeprecationWarning, + stacklevel=2 + ) + return self.machine_current + + @property @docstring(TomoScanBase.machine_current) def machine_current(self) -> tuple: diff --git a/tomoscan/esrf/scan/framereducer/edfframereducer.py b/tomoscan/esrf/scan/framereducer/edfframereducer.py index 4ef7afa6a0a621aef77f7472f42661fe19699c77..11c9ad5d844f434781afa68c3afd4bce1c0a48b4 100644 --- a/tomoscan/esrf/scan/framereducer/edfframereducer.py +++ b/tomoscan/esrf/scan/framereducer/edfframereducer.py @@ -291,9 +291,9 @@ class EDFFrameReducer(FrameReducerBase): # update electrical machine current if header["SRCUR"] is not None: - if infos.machine_electric_current is None: - infos.machine_electric_current = [] - infos.machine_electric_current.append(header["SRCUR"]) + if infos.machine_current is None: + infos.machine_current = [] + infos.machine_current.append(header["SRCUR"]) if header["Count_time"] is not None: if infos.count_time is None: infos.count_time = [] diff --git a/tomoscan/esrf/scan/framereducer/hdf5framereducer.py b/tomoscan/esrf/scan/framereducer/hdf5framereducer.py index ac5f70c40074292b93f74e6c059c6c15d76691e9..c2d60a06c34b1e92d9badec378a1917138621f8d 100644 --- a/tomoscan/esrf/scan/framereducer/hdf5framereducer.py +++ b/tomoscan/esrf/scan/framereducer/hdf5framereducer.py @@ -65,7 +65,7 @@ class HDF5FrameReducer(FrameReducerBase): else: return self.scan.count_time[indexes] - def get_machine_electric_current(self, indexes): + def get_machine_current(self, indexes): if self.scan.machine_current is None: return [] else: @@ -162,7 +162,7 @@ class HDF5FrameReducer(FrameReducerBase): series_frame_data = self.load_data_serie(series_) series_count_time = self.get_count_time_serie(indexes=list(series_.keys())) - series_machine_electric_current = self.get_machine_electric_current( + series_machine_current = self.get_machine_current( indexes=list(series_.keys()) ) @@ -179,17 +179,17 @@ class HDF5FrameReducer(FrameReducerBase): raise ValueError( f"reduced method not handle for method 'raw' ({self.reduced_method}). Expects 'first' or 'last'" ) - if len(series_machine_electric_current) > 0: - infos.machine_electric_current.append( - series_machine_electric_current[index_infos] + if len(series_machine_current) > 0: + infos.machine_current.append( + series_machine_current[index_infos] ) if len(series_count_time) > 0: infos.count_time.append(series_count_time[index_infos]) else: data = method_(series_frame_data, axis=0) - if len(series_machine_electric_current) > 0: - infos.machine_electric_current.append( - method_(series_machine_electric_current) + if len(series_machine_current) > 0: + infos.machine_current.append( + method_(series_machine_current) ) if len(series_count_time) > 0: infos.count_time.append(method_(series_count_time)) diff --git a/tomoscan/esrf/scan/framereducer/tests/test_edfframereducer.py b/tomoscan/esrf/scan/framereducer/tests/test_edfframereducer.py index 6b84960ac2d61e37db193056f35bf7d61f0791fa..d570a2078d88a9198c3a2229f9f1038211d9341f 100644 --- a/tomoscan/esrf/scan/framereducer/tests/test_edfframereducer.py +++ b/tomoscan/esrf/scan/framereducer/tests/test_edfframereducer.py @@ -230,19 +230,19 @@ def test_reduce_edf(tmp_path): assert isinstance(darks_metadata, ReducedFramesInfos) assert ( len(darks_metadata.count_time) - == len(darks_metadata.machine_electric_current) + == len(darks_metadata.machine_current) == 1 ) # with the current method (only one Srcurrent and Count_time value per acquistion) flats and darks will have the same value # and also the same no matter the method to compute it assert darks_metadata.count_time[0] == count_time - assert darks_metadata.machine_electric_current[0] == machine_current + assert darks_metadata.machine_current[0] == machine_current _, flats_metadata = scan.compute_reduced_flats( reduced_method="mean", return_info=True ) assert ( len(flats_metadata.count_time) - == len(flats_metadata.machine_electric_current) + == len(flats_metadata.machine_current) == 2 ) assert ( @@ -251,9 +251,9 @@ def test_reduce_edf(tmp_path): == flats_metadata.count_time[1] ) assert ( - darks_metadata.machine_electric_current[0] - == flats_metadata.machine_electric_current[0] - == flats_metadata.machine_electric_current[1] + darks_metadata.machine_current[0] + == flats_metadata.machine_current[0] + == flats_metadata.machine_current[1] ) diff --git a/tomoscan/esrf/scan/framereducer/tests/test_hdf5framereducer.py b/tomoscan/esrf/scan/framereducer/tests/test_hdf5framereducer.py index 8f0455df984f3a7d8aa3f3f88e609d373a2987cc..444914637553a8b763bd06fa854767a093e39675 100644 --- a/tomoscan/esrf/scan/framereducer/tests/test_hdf5framereducer.py +++ b/tomoscan/esrf/scan/framereducer/tests/test_hdf5framereducer.py @@ -212,9 +212,9 @@ def test_reduce_hdf5(tmp_path): reduced_method="median", return_info=True ) assert isinstance(darks_infos, ReducedFramesInfos) - assert len(darks_infos.machine_electric_current) == len(darks_infos.count_time) == 1 + assert len(darks_infos.machine_current) == len(darks_infos.count_time) == 1 numpy.testing.assert_almost_equal( - darks_infos.machine_electric_current[0], numpy.median(darks_machine_current) + darks_infos.machine_current[0], numpy.median(darks_machine_current) ) numpy.testing.assert_almost_equal( darks_infos.count_time[0], numpy.median(darks_count_time) @@ -222,7 +222,7 @@ def test_reduce_hdf5(tmp_path): _, darks_infos = scan.compute_reduced_darks(reduced_method="mean", return_info=True) numpy.testing.assert_almost_equal( - darks_infos.machine_electric_current[0], numpy.mean(darks_machine_current) + darks_infos.machine_current[0], numpy.mean(darks_machine_current) ) numpy.testing.assert_almost_equal( darks_infos.count_time[0], numpy.mean(darks_count_time) @@ -232,13 +232,13 @@ def test_reduce_hdf5(tmp_path): reduced_method="first", return_info=True ) numpy.testing.assert_almost_equal( - darks_infos.machine_electric_current[0], darks_machine_current[0] + darks_infos.machine_current[0], darks_machine_current[0] ) numpy.testing.assert_almost_equal(darks_infos.count_time[0], darks_count_time[0]) _, darks_infos = scan.compute_reduced_darks(reduced_method="last", return_info=True) numpy.testing.assert_almost_equal( - darks_infos.machine_electric_current[0], darks_machine_current[-1] + darks_infos.machine_current[0], darks_machine_current[-1] ) numpy.testing.assert_almost_equal(darks_infos.count_time[0], darks_count_time[-1]) @@ -247,13 +247,13 @@ def test_reduce_hdf5(tmp_path): reduced_method="median", return_info=True ) assert isinstance(flats_infos, ReducedFramesInfos) - assert len(flats_infos.machine_electric_current) == len(flats_infos.count_time) == 2 + assert len(flats_infos.machine_current) == len(flats_infos.count_time) == 2 numpy.testing.assert_almost_equal( - flats_infos.machine_electric_current[0], + flats_infos.machine_current[0], numpy.median(flats_s1_machine_current), ) numpy.testing.assert_almost_equal( - flats_infos.machine_electric_current[1], + flats_infos.machine_current[1], numpy.median(flats_s2_machine_current), ) numpy.testing.assert_almost_equal( @@ -265,10 +265,10 @@ def test_reduce_hdf5(tmp_path): _, flats_infos = scan.compute_reduced_flats(reduced_method="mean", return_info=True) numpy.testing.assert_almost_equal( - flats_infos.machine_electric_current[0], numpy.mean(flats_s1_machine_current) + flats_infos.machine_current[0], numpy.mean(flats_s1_machine_current) ) numpy.testing.assert_almost_equal( - flats_infos.machine_electric_current[1], numpy.mean(flats_s2_machine_current) + flats_infos.machine_current[1], numpy.mean(flats_s2_machine_current) ) numpy.testing.assert_almost_equal( flats_infos.count_time[0], numpy.mean(flats_s1_count_time) diff --git a/tomoscan/esrf/scan/tests/test_edfscan.py b/tomoscan/esrf/scan/tests/test_edfscan.py index 7e03f1a9120e744542b788500eb68f858b4af898..33cddfcf40b71bc681e621cc88a3334c8e65e6df 100644 --- a/tomoscan/esrf/scan/tests/test_edfscan.py +++ b/tomoscan/esrf/scan/tests/test_edfscan.py @@ -849,7 +849,7 @@ def test_save_dark_flat_reduced_several_urls(tmp_path): # test metadata flats_infos = ReducedFramesInfos() flats_infos.count_time = [1.0, 1.0] - flats_infos.machine_electric_current = [13.0, 13.0] + flats_infos.machine_current = [13.0, 13.0] scan.save_reduced_flats( flats={ @@ -863,7 +863,7 @@ def test_save_dark_flat_reduced_several_urls(tmp_path): darks_infos.count_time = [ 2.0, ] - darks_infos.machine_electric_current = [13.1] + darks_infos.machine_current = [13.1] scan.save_reduced_darks( darks={ 0: dark_frame, diff --git a/tomoscan/esrf/scan/tests/test_nxtomoscan.py b/tomoscan/esrf/scan/tests/test_nxtomoscan.py index 3385311191a6182e2a050b94a729bbef51f17d35..40e5041424f54025a424ea00e5c5ba5cfb9a2ac2 100644 --- a/tomoscan/esrf/scan/tests/test_nxtomoscan.py +++ b/tomoscan/esrf/scan/tests/test_nxtomoscan.py @@ -769,7 +769,7 @@ def test_save_dark_flat_reduced_several_urls(tmp_path): flats_infos.count_time = [ 1, ] - flats_infos.machine_electric_current = [ + flats_infos.machine_current = [ 12.3, ] @@ -783,7 +783,7 @@ def test_save_dark_flat_reduced_several_urls(tmp_path): ) flats_infos.count_time = [1.0, 1.0] - flats_infos.machine_electric_current = [12.3, 13.2] + flats_infos.machine_current = [12.3, 13.2] scan.save_reduced_flats( flats={ 1: flat_frame_1, @@ -846,7 +846,7 @@ def test_save_dark_flat_reduced_several_urls(tmp_path): ) darks_infos = ReducedFramesInfos() darks_infos.count_time = [2.5] - darks_infos.machine_electric_current = [13.1] + darks_infos.machine_current = [13.1] scan.save_reduced_darks( darks={ 0: dark_frame, diff --git a/tomoscan/esrf/scan/tests/test_utils.py b/tomoscan/esrf/scan/tests/test_utils.py index d020a7fae3464241ab83a42160780f0c5f8ddeb0..4ee66f608c894bd270b91f89286a38d4d1e826e0 100644 --- a/tomoscan/esrf/scan/tests/test_utils.py +++ b/tomoscan/esrf/scan/tests/test_utils.py @@ -198,14 +198,14 @@ def test_dark_and_flat_copy(tmp_path): numpy.array(scan.reduced_darks_infos.count_time), numpy.array([1.0]) ) assert numpy.array_equal( - numpy.array(scan.reduced_darks_infos.machine_electric_current), + numpy.array(scan.reduced_darks_infos.machine_current), numpy.array([12.3]), ) assert numpy.array_equal( numpy.array(scan.reduced_flats_infos.count_time), numpy.array([2.0, 2.1]) ) assert numpy.array_equal( - numpy.array(scan.reduced_flats_infos.machine_electric_current), + numpy.array(scan.reduced_flats_infos.machine_current), numpy.array([14.3, 14.2]), ) diff --git a/tomoscan/framereducer/reducedframesinfos.py b/tomoscan/framereducer/reducedframesinfos.py index e0a23c438a7a0be3a93dfd1ab70f74e2caf96ad4..fd6ed0eacc158be06d50bed964d17eac2cef650d 100644 --- a/tomoscan/framereducer/reducedframesinfos.py +++ b/tomoscan/framereducer/reducedframesinfos.py @@ -2,6 +2,7 @@ from __future__ import annotations import numpy +import warnings from typing import Iterable @@ -24,8 +25,8 @@ class ReducedFramesInfos: return numpy.array_equal( numpy.array(self.count_time), numpy.array(__o.count_time) ) and numpy.array_equal( - numpy.array(self.machine_electric_current), - numpy.array(__o.machine_electric_current), + numpy.array(self.machine_current), + numpy.array(__o.machine_current), ) def clear(self): @@ -48,13 +49,31 @@ class ReducedFramesInfos: @property def machine_electric_current(self) -> list: + warnings.warn( + "machine_electric_current is deprecated and will be removed in a future version. Use machine_current instead.", + DeprecationWarning, + stacklevel=2 + ) + return self.machine_current + + @machine_electric_current.setter + def machine_electric_current(self, machine_current: Iterable | None): + warnings.warn( + "machine_electric_current is deprecated and will be removed in a future version. Use machine_current instead.", + DeprecationWarning, + stacklevel=2 + ) + self.machine_current = machine_current + + @property + def machine_current(self) -> list: """ machine electric current in Ampere """ return self._machine_current - @machine_electric_current.setter - def machine_electric_current(self, machine_current: Iterable | None): + @machine_current.setter + def machine_current(self, machine_current: Iterable | None): if machine_current is None: self._machine_current.clear() else: @@ -62,14 +81,14 @@ class ReducedFramesInfos: def to_dict(self) -> dict: res = {} - if len(self.machine_electric_current) > 0: - res[self.MACHINE_ELECT_CURRENT_KEY] = self.machine_electric_current + if len(self.machine_current) > 0: + res[self.MACHINE_ELECT_CURRENT_KEY] = self.machine_current if len(self.count_time) > 0: res[self.COUNT_TIME_KEY] = self.count_time return res def load_from_dict(self, my_dict: dict): - self.machine_electric_current = my_dict.get( + self.machine_current = my_dict.get( self.MACHINE_ELECT_CURRENT_KEY, None ) self.count_time = my_dict.get(self.COUNT_TIME_KEY, None) @@ -92,7 +111,7 @@ class ReducedFramesInfos: def __str__(self): return "\n".join( [ - f"machine_electric_current {self.machine_electric_current}", + f"machine_current {self.machine_current}", f"count_time {self.count_time}", ] ) diff --git a/tomoscan/scanbase.py b/tomoscan/scanbase.py index b22ad795e1fb437820a59522f8e3fc3e1b9cdc59..9599f95b96539e0644baa8964deb1b4742e93a2e 100644 --- a/tomoscan/scanbase.py +++ b/tomoscan/scanbase.py @@ -10,6 +10,7 @@ from bisect import bisect_left from collections import OrderedDict from math import ceil from typing import Iterable +import warnings import fabio import h5py @@ -515,6 +516,24 @@ class TomoScanBase(TomoObject): def count_time(self) -> list | None: raise NotImplementedError("Base class") + @property + def electric_current(self) -> tuple: + warnings.warn( + "electric_current is deprecated and will be removed in a future version. Use machine_current instead.", + DeprecationWarning, + stacklevel=2 + ) + return self.machine_current + + @electric_current.setter + def electric_current(self, current: tuple | None) -> None: + warnings.warn( + "electric_current is deprecated and will be removed in a future version. Use machine_current instead.", + DeprecationWarning, + stacklevel=2 + ) + self.machine_current = current + @property def machine_current(self) -> tuple: """Return the sample name""" @@ -1246,9 +1265,9 @@ class TomoScanBase(TomoObject): header = {} if ( frames_metadata is not None - and len(frames_metadata.machine_electric_current) > 0 + and len(frames_metadata.machine_current) > 0 ): - header["SRCUR"] = frames_metadata.machine_electric_current[ + header["SRCUR"] = frames_metadata.machine_current[ i_frame ] if ( @@ -1287,7 +1306,7 @@ class TomoScanBase(TomoObject): ) scheme = url.scheme() for metadata_name, metadata_values in frames_metadata.to_dict().items(): - # warning: for now we only handle list (of count_time and machine_electric_current) + # warning: for now we only handle list (of count_time and machine_current) if len(metadata_values) == 0: continue else: @@ -1422,7 +1441,7 @@ class TomoScanBase(TomoObject): else: res_data[frame_index] = handler.data if "SRCUR" in handler.header: - res_metadata.machine_electric_current.append( + res_metadata.machine_current.append( float(handler.header["SRCUR"]) ) if "CountTime" in handler.header: @@ -1527,7 +1546,7 @@ class TomoScanBase(TomoObject): res_metadata.count_time = count_time * unit_factor if ReducedFramesInfos.MACHINE_ELECT_CURRENT_KEY in parent_group: - machine_electric_current = silx.io.utils.h5py_read_dataset( + machine_current = silx.io.utils.h5py_read_dataset( parent_group[ ReducedFramesInfos.MACHINE_ELECT_CURRENT_KEY ] @@ -1539,8 +1558,8 @@ class TomoScanBase(TomoObject): ].attrs, metric_system=ElectricCurrentSystem, ) - res_metadata.machine_electric_current = ( - machine_electric_current * unit_factor + res_metadata.machine_current = ( + machine_current * unit_factor ) return res_data, res_metadata @@ -1552,9 +1571,9 @@ class TomoScanBase(TomoObject): if len(infos.count_time) not in (0, len(reduced_frames)): incoherent_metadata = True incoherent_metadata_mess += f"\n - count_time gets {len(infos.count_time)} when 0 or {len(reduced_frames)} expected" - if len(infos.machine_electric_current) not in (0, len(reduced_frames)): + if len(infos.machine_current) not in (0, len(reduced_frames)): incoherent_metadata = True - incoherent_metadata_mess += f"\n - machine_electric_current gets {len(infos.machine_electric_current)} when 0 or {len(reduced_frames)} expected" + incoherent_metadata_mess += f"\n - machine_current gets {len(infos.machine_current)} when 0 or {len(reduced_frames)} expected" if incoherent_metadata: raise ValueError(incoherent_metadata_mess) @@ -1572,7 +1591,7 @@ class TomoScanBase(TomoObject): :param darks: dictionary with frame indices as key (int) and a 2D numpy array as value. :param output_urls: tuple of silx DataUrl, where to save the darks. Default value is usually provided by children class directly. You better know what you are doing if you modify the default value. - :param darks_infos: information regarding darks (metadata) like the machine electric current, exposure time... + :param darks_infos: information regarding darks (metadata) like the machine current, exposure time... :param metadata_output_urls: tuple of silx DataUrl, where to save the metadata / darks information. Default value is usually provided by children class directly You better know what you are doing if you modify the default value. :param overwrtie: if the output files exist then will overwrite them. @@ -1586,7 +1605,7 @@ class TomoScanBase(TomoObject): scan = ... # scan must be an instance of TomoScanBase like NXtomoScan() darks_infos.count_time = [2.5] - darks_infos.machine_electric_current = [13.1] + darks_infos.machine_current = [13.1] scan.save_reduced_darks( darks={ 0: dark_frame, # dark_frame is a 2d numpy array @@ -1655,7 +1674,7 @@ class TomoScanBase(TomoObject): :param flats: dictionary with frame indices as key (int) and a 2D numpy array as value. :param output_urls: tuple of silx DataUrl, where to save the flats. Default value is usually provided by children class directly. You better know what you are doing if you modify the default value. - :param flats_infos: information regarding flats (metadata) like the machine electric current, exposure time... + :param flats_infos: information regarding flats (metadata) like the machine current, exposure time... :param metadata_output_urls: tuple of silx DataUrl, where to save the metadata / flats information. Default value is usually provided by children class directly You better know what you are doing if you modify the default value. :param overwrite: if the output files exist then will overwrite them. @@ -1670,9 +1689,9 @@ class TomoScanBase(TomoObject): scan = ... # scan must be an instance of TomoScanBase like NXtomoScan() flats_infos = ReducedFramesInfos() flats_infos.count_time = [2.5, 1.2] - flats_infos.machine_electric_current = [12.5, 13.1] - # for normalization the first reduced flat (at index 1) will have 2.5 as count time and 12.5 as machine electric current - # the second reduced flat frame (at index 1002) will have 1.2 as count time and 13.1 as machine electric current + flats_infos.machine_current = [12.5, 13.1] + # for normalization the first reduced flat (at index 1) will have 2.5 as count time and 12.5 as machine current + # the second reduced flat frame (at index 1002) will have 1.2 as count time and 13.1 as machine current scan.save_reduced_darks( darks={ 1: flat_frame_1, # flat_frame_1 is a 2d numpy array diff --git a/tomoscan/tests/test_scanbase.py b/tomoscan/tests/test_scanbase.py index bb6c24e3d0563c987d0aca8258d28d570139fb86..d2f93610794be87f71af258289d1a3f569818a2c 100644 --- a/tomoscan/tests/test_scanbase.py +++ b/tomoscan/tests/test_scanbase.py @@ -205,8 +205,8 @@ def test_ReducedFramesInfo(): assert infos.to_dict() == {} infos.count_time = numpy.array([12.3, 13.0]) assert infos.count_time == [12.3, 13.0] - infos.machine_electric_current = [23.5, 56.9] - assert infos.machine_electric_current == [23.5, 56.9] + infos.machine_current = [23.5, 56.9] + assert infos.machine_current == [23.5, 56.9] my_dict = deepcopy(infos.to_dict()) assert my_dict == { ReducedFramesInfos.COUNT_TIME_KEY: [12.3, 13.0], @@ -222,6 +222,6 @@ def test_ReducedFramesInfo(): with pytest.raises(TypeError): new_infos.count_time = 12 with pytest.raises(TypeError): - new_infos.machine_electric_current = 12 + new_infos.machine_current = 12 str(new_infos)