Skip to content

Commit

Permalink
fixed loading uwo state files with no magick type
Browse files Browse the repository at this point in the history
  • Loading branch information
dvida committed Sep 1, 2023
1 parent b0c54e5 commit 67eda95
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
56 changes: 37 additions & 19 deletions RMS/Formats/FrameInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
from RMS.Routines.DynamicFTPCompressionCy import FFMimickInterface


# ConstantsO
UWO_MAGICK_CAMO = 1144018537
UWO_MAGICK_EMCCD = 1141003881
UWO_MAGICK_ASGARD = 38037846


def getCacheID(first_frame, size):
""" Get the frame chunk ID. """

Expand Down Expand Up @@ -1217,6 +1223,8 @@ def currentFrameTime(self, frame_no=None, dt_obj=False):
return (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond/1000)




class InputTypeImages(object):
def __init__(self, dir_path, config, beginning_time=None, fps=None, detection=False):
""" Input file type handle for a folder with images.
Expand Down Expand Up @@ -1317,30 +1325,14 @@ def __init__(self, dir_path, config, beginning_time=None, fps=None, detection=Fa
### Try to detect if the given images are UWO-style PNGs ###

self.uwo_png_mode = False
self.uwo_magick_type = None

# Load the first image
img = self.loadFrame(fr_no=0)

# Read in the magick number as a uint32
magicknum = np.frombuffer(img[0], dtype=np.uint32)[0]

# Define the magick numbers for different UWO PNGs
magicknum_camo = 1144018537
magicknum_emccd = 1141003881
magicknum_asgard = 38037846
uwo_magick_num_list = [magicknum_camo, magicknum_emccd, magicknum_asgard]

# Check the magick number for UWO PNGs
if magicknum in uwo_magick_num_list:
# Get the magick type
self.uwo_magick_type = self.getUWOMagickType(img)

# Set the magick type
if magicknum == magicknum_camo:
self.uwo_magick_type = "camo"
elif magicknum == magicknum_emccd:
self.uwo_magick_type = "emccd"
elif magicknum == magicknum_asgard:
self.uwo_magick_type = "asgard"
if self.uwo_magick_type is not None:

self.uwo_png_mode = True

Expand Down Expand Up @@ -1960,6 +1952,32 @@ def currentFrameTime(self, frame_no=None, dt_obj=False):

else:
return (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond/1000)


def getUWOMagickType(self, img):
""" Return the type of the UWO PNG image. """

# Read in the magick number as a uint32
magicknum = np.frombuffer(img[0], dtype=np.uint32)[0]

# Define the magick numbers for different UWO PNGs
uwo_magick_num_list = [UWO_MAGICK_CAMO, UWO_MAGICK_EMCCD, UWO_MAGICK_ASGARD]

# Check the magick number for UWO PNGs
if magicknum in uwo_magick_num_list:

# Set the magick type
if magicknum == UWO_MAGICK_CAMO:
uwo_magick_type = "camo"
elif magicknum == UWO_MAGICK_EMCCD:
uwo_magick_type = "emccd"
elif magicknum == UWO_MAGICK_ASGARD:
uwo_magick_type = "asgard"

return uwo_magick_type

else:
return None


class InputTypeDFN(InputType):
Expand Down
13 changes: 13 additions & 0 deletions Utils/SkyFit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,19 @@ def loadState(self, dir_path, state_name, beginning_time=None):
if not hasattr(self.img_handle, "cabernet_status"):
self.img_handle.cabernet_status = False

# Make sure an option is not missing from the UWO png mode
if self.img_handle.input_type == 'images':
if self.img_handle.uwo_png_mode:

if not hasattr(self.img_handle, "uwo_magick_type"):

# Load the first image
img = self.img_handle.loadFrame(fr_no=0)

# Get the magick type
self.img_handle.uwo_magick_type = self.img_handle.getUWOMagickType(img)


# Update possibly missing input_path variable
if not hasattr(self, "input_path"):
self.input_path = dir_path
Expand Down

0 comments on commit 67eda95

Please sign in to comment.