-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
122 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import logging | ||
import os | ||
import pickle | ||
from tqdm import tqdm | ||
from ztfquery.fields import FIELD_DATAFRAME | ||
from gwemopt.ztf_tiling import get_quadrant_ipix | ||
|
||
|
||
def get_flatpix_path(nside: int): | ||
outdir = os.path.join("nuztf", "data") | ||
if not os.path.exists(outdir): | ||
os.makedirs(outdir) | ||
|
||
outfile = os.path.join(outdir, f"ztf_fields_ipix_nside={nside}.pickle") | ||
return outfile | ||
|
||
|
||
def generate_flatpix_file(nside: int, logger=logging.getLogger(__name__)): | ||
""" | ||
Generate and save the fields-healpix lookup table | ||
""" | ||
|
||
logger.info(f"Generating field-healpix lookup table for nside={nside}") | ||
|
||
field_dataframe = FIELD_DATAFRAME.reset_index() | ||
|
||
fields = field_dataframe["ID"].values | ||
ras = field_dataframe["RA"].values | ||
decs = field_dataframe["Dec"].values | ||
|
||
flat_pix_dict = dict() | ||
|
||
for i, field in tqdm(enumerate(fields), total=len(fields)): | ||
|
||
ra = ras[i] | ||
dec = decs[i] | ||
pix = get_quadrant_ipix(nside, ra, dec) | ||
|
||
flat_pix = [] | ||
|
||
for sub_list in pix: | ||
for p in sub_list: | ||
flat_pix.append(p) | ||
|
||
flat_pix = list(set(flat_pix)) | ||
flat_pix_dict[field] = flat_pix | ||
|
||
outfile = get_flatpix_path(nside=nside) | ||
|
||
logger.info(f"Saving to {outfile}") | ||
|
||
with open(outfile, "wb") as f: | ||
pickle.dump(flat_pix_dict, f) | ||
|
||
|
||
def get_flatpix(nside: int, logger=logging.getLogger(__name__)): | ||
|
||
infile = get_flatpix_path(nside=nside) | ||
|
||
# Generate a lookup table for field healpix | ||
# if none exists (because this is computationally costly) | ||
if not os.path.isfile(infile): | ||
generate_flatpix_file(nside=nside, logger=logger) | ||
|
||
with open(infile, "rb") as f: | ||
field_pix = pickle.load(f) | ||
|
||
return field_pix |
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.