-
Notifications
You must be signed in to change notification settings - Fork 23
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
12 changed files
with
966 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import fitsio | ||
import numpy as np | ||
import argparse | ||
from desitarget.secondary import select_secondary, _get_scxdir | ||
from desitarget.targets import main_cmx_or_sv | ||
from desitarget import io | ||
import os | ||
from glob import glob | ||
from time import time | ||
time0 = time() | ||
|
||
from desiutil.log import get_logger | ||
log = get_logger() | ||
|
||
import multiprocessing | ||
nproc = multiprocessing.cpu_count() // 2 | ||
|
||
from argparse import ArgumentParser | ||
ap = ArgumentParser(description='Generate file of secondary-only targets from $SECONDARY_DIR, write matches to primary targets back to $SECONDARY_DIR') | ||
ap.add_argument("surveydir", | ||
help="Base directory of primary target files (e.g. '/project/projectdirs/desi/target/catalogs/dr7.1/0.22.0/' at NERSC). "+ | ||
"All files that contain the string 'target' or 'targets' in their names will be considered a target file." + | ||
"Whether the file is an SV file is derived from the DESI_TARGET column in the first file detected in this directory.") | ||
ap.add_argument("dest", | ||
help="Output secondary-only targets file (e.g. '/project/projectdirs/desi/target/catalogs/secondary-dr6-0.20.0.fits' at NERSC)") | ||
ap.add_argument('-n', "--numproc", type=int, | ||
help='number of concurrent processes to use (defaults to [{}])'.format(nproc), | ||
default=nproc) | ||
ap.add_argument("-s", "--separation", type=float, default=1., | ||
help='Angular separation at which to match primary and secondary targets. Defaults to [1.]') | ||
ap.add_argument("--scnddir", | ||
help="Base directory of secondary target files (e.g. '/project/projectdirs/desi/target/secondary' at NERSC). "+ | ||
"Defaults to SECONDARY_DIR environment variable.") | ||
|
||
ns = ap.parse_args() | ||
|
||
infiles = io.list_targetfiles(ns.surveydir) | ||
if len(infiles) == 0: | ||
log.critical('no target files found') | ||
sys.exit(1) | ||
|
||
log.info('running on {} processors...t={:.1f}mins'.format(ns.numproc, (time()-time0)/60.)) | ||
|
||
# ADM check if this is an SV or main survey file. | ||
chk = fitsio.read(infiles[0],rows=0) | ||
cols, mx, surv = main_cmx_or_sv(chk, scnd=True) | ||
log.info('running on the {} survey...'.format(surv)) | ||
|
||
# ADM retrieve the SECONDARY_DIR, in case it wasn't passed and it's stored as an environment variable. | ||
scxdir = _get_scxdir(ns.scnddir) | ||
# ADM and augment the scxdir if this is an SV set of primary files. | ||
if surv != 'main': | ||
scxdir = os.path.join(scxdir, surv) | ||
|
||
scx = select_secondary(infiles, numproc=ns.numproc, sep=ns.separation, scxdir=scxdir, scnd_mask=mx[3]) | ||
|
||
# ADM start the header with that of the first primary file, the primary directory and the separation. | ||
hdr = fitsio.read_header(infiles[0], extension='TARGETS') | ||
hdr['PRIMDIR'] = ns.surveydir | ||
hdr['SEP'] = float(ns.separation) | ||
|
||
# ADM write out the secondary targets. | ||
io.write_secondary(ns.dest, scx, primhdr=hdr, scxdir=scxdir) | ||
|
||
log.info('{} secondary targets written to {}...t={:.1f}mins'.format(len(scx), ns.dest, (time()-time0)/60.)) |
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 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.