Skip to content

Commit

Permalink
expand OME metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tienday committed Feb 1, 2024
1 parent 2533781 commit 8a61d52
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
5 changes: 4 additions & 1 deletion studio/app/optinist/microscopes/IsxdReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
)

Expand Down
14 changes: 6 additions & 8 deletions studio/app/optinist/microscopes/MicroscopeDataReaderBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 20 additions & 5 deletions studio/app/optinist/microscopes/ND2Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import platform
import re
from enum import Enum, IntEnum

import numpy as np
Expand Down Expand Up @@ -167,22 +168,33 @@ 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(
image_name=original_metadata["data_name"],
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,
)

Expand Down Expand Up @@ -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変数構築
# ----------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions studio/app/optinist/microscopes/OIRReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
)

Expand Down

0 comments on commit 8a61d52

Please sign in to comment.