diff --git a/studio/app/optinist/microscopes/IsxdReader.py b/studio/app/optinist/microscopes/IsxdReader.py index 1e62e6b93..c0bc36415 100644 --- a/studio/app/optinist/microscopes/IsxdReader.py +++ b/studio/app/optinist/microscopes/IsxdReader.py @@ -71,7 +71,10 @@ def _build_ome_metadata(self, original_metadata: dict) -> OMEDataModel: size_x=spacing["width"], size_y=spacing["height"], size_t=timing["num_samples"], - size_c=0, + size_z=0, # Note: currently unsettled + size_c=0, # Note: currently unsettled + acquisition_date=timing["start"], + objective_model=None, # Note: currently unsettled fps=(1000 / timing["period_msec"]), ) diff --git a/studio/app/optinist/microscopes/MicroscopeDataReaderBase.py b/studio/app/optinist/microscopes/MicroscopeDataReaderBase.py index ff4dead87..2006126ec 100644 --- a/studio/app/optinist/microscopes/MicroscopeDataReaderBase.py +++ b/studio/app/optinist/microscopes/MicroscopeDataReaderBase.py @@ -12,14 +12,12 @@ class OMEDataModel: image_name: str size_x: int # width size_y: int # height - size_t: int # time - size_c: int # TODO: 要確認 - fps: int # frames_per_second # TODO: OME標準の類似項目に合わせる - - # TODO: 以下今後追加想定 - # SizeZ: int - # AcquisitionDate: date - # Instrument/(Laser|Detector): str + size_t: int # time frames + size_z: int # axis z frames + size_c: int # channels + acquisition_date: str + objective_model: str # objective lens model + fps: int # frames_per_second # Note: extended from OME format class MicroscopeDataReaderBase(metaclass=ABCMeta): diff --git a/studio/app/optinist/microscopes/ND2Reader.py b/studio/app/optinist/microscopes/ND2Reader.py index 76e4f09c0..0a12ccef1 100644 --- a/studio/app/optinist/microscopes/ND2Reader.py +++ b/studio/app/optinist/microscopes/ND2Reader.py @@ -2,6 +2,7 @@ import json import os import platform +import re from enum import Enum, IntEnum import numpy as np @@ -167,14 +168,22 @@ def _build_ome_metadata(self, original_metadata: dict) -> OMEDataModel: """ attributes = original_metadata["attributes"] + metadata = original_metadata["metadata"] + textinfo = original_metadata["textinfo"] experiments = original_metadata["experiments"] + first_experiment_parameters = experiments[0]["parameters"] + metadata_ch0_microscope = metadata["channels"][0]["microscope"] # experiment, periods, の参照は先頭データの内容から取得 - if (experiments is not None) and ("periods" in experiments[0]["parameters"]): - period_ms = float(experiments[0]["parameters"]["periods"][0]["periodMs"]) - fps = (1000 / period_ms) if period_ms > 0 else 0 + if "periods" in first_experiment_parameters: + try: + fps = ( + 1000 + / first_experiment_parameters["periods"][0]["periodDiff"]["avg"] + ) + except: # noqa: E722 + fps = 1000 / first_experiment_parameters["periodDiff"]["avg"] else: - period_ms = 0 fps = 0 omeData = OMEDataModel( @@ -182,7 +191,10 @@ def _build_ome_metadata(self, original_metadata: dict) -> OMEDataModel: size_x=attributes["widthPx"], size_y=attributes["heightPx"], size_t=attributes["sequenceCount"], - size_c=0, + size_z=0, # size_z は後続処理で計算・設定する + size_c=len(metadata["channels"]), + acquisition_date=re.sub(" +", " ", textinfo["date"]), + objective_model=metadata_ch0_microscope.get("objectiveName", None), fps=fps, ) @@ -223,6 +235,9 @@ def _build_lab_specific_metadata(self, original_metadata: dict) -> dict: z_slicenum = experiments[0]["count"] z_interval = experiments[0]["parameters"]["stepUm"] + # ※ome_metadata の一部項目をアップデート + self.ome_metadata.size_z = z_slicenum + # ---------------------------------------- # Lab固有metadata変数構築 # ---------------------------------------- diff --git a/studio/app/optinist/microscopes/OIRReader.py b/studio/app/optinist/microscopes/OIRReader.py index 5fda8cbaa..429f5dcba 100644 --- a/studio/app/optinist/microscopes/OIRReader.py +++ b/studio/app/optinist/microscopes/OIRReader.py @@ -207,6 +207,9 @@ def _build_ome_metadata(self, original_metadata: dict) -> OMEDataModel: rect = original_metadata["rect"] axis_info = original_metadata["axis_info"] + channel_info = original_metadata["channel_info"] + objective_lens_info = original_metadata["objective_lens_info"] + file_creation_time = original_metadata["file_creation_time"] # get sequence counts # Note: Use the largest sequence count for each axis. @@ -215,14 +218,24 @@ def _build_ome_metadata(self, original_metadata: dict) -> OMEDataModel: axes_sequence_counts.append(axis["max"]) sequence_count = max(axes_sequence_counts) - fps = 0 # TODO: 今後計算対象予定 + # get axis z frame count + nZLoop = axis_info["ZSTACK"]["max"] if "ZSTACK" in axis_info else 1 + + # get fps + # TODO: fps の取得には、FrameManager経由 + # (FrameManager.m_vecAxisPosition[].GetPosition) での + # アクセスが必要となる模様. 今後計算対象予定. + fps = 0 omeData = OMEDataModel( image_name=original_metadata["data_name"], size_x=rect["width"], size_y=rect["height"], size_t=sequence_count, - size_c=0, + size_z=nZLoop, + size_c=len(channel_info), + acquisition_date=file_creation_time["creation_time"], + objective_model=objective_lens_info["name"], fps=fps, )