Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions hips/draw/paint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import time
import warnings
import numpy as np
from typing import List, Tuple, Union, Dict, Any
from astropy.wcs.utils import proj_plane_pixel_scales
Expand Down Expand Up @@ -142,6 +143,8 @@ def warp_image(self, tile: HipsTile) -> np.ndarray:
self.projection(tile),
output_shape=self.geometry.shape,
preserve_range=True,
mode="constant",
cval=np.nan,
)

def run(self) -> np.ndarray:
Expand Down Expand Up @@ -187,7 +190,7 @@ def _make_empty_sky_image(self):
height=self.geometry.shape.height,
fmt=self.tile_format,
)
return np.zeros(shape, dtype=np.float32)
return np.full(shape, fill_value=np.nan, dtype=np.float32)

def draw_all_tiles(self):
"""Make an empty sky image and draw all the tiles."""
Expand All @@ -200,9 +203,12 @@ def draw_all_tiles(self):

for tile in tiles:
tile_image = self.warp_image(tile)
# TODO: put better algorithm here instead of summing pixels
# this can lead to pixels that are painted twice and become to bright
image += tile_image
with warnings.catch_warnings():
warnings.filterwarnings("ignore",
message="All-NaN slice encountered",
category=RuntimeWarning,
)
image = np.nanmedian(np.stack([image, tile_image]), axis=0)

# Store the result
self.float_image = image
Expand Down
7 changes: 3 additions & 4 deletions hips/draw/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,12 @@ def write_image(self, filename: str, overwrite: bool = False) -> None:
overwrite : bool
Overwrite the output file, if it exists
"""
if overwrite == False and Path(filename).exists():
raise FileExistsError(f"File {filename} already exists.")

if self.tile_format == 'fits':
hdu = fits.PrimaryHDU(data=self.image, header=self.geometry.fits_header)
hdu.writeto(filename)
hdu.writeto(filename, overwrite=overwrite)
else:
if overwrite is False and Path(filename).exists():
raise FileExistsError(f"File {filename} already exists.")
image = Image.fromarray(self.image)
image.save(filename)

Expand Down