Skip to content

Commit

Permalink
handle masking
Browse files Browse the repository at this point in the history
  • Loading branch information
kbwestfall committed Feb 13, 2025
1 parent 6f98a44 commit a2917ad
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ccdproc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,18 +818,25 @@ def flat_correct(ccd, flat, min_value=None, norm_value=None):

# If a norm_value was input and is positive, use it to scale the flat
if norm_value is not None and norm_value > 0:
flat_mean_val = norm_value
flat_mean = norm_value if hasattr(norm_value, 'unit') else norm_value * use_flat.unit
elif norm_value is not None:
# norm_value was set to a bad value
raise ValueError("norm_value must be greater than zero.")
else:
# norm_value was not set, use mean of the image.
flat_mean_val = use_flat.data.mean()
flat_mean = use_flat.mean()

# Normalize the flat.
flat_mean = flat_mean_val * use_flat.unit
flat_normed = use_flat.divide(flat_mean)

# TODO: Check that the normed flat is unitless?

# Set masked values to unity; the array element remains masked, but the data
# value is set to unity to avoid runtime divide-by-zero errors that are due
# to a masked value being set to 0.
if flat_normed.mask.any():
flat_normed.data[flat_normed.mask] = 1.

# divide through the flat
flat_corrected = ccd.divide(flat_normed)

Expand Down

0 comments on commit a2917ad

Please sign in to comment.