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
30 changes: 26 additions & 4 deletions tilemaker/processing/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def extract(
metadata: DataConfiguration,
grants: set[str],
show_grid: bool = False,
) -> tuple[np.array, list[PushableTile]]:
) -> tuple[np.array, list[PushableTile], WCS]:
"""
Extract a sub-map from a band between RA and Dec ranges (in degrees).

Expand Down Expand Up @@ -84,11 +84,11 @@ def extract(
wcs = WCS(
{
"NAXIS": 2,
"NAXIS1": NAXIS1,
"NAXIS2": NAXIS2,
"CRPIX1": NAXIS1 * 0.5,
"CRPIX2": NAXIS2 * 0.5 + 0.5,
"CRVAL1": 0.0,
"NAXIS1": NAXIS1,
"NAXIS2": NAXIS2,
"CRVAL2": 0.0,
"CDELT1": CDELT_RA,
"CDELT2": -CDELT_DEC,
Expand Down Expand Up @@ -197,4 +197,26 @@ def extract(

log = log.info("extractor.complete")

return buffer, pushables
# Create WCS for submap; note that only CRPIX and NAXIS change
submap_wcs = WCS(
{
"NAXIS": 2,
"NAXIS1": x_size,
"NAXIS2": y_size,
"CRPIX1": wcs.wcs.crpix[0] - left_pix,
"CRPIX2": wcs.wcs.crpix[1] - bottom_pix,
"CRVAL1": wcs.wcs.crval[0],
"CRVAL2": wcs.wcs.crval[1],
"CDELT1": wcs.wcs.cdelt[0],
"CDELT2": wcs.wcs.cdelt[1],
"CTYPE1": "RA---CAR",
"CTYPE2": "DEC--CAR",
"CUNIT1": "deg",
"CUNIT2": "deg",
"LONPOLE": 90.0,
"LATPOLE": 0.0,
"RADESYS": "ICRS",
}
)

return buffer, pushables, submap_wcs
5 changes: 3 additions & 2 deletions tilemaker/server/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_submap(
Get a submap of the specified band.
"""

submap, pushables = extract(
submap, pushables, wcs = extract(
layer_id=layer_id,
left=left,
right=right,
Expand Down Expand Up @@ -186,7 +186,8 @@ def get_submap(
return Response(content=output.getvalue(), media_type="image/png")
elif ext == "fits":
with io.BytesIO() as output:
hdu = fits.PrimaryHDU(submap)
header = wcs.to_header()
hdu = fits.PrimaryHDU(submap, header=header)
hdu.writeto(output)
return Response(content=output.getvalue(), media_type="image/fits")

Expand Down
Loading