def parse_known_metadata(self) -> ImageMetadata: imd = super().parse_known_metadata() sis_metadata = self._parsed_sis_metadata imd.acquisition_datetime = sis_metadata.get('datetime') physical_size_x = sis_metadata.get('pixelsizex') if physical_size_x: imd.physical_size_x = physical_size_x * UNIT_REGISTRY('meters') physical_size_y = sis_metadata.get('pixelsizey') if physical_size_y: imd.physical_size_y = physical_size_y * UNIT_REGISTRY('meters') imd.objective.nominal_magnification = sis_metadata.get('magnification') return imd
def parse_ome_physical_size(physical_size: Optional[float], unit: Optional[str]) -> Optional[Quantity]: if unit is None: unit = 'µm' if physical_size in [None, 0] or unit in ['pixel', 'reference frame']: return None return physical_size * UNIT_REGISTRY(unit)
def parse_frame_rate(time_increment: Optional[float], unit: Optional[str]) -> Optional[Quantity]: if unit is None: unit = 's' if time_increment in [None, 0]: return None return 1 / (time_increment * UNIT_REGISTRY(unit))
def parse_physical_size(physical_size: Optional[int], unit: Optional[str]) -> Optional[Quantity]: supported_units = ("meters", "inches", "cm") if physical_size is not None and parse_float(physical_size) is not None \ and unit in supported_units: return parse_float(physical_size) * UNIT_REGISTRY(unit) return None
def parse_physical_size(physical_size: Optional[str], unit: Optional[str], inverse: bool) -> Optional[Quantity]: supported_units = {1: "meter", 2: "inch"} if type(unit) == str: supported_units = {"meters": "meter", "inches": "inch"} if physical_size is not None and parse_float(physical_size) is not None \ and unit in supported_units.keys(): physical_size = parse_float(physical_size) if inverse: physical_size = 1 / physical_size return physical_size * UNIT_REGISTRY(supported_units[unit]) return None
def parse_physical_size( physical_size: Union[Tuple, float], unit: Optional[tifffile.TIFF.RESUNIT] = None ) -> Union[Quantity, None]: """ Parse a physical size and its unit from a TiffTag to a Quantity. """ if not unit or physical_size is None: return None if type(physical_size) == tuple and len(physical_size) == 1: rational = (physical_size[0], 1) elif type(physical_size) != tuple: rational = (physical_size, 1) else: rational = physical_size if rational[0] == 0: return None return rational[1] / rational[0] * UNIT_REGISTRY(unit.name.lower())
def parse_physical_size(physical_size: str) -> Optional[Quantity]: if physical_size is not None and parse_float( physical_size) is not None: return parse_float(physical_size) * UNIT_REGISTRY("millimeter") return None
def parse_physical_size( physical_size: Optional[str]) -> Optional[Quantity]: if physical_size is not None and parse_float(physical_size) not in ( None, 0.0): return 1 / parse_float(physical_size) * UNIT_REGISTRY("meters") return None