Skip to content

Commit

Permalink
Merge pull request #589 from JensWendt/timestamp_fix
Browse files Browse the repository at this point in the history
implemented get_timestamps() from timeIncrement attribute
  • Loading branch information
will-moore authored Oct 3, 2024
2 parents 8a70fe9 + 6da129e commit d07375a
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions omero_figure/omeroutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from omero.sys import ParametersI
from omero.gateway import PlaneInfoWrapper
from omero.model.enums import UnitsTime
from omero.model import TimeI


def get_timestamps(conn, image):
Expand All @@ -28,13 +30,34 @@ def get_timestamps(conn, image):
info_list = conn.getQueryService().findAllByQuery(
query, params, conn.SERVICE_OPTS)
timemap = {}
for info in info_list:
t_index = info.theT.getValue()
if info.deltaT is not None:
# Use wrapper to help unit conversion
plane_info = PlaneInfoWrapper(conn, info)
delta_t = plane_info.getDeltaT('SECOND')
timemap[t_index] = delta_t.getValue()
# check if any PlaneInfo was found
if len(info_list) > 0:
# get time info from the PlaneInfo
for info in info_list:
t_index = info.theT.getValue()
if info.deltaT is not None:
# Use wrapper to help unit conversion
plane_info = PlaneInfoWrapper(conn, info)
delta_t = plane_info.getDeltaT('SECOND')
timemap[t_index] = delta_t.getValue()
# double check to see if timemap actually got populated
if len(info_list) == 0 or len(timemap) == 0:
# get time info from the timeIncrement of the Pixels
time_increment = 0
converted_value = 0
try:
pixels = image.getPrimaryPixels()._obj
time_increment = pixels.getTimeIncrement()
secs_unit = getattr(UnitsTime, "SECOND")
seconds = TimeI(time_increment, secs_unit)
converted_value = seconds.getValue()

except Exception as error:
print(f"An exception occured: {error}\n"
"maybe the image has no 'timeIncrement' set")
if converted_value != 0:
for i in range(image.getSizeT()):
timemap[i] = i*converted_value
time_list = []
for t in range(image.getSizeT()):
if t in timemap:
Expand Down

0 comments on commit d07375a

Please sign in to comment.