Skip to content

Commit

Permalink
Allow creation of png from 3D and 4D arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
bhilbert4 committed Mar 13, 2024
1 parent bd44bac commit 2d4b42d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions jwql/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ def create_png_from_fits(filename, outdir):
"""
if os.path.isfile(filename):
image = fits.getdata(filename)

# If the input file is a rateints/calints file, it will have 3 dimensions.
# If it is a file containing all groups, prior to ramp-fitting, it will have
# 4 dimensions. In this case, grab the appropriate 2D image to work with. For
# a 3D case, get the first integration. For a 4D case, get the last group
# (which will have the highest SNR).
ndim = len(image.shape)
if ndim == 2:
pass
elif ndim == 3:
image = image[0, :, :]
elif ndim == 4:
image = image[0, -1, :, :]
else:
raise ValueError(f'File {filename} has an unsupported number of dimensions: {ndim}.')

ny, nx = image.shape
img_mn, img_med, img_dev = sigma_clipped_stats(image[4: ny - 4, 4: nx - 4])

Expand Down

0 comments on commit 2d4b42d

Please sign in to comment.