Commit 916eec6f authored by payno's avatar payno
Browse files

Merge branch 'add_hdf5' of gitlab.esrf.fr:tomotools/tomoscan into add_hdf5

parents e1168a73 15f8b707
Pipeline #21904 passed with stages
in 2 minutes and 8 seconds
......@@ -85,8 +85,10 @@ class EDFTomoScan(TomoScanBase):
self.__scan_range = None
self._edf_n_frames = n_frames
self.__distance = None
self.__energy = None
self.update()
@docstring(TomoScanBase.clear_caches)
def clear_caches(self):
self._darks = None
......@@ -422,7 +424,7 @@ class EDFTomoScan(TomoScanBase):
if self.__distance is None:
return None
else:
return self.__distance
return self.__distance * MetricSystem.MILLIMETER.value
@property
@docstring(TomoScanBase.energy)
......@@ -457,7 +459,7 @@ class EDFTomoScan(TomoScanBase):
# for now pixel size are stored in microns.
# We want to return them in meter
if value is not None:
return value * MetricSystem.MICROMETER
return value * MetricSystem.MICROMETER.value
else:
return None
......
......@@ -90,6 +90,8 @@ class HDF5TomoScan(TomoScanBase):
_DISTANCE_PATH = 'instrument/detector/distance'
_ENERGY_PATH = 'beam/incident_energy'
_SCHEME = 'silx'
_EPSILON_ROT_ANGLE = 0.02
......@@ -148,6 +150,7 @@ class HDF5TomoScan(TomoScanBase):
self._image_keys = None
self._rotation_angles = None
self._distance = None
self._energy = None
@staticmethod
def get_master_file(scan_path):
......@@ -483,6 +486,15 @@ class HDF5TomoScan(TomoScanBase):
self._distance = self._get_value(distance_dataset, default_unit='m')
return self._distance
@property
def energy(self) -> typing.Union[None, float]:
if (self._energy is None and self.master_file and
os.path.exists(self.master_file)):
with h5py.File(self.master_file, 'r') as h5_file:
energy_dataset = h5_file[self._entry][self._ENERGY_PATH]
self._energy = self._get_value(energy_dataset, default_unit='keV')
return self._energy
@property
def frames(self) -> typing.Union[None, tuple]:
"""return tuple of frames. Frames contains """
......
......@@ -29,9 +29,50 @@ __date__ = "01/09/2016"
from silx.utils.enum import Enum as _Enum
# Constants
_elementary_charge_coulomb = 1.602176634e-19
_meter = 1.0
_joule_si = 1.0
class EnergySI(_Enum):
"""Util enum for energy in SI units (Joules)"""
JOULE = _joule_si
ELEMCHARGE = _elementary_charge_coulomb
ELECTRONVOLT = _elementary_charge_coulomb
KILOELECTRONVOLT = _elementary_charge_coulomb * 1e3
KILOJOULE = 1e3 * _joule_si
@classmethod
def from_value(cls, value):
if isinstance(value, str):
return cls.from_str(value=value)
else:
_Enum.from_value(value=value)
@classmethod
def from_str(cls, value: str):
assert isinstance(value, str)
if value.lower() in ('e', 'qe'):
return EnergySI.ELEMCHARGE
elif value.lower() in ("j", "joule"):
return EnergySI.JOULE
elif value.lower() in ("kj", "kilojoule"):
return EnergySI.KILOJOULE
elif value.lower() in ("ev", "electronvolt"):
return EnergySI.ELECTRONVOLT
elif value.lower() in ("kev", "kiloelectronvolt"):
return EnergySI.KILOELECTRONVOLT
else:
raise ValueError("Cannot convert: %s" % value)
# Default units:
# - lenght: meter (m)
# - energy: kilo Electronvolt (keV)
_meter = 1.0
_kev = 1.0
_joule_kev = 1./EnergySI.KILOELECTRONVOLT.value
class MetricSystem(_Enum):
"""Util enum to retrieve metric"""
......@@ -42,6 +83,12 @@ class MetricSystem(_Enum):
MICROMETER = _meter * 1e-6
NANOMETER = _meter * 1e-9
KILOELECTRONVOLT = _kev
ELECTRONVOLT = _kev * 1e-3
JOULE = _kev / EnergySI.KILOELECTRONVOLT.value
KILOJOULE = _kev / EnergySI.KILOELECTRONVOLT.value * 1e3
@classmethod
def from_value(cls, value):
if isinstance(value, str):
......@@ -62,6 +109,14 @@ class MetricSystem(_Enum):
return MetricSystem.MICROMETER
elif value.lower() in ('nm', 'nanometer'):
return MetricSystem.NANOMETER
elif value.lower() in ('kev', 'kiloelectronvolt'):
return MetricSystem.KILOELECTRONVOLT
elif value.lower() in ('ev', 'electronvolt'):
return MetricSystem.ELECTRONVOLT
elif value.lower() in ('j', 'joule'):
return MetricSystem.JOULE
elif value.lower() in ('kj', 'kilojoule'):
return MetricSystem.KILOJOULE
else:
raise ValueError("Cannot convert: %s" % value)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment