Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make image processing match existing method elsewhere #533

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions extensions/skyportal/skyportal/handlers/api/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,15 +1629,17 @@ async def get(self, object_id: str = None):
with gzip.open(io.BytesIO(cutout_data), "rb") as f:
with fits.open(io.BytesIO(f.read())) as hdu:
data = hdu[0].data
medfill = np.nanmedian(data.flatten())
median = np.nanmedian(data.flatten())
if (
medfill == np.nan
or medfill == -np.inf
or medfill == np.inf
median == np.nan
or median == -np.inf
or median == np.inf
):
image_corrupt = True

cutout_dict[cutout] = np.nan_to_num(data, nan=medfill)
# fill nans with zeros
cutout_dict[cutout] = np.nan_to_num(data)

# normalize
if normalize_image and not image_corrupt:
cutout_dict[cutout] /= np.linalg.norm(
Expand All @@ -1650,12 +1652,12 @@ async def get(self, object_id: str = None):
# pad to 63x63 if smaller
shape = cutout_dict[cutout].shape
if shape != (63, 63):
medfill = np.nanmedian(cutout_dict[cutout].flatten())
# pad empty rows/cols with 1e-9
cutout_dict[cutout] = np.pad(
cutout_dict[cutout],
[(0, 63 - shape[0]), (0, 63 - shape[1])],
mode="constant",
constant_values=medfill,
constant_values=1e-9,
)
triplet = np.zeros((63, 63, 3))
triplet[:, :, 0] = cutout_dict["science"]
Expand Down
Loading