Commit b29c39d3 authored by Wei Shoulin's avatar Wei Shoulin
Browse files

add compute_ra_dec_range

parent f59adb80
......@@ -3,6 +3,7 @@ from astropy.coordinates import ICRS
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.io import fits
from astropy import wcs
from csst_dfs_commons.models.constants import PI, DEFAULT_NSIDE
......@@ -110,3 +111,27 @@ def dfs_heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec', br
whereSql = f"{distance} <= 4*pow(pi()*{radius}/180.0/2, 2) and {whereZoneSql}"
return whereSql
def compute_ra_dec_range(hdulist):
header = hdulist[1].header
fits_wcs = wcs.WCS(header)
# Get the shape of the data
naxis1 = header['NAXIS1']
naxis2 = header['NAXIS2']
# Get the pixel coordinates of all corners
corners = [(0, 0), (naxis1, 0), (naxis1, naxis2), (0, naxis2)]
# Convert pixel coordinates of corners to RA and Dec
corners_coords = fits_wcs.all_pix2world(corners, 0)
# Extract RA and Dec values
ras = [coord[0] for coord in corners_coords]
decs = [coord[1] for coord in corners_coords]
# Compute the min and max of RA and Dec
min_ra, max_ra = min(ras), max(ras)
min_dec, max_dec = min(decs), max(decs)
return min_ra, max_ra, min_dec, max_dec
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment