Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-commons
Commits
b29c39d3
Commit
b29c39d3
authored
Oct 28, 2024
by
Wei Shoulin
Browse files
add compute_ra_dec_range
parent
f59adb80
Changes
1
Hide whitespace changes
Inline
Side-by-side
csst_dfs_commons/utils/fits.py
View file @
b29c39d3
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment