-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,32 @@ | ||
import astropy.units as u | ||
import healpy as hp | ||
import matplotlib | ||
import numpy as np | ||
from astropy import coordinates | ||
from astropy_healpix import HEALPix | ||
from mocpy import MOC | ||
from astropy.coordinates import ICRS, SkyCoord | ||
from mocpy import MOC, mocpy | ||
from tqdm import tqdm | ||
|
||
|
||
def getRegionPixels( | ||
ra_pointing, | ||
dec_pointing, | ||
regions, | ||
nside, | ||
): | ||
theta = 0.5 * np.pi - np.deg2rad(dec_pointing) | ||
phi = np.deg2rad(ra_pointing) | ||
def get_region_moc(ra, dec, regions, max_depth=12, n_threads=None): | ||
|
||
HPX = HEALPix(nside=nside, order="nested", frame=coordinates.ICRS()) | ||
|
||
skyoffset_frames = coordinates.SkyCoord( | ||
ra_pointing, dec_pointing, unit=u.deg | ||
).skyoffset_frame() | ||
|
||
moc = None | ||
|
||
# security for the periodic limit conditions | ||
for reg in regions: | ||
ra_tmp = reg.vertices.ra | ||
dec_tmp = reg.vertices.dec | ||
|
||
coords = np.stack([np.array(ra_tmp), np.array(dec_tmp)]) | ||
|
||
# Copy the tile coordinates such that there is one per field | ||
# in the grid | ||
coords_icrs = coordinates.SkyCoord( | ||
*np.tile(coords[:, np.newaxis, ...], (1, 1, 1)), | ||
unit=u.deg, | ||
frame=skyoffset_frames[:, np.newaxis, np.newaxis], | ||
).transform_to(coordinates.ICRS) | ||
coords = coords_icrs.transform_to(HPX.frame) | ||
|
||
if moc is None: | ||
moc = MOC.from_polygon_skycoord(coords) | ||
else: | ||
moc = moc + MOC.from_polygon_skycoord(coords) | ||
|
||
return moc | ||
skyoffset_frames = SkyCoord(ra, dec, unit=u.deg).skyoffset_frame() | ||
coords_icrs = SkyCoord( | ||
*np.tile(coords[:, np.newaxis, ...], (1, 1, 1)), | ||
unit=u.deg, | ||
frame=skyoffset_frames[:, np.newaxis, np.newaxis], | ||
).transform_to(ICRS) | ||
|
||
mocs = [] | ||
for ccd_coords in tqdm(coords_icrs): | ||
stacked = np.stack((ccd_coords.ra.deg, ccd_coords.dec.deg), axis=1) | ||
result = stacked.reshape(-1, ccd_coords.ra.deg.shape[1]) | ||
lon_lat_list = [row for row in result] | ||
indices = mocpy.from_polygons(lon_lat_list, np.uint8(max_depth), n_threads) | ||
moc = sum([MOC(index) for index in indices]) | ||
mocs.append(moc) | ||
|
||
return mocs |