Commit b5d67306 authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Merge branch 'dev_0_2' into 'master'

Dev 0 2

See merge request !8
parents e2a7e2f8 46bce5e6
Pipeline #21854 failed with stages
in 52 seconds
......@@ -38,7 +38,7 @@ import io
from typing import Union
from ..scanbase import TomoScanBase
from .utils import get_parameters_frm_par_or_info, extract_urls_from_edf
from ..unitsystem import metricsystem
from ..unitsystem.metricsystem import MetricSystem
from ..utils import docstring
import logging
......@@ -116,7 +116,7 @@ class EDFTomoScan(TomoScanBase):
:rtype: float
"""
if self.__pixel_size is None:
self.__pixel_size = EDFTomoScan.get_pixel_size(scan=self.path)
self.__pixel_size = EDFTomoScan._get_pixel_size(scan=self.path)
return self.__pixel_size
@property
......@@ -330,7 +330,10 @@ class EDFTomoScan(TomoScanBase):
if part_1 is None:
return None
if part_2 is None:
return int(part_1)
if part_1 is None:
return None
else:
return int(part_1)
else:
return float(part_1) + part_2
else:
......@@ -392,8 +395,34 @@ class EDFTomoScan(TomoScanBase):
return d1, d2
@property
@docstring(TomoScanBase.distance)
def distance(self) -> Union[None, float]:
if self.__distance is None:
self.__distance = EDFTomoScan.retrieve_information(self.path,
None, "Distance",
type_=float,
key_aliases=('distance', )
)
if self.__distance is None:
return None
else:
return self.__distance
@property
@docstring(TomoScanBase.energy)
def energy(self):
if self.__energy is None:
self.__energy = EDFTomoScan.retrieve_information(self.path,
None,
"Energy",
type_=float,
key_aliases=('energy', )
)
return self.__energy
@staticmethod
def get_pixel_size(scan: str) -> Union[None, int]:
def _get_pixel_size(scan: str) -> Union[None, float]:
if os.path.isdir(scan) is False:
return None
value = EDFTomoScan.retrieve_information(scan=scan,
......@@ -413,7 +442,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
else:
return None
......
......@@ -32,6 +32,7 @@ import os
import logging
from typing import Union
from collections import OrderedDict
from .unitsystem.metricsystem import MetricSystem
logger = logging.getLogger(__name__)
......@@ -141,9 +142,15 @@ class TomoScanBase:
raise NotImplementedError('Base class')
@property
def pixel_size(self) -> Union[None, int]:
def pixel_size(self) -> Union[None, float]:
raise NotImplementedError('Base class')
def get_pixel_size(self, unit='m') -> Union[None, float]:
if self.pixel_size:
return self.pixel_size / MetricSystem.from_value(unit)
else:
return None
@property
def dim_1(self) -> Union[None, int]:
raise NotImplementedError('Base class')
......@@ -160,6 +167,33 @@ class TomoScanBase:
def scan_range(self) -> Union[None, int]:
raise NotImplementedError('Base class')
@property
def energy(self) -> Union[None, float]:
"""
:return: incident beam energy in keV
"""
raise NotImplementedError('Base class')
@property
def distance(self) -> Union[None, float]:
"""
:return: sample / detector distance in meter
"""
raise NotImplementedError('Base class')
def get_distance(self, unit='m') -> Union[None, float]:
"""
:param Union[MetricSystem, str] unit: unit requested for the distance
:return: sample / detector distance with the requested unit
"""
if self.distance:
return self.distance / MetricSystem.from_value(unit).value
else:
return None
def update(self) -> None:
"""Parse the root folder and files to update informations"""
raise NotImplementedError("Base class")
......
......@@ -27,40 +27,54 @@ __license__ = "MIT"
__date__ = "01/09/2016"
from typing import Union
from silx.utils.enum import Enum as _Enum
meter = 1.0
m = meter
_meter = 1.0
centimeter = meter / 100.0
cm = centimeter
millimeter = 0.1 * centimeter
mm = millimeter
class MetricSystem(_Enum):
"""Util enum to retrieve metric"""
METER = _meter
m = _meter
CENTIMETER = _meter / 100.0
MILLIMETER = _meter / 1000.0
MICROMETER = _meter * 1e-6
NANOMETER = _meter * 1e-9
@classmethod
def from_value(cls, value):
if isinstance(value, str):
return cls.from_str(value=value)
else:
_Enum.from_value(value=value)
micrometer = 1e-6 * meter
@classmethod
def from_str(cls, value: str):
assert isinstance(value, str)
if value.lower() in ('m', 'meter'):
return MetricSystem.METER
elif value.lower() in ('cm', 'centimeter'):
return MetricSystem.CENTIMETER
elif value.lower() in ('mm', 'millimeter'):
return MetricSystem.MILLIMETER
elif value.lower() in ('micrometer'):
return MetricSystem.MICROMETER
elif value.lower() in ('nm', 'nanometer'):
return MetricSystem.NANOMETER
else:
raise ValueError("Cannot convert: %s" % value)
nanometer = 1e-9 * meter
nm = nanometer
mm2 = millimeter * millimeter
cm2 = centimeter * centimeter
m2 = meter * meter
m = MetricSystem.METER
meter = MetricSystem.METER
centimeter = MetricSystem.CENTIMETER
cm = centimeter
def getUnitName(value: Union[float, int]) -> str:
"""
:return: name in (None, nm, cm, m, mm) from the given unit
"""
if value == nanometer:
return 'nm'
if value == millimeter:
return 'mm'
if value == centimeter:
return 'cm'
if value == meter:
return 'm'
return None
millimeter = MetricSystem.MILLIMETER
mm = MetricSystem.MILLIMETER
micrometer = MetricSystem.MICROMETER
nanometer = MetricSystem.NANOMETER
......@@ -67,8 +67,8 @@ RELEASE_LEVEL_VALUE = {"dev": 0,
"final": 15}
MAJOR = 0
MINOR = 1
MICRO = 1
MINOR = 2
MICRO = 0
RELEV = "final" # <16
SERIAL = 0 # <16
......
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