Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 55 additions & 56 deletions src/imcflibs/imagej/omerotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,68 +226,67 @@
# Fetch the dataset from the OMERO server using the provided dataset ID
return client.getDataset(Long(dataset_id))

def get_acquisition_metadata(user_client, image_wpr):
"""Get acquisition metadata from OMERO based on an image ID.

Parameters
----------
user_client : fr.igred.omero.Client
Client used for login to OMERO
image_wpr : fr.igred.omero.repositor.ImageWrapper
Wrapper to the image for the metadata

Returns
-------
dict

{
objective_magnification : float,
objective_na : float,
acquisition_date : str,
acquisition_date_number : str,
}
"""
ctx = user_client.getCtx()
instrument_data = (
user_client.getGateway()
.getMetadataService(ctx)
.loadInstrument(image_wpr.asDataObject().getInstrumentId())
)
objective_data = instrument_data.copyObjective().get(0)
metadata = {}

metadata["objective_magnification"] = (
objective_data.getNominalMagnification().getValue()
if objective_data.getNominalMagnification() is not None
else 0
)
metadata["objective_na"] = (
objective_data.getLensNA().getValue()
if objective_data.getLensNA() is not None
else 0
)
def get_acquisition_metadata(user_client, image_wpr):
"""Get acquisition metadata from OMERO based on an image ID.

if image_wpr.getAcquisitionDate() is None:
if image_wpr.asDataObject().getFormat() == "ZeissCZI":
field = "Information|Document|CreationDate"
date_field = get_info_from_original_metadata(
user_client, image_wpr, field
)
metadata["acquisition_date"] = date_field.split("T")[0]
metadata["acquisition_date_number"] = int(
metadata["acquisition_date"].replace("-", "")
)
else:
metadata["acquisition_date"] = "NA"
metadata["acquisition_date_number"] = 0
else:
sdf = SimpleDateFormat("yyyy-MM-dd")
metadata["acquisition_date"] = sdf.format(image_wpr.getAcquisitionDate())
Parameters

Check warning on line 233 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L233

Added line #L233 was not covered by tests
----------
user_client : fr.igred.omero.Client
Client used for login to OMERO

Check warning on line 236 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L236

Added line #L236 was not covered by tests
image_wpr : fr.igred.omero.repositor.ImageWrapper
Wrapper to the image for the metadata

Returns
-------
dict

{
objective_magnification : float,
objective_na : float,
acquisition_date : str,
acquisition_date_number : str,
}
"""
ctx = user_client.getCtx()
instrument_data = (
user_client.getGateway()
.getMetadataService(ctx)
.loadInstrument(image_wpr.asDataObject().getInstrumentId())
)
objective_data = instrument_data.copyObjective().get(0)
metadata = {}

Check warning on line 258 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L257-L258

Added lines #L257 - L258 were not covered by tests

metadata["objective_magnification"] = (
objective_data.getNominalMagnification().getValue()
if objective_data.getNominalMagnification() is not None
else 0
)

Check warning on line 264 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L263-L264

Added lines #L263 - L264 were not covered by tests
metadata["objective_na"] = (
objective_data.getLensNA().getValue()

Check warning on line 266 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L266

Added line #L266 was not covered by tests
if objective_data.getLensNA() is not None
else 0
)

if image_wpr.getAcquisitionDate() is None:

Check warning on line 271 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L271

Added line #L271 was not covered by tests
if image_wpr.asDataObject().getFormat() == "ZeissCZI":
field = "Information|Document|CreationDate"
date_field = get_info_from_original_metadata(user_client, image_wpr, field)
metadata["acquisition_date"] = date_field.split("T")[0]
metadata["acquisition_date_number"] = int(
metadata["acquisition_date"].replace("-", "")
)
else:
metadata["acquisition_date"] = "NA"
metadata["acquisition_date_number"] = 0
else:

Check warning on line 282 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L279-L282

Added lines #L279 - L282 were not covered by tests
sdf = SimpleDateFormat("yyyy-MM-dd")
metadata["acquisition_date"] = sdf.format(image_wpr.getAcquisitionDate())
metadata["acquisition_date_number"] = int(
metadata["acquisition_date"].replace("-", "")
)

Check warning on line 287 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L286-L287

Added lines #L286 - L287 were not covered by tests

return metadata
return metadata

Check warning on line 289 in src/imcflibs/imagej/omerotools.py

View check run for this annotation

Codecov / codecov/patch

src/imcflibs/imagej/omerotools.py#L289

Added line #L289 was not covered by tests


def get_info_from_original_metadata(user_client, image_wpr, field):
Expand Down
Loading