Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Fastspec PCA templates #260

Merged
merged 14 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9'] # fitsio does not like Python < 3.7
python-version: ['3.9', '3.10'] # fitsio does not like Python < 3.7
# astropy-version: ['<3.0', '<4.1'] #, '<5.0']
env:
DESIUTIL_VERSION: 3.2.5
Expand Down
39 changes: 39 additions & 0 deletions py/redrock/data/DLAcoeff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
2 1215.670 1.61698E-04 5.38995E-05
3 1025.720 1.54539E-04 5.15129E-05
4 972.537 1.49767E-04 4.99222E-05
5 949.743 1.46031E-04 4.86769E-05
6 937.803 1.42893E-04 4.76312E-05
7 930.748 1.40159E-04 4.67196E-05
8 926.226 1.37714E-04 4.59048E-05
9 923.150 1.35495E-04 4.51650E-05
10 920.963 1.33452E-04 4.44841E-05
11 919.352 1.31561E-04 4.38536E-05
12 918.129 1.29785E-04 4.32617E-05
13 917.181 1.28117E-04 4.27056E-05
14 916.429 1.26540E-04 4.21799E-05
15 915.824 1.25041E-04 4.16804E-05
16 915.329 1.23614E-04 4.12046E-05
17 914.919 1.22248E-04 4.07494E-05
18 914.576 1.20938E-04 4.03127E-05
19 914.286 1.19681E-04 3.98938E-05
20 914.039 1.18469E-04 3.94896E-05
21 913.826 1.17298E-04 3.90995E-05
22 913.641 1.16167E-04 3.87225E-05
23 913.480 1.15071E-04 3.83572E-05
24 913.339 1.14011E-04 3.80037E-05
25 913.215 1.12983E-04 3.76609E-05
26 913.104 1.11972E-04 3.73241E-05
27 913.006 1.11002E-04 3.70005E-05
28 912.918 1.10051E-04 3.66836E-05
29 912.839 1.09125E-04 3.63749E-05
30 912.768 1.08220E-04 3.60734E-05
31 912.703 1.07337E-04 3.57789E-05
32 912.645 1.06473E-04 3.54909E-05
33 912.592 1.05629E-04 3.52096E-05
34 912.543 1.04802E-04 3.49340E-05
35 912.499 1.03991E-04 3.46636E-05
36 912.458 1.03198E-04 3.43994E-05
37 912.420 1.02420E-04 3.41402E-05
38 912.385 1.01657E-04 3.38856E-05
39 912.353 1.00908E-04 3.36359E-05
40 912.324 1.00168E-04 3.33895E-05
39 changes: 39 additions & 0 deletions py/redrock/data/LAFcoeff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
2 1215.670 1.68976E-02 2.35379E-03 1.02611E-04
3 1025.720 4.69229E-03 6.53625E-04 2.84940E-05
4 972.537 2.23898E-03 3.11884E-04 1.35962E-05
5 949.743 1.31901E-03 1.83735E-04 8.00974E-06
6 937.803 8.70656E-04 1.21280E-04 5.28707E-06
7 930.748 6.17843E-04 8.60640E-05 3.75186E-06
8 926.226 4.60924E-04 6.42055E-05 2.79897E-06
9 923.150 3.56887E-04 4.97135E-05 2.16720E-06
10 920.963 2.84278E-04 3.95992E-05 1.72628E-06
11 919.352 2.31771E-04 3.22851E-05 1.40743E-06
12 918.129 1.92348E-04 2.67936E-05 1.16804E-06
13 917.181 1.62155E-04 2.25878E-05 9.84689E-07
14 916.429 1.38498E-04 1.92925E-05 8.41033E-07
15 915.824 1.19611E-04 1.66615E-05 7.26340E-07
16 915.329 1.04314E-04 1.45306E-05 6.33446E-07
17 914.919 9.17397E-05 1.27791E-05 5.57091E-07
18 914.576 8.12784E-05 1.13219E-05 4.93564E-07
19 914.286 7.25069E-05 1.01000E-05 4.40299E-07
20 914.039 6.50549E-05 9.06198E-06 3.95047E-07
21 913.826 5.86816E-05 8.17421E-06 3.56345E-07
22 913.641 5.31918E-05 7.40949E-06 3.23008E-07
23 913.480 4.84261E-05 6.74563E-06 2.94068E-07
24 913.339 4.42740E-05 6.16726E-06 2.68854E-07
25 913.215 4.06311E-05 5.65981E-06 2.46733E-07
26 913.104 3.73821E-05 5.20723E-06 2.27003E-07
27 913.006 3.45377E-05 4.81102E-06 2.09731E-07
28 912.918 3.19891E-05 4.45601E-06 1.94255E-07
29 912.839 2.97110E-05 4.13867E-06 1.80421E-07
30 912.768 2.76635E-05 3.85346E-06 1.67987E-07
31 912.703 2.58178E-05 3.59636E-06 1.56779E-07
32 912.645 2.41479E-05 3.36374E-06 1.46638E-07
33 912.592 2.26347E-05 3.15296E-06 1.37450E-07
34 912.543 2.12567E-05 2.96100E-06 1.29081E-07
35 912.499 1.99967E-05 2.78549E-06 1.21430E-07
36 912.458 1.88476E-05 2.62543E-06 1.14452E-07
37 912.420 1.77928E-05 2.47850E-06 1.08047E-07
38 912.385 1.68222E-05 2.34330E-06 1.02153E-07
39 912.353 1.59286E-05 2.21882E-06 9.67268E-08
40 912.324 1.50996E-05 2.10334E-06 9.16925E-08
16 changes: 15 additions & 1 deletion py/redrock/external/desi.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,15 @@ def rrdesi(options=None, comm=None):
parser.add_argument("--chi2-scan", type=str, default=None,
required=False, help="Load the chi2-scan from the input file")

parser.add_argument("--zscan-galaxy", type=str, default='-0.005,1.7,3e-4',
required=False, help="Redshift scan parameters for galaxies: zmin,zmax,dz")

parser.add_argument("--zscan-qso", type=str, default='0.05,6.0,5e-4',
required=False, help="Redshift scan parameters for QSO: zmin,zmax,dz")

parser.add_argument("--zscan-star", type=str, default='-0.002,0.00201,4e-5',
required=False, help="Redshift scan parameters for stars: zmin,zmax,dz")

parser.add_argument("-n", "--ntargets", type=int,
required=False, help="the number of targets to process in each file")

Expand Down Expand Up @@ -813,7 +822,12 @@ def rrdesi(options=None, comm=None):
# Read the template data
# Pass both use_gpu (this proc) and args.gpu (if any proc is using GPU)
dtemplates = load_dist_templates(dwave, templates=args.templates,
comm=comm, mp_procs=mpprocs, redistribute=redistribute_templates, use_gpu=use_gpu, gpu_mode=args.gpu)
zscan_galaxy=args.zscan_galaxy,
zscan_qso=args.zscan_qso,
zscan_star=args.zscan_star,
comm=comm, mp_procs=mpprocs,
redistribute=redistribute_templates,
use_gpu=use_gpu, gpu_mode=args.gpu)

# Compute the redshifts, including both the coarse scan and the
# refinement. This function only returns data on the rank 0 process.
Expand Down
32 changes: 22 additions & 10 deletions py/redrock/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Template(object):

"""
def __init__(self, filename=None, spectype=None, redshifts=None,
wave=None, flux=None, subtype=None):
wave=None, flux=None, subtype=None,
zscan_galaxy=None, zscan_qso=None, zscan_star=None):

if filename is not None:
fx = None
Expand Down Expand Up @@ -73,15 +74,23 @@ def __init__(self, filename=None, spectype=None, redshifts=None,
self._rrtype = hdr['RRTYPE'].strip().upper()
if old_style_templates:
if self._rrtype == 'GALAXY':
# redshifts = 10**np.arange(np.log10(1+0.005),
# np.log10(1+2.0), 1.5e-4) - 1
self._redshifts = 10**np.arange(np.log10(1-0.005),
np.log10(1+1.7), 3e-4) - 1
if zscan_galaxy is not None:
zmin, zmax, dz = zscan_galaxy.split(',')
self._redshifts = 10**np.arange(np.log10(1+float(zmin)), np.log10(1+float(zmax)), float(dz)) - 1
else:
self._redshifts = 10**np.arange(np.log10(1-0.005), np.log10(1+1.7), 3e-4) - 1
elif self._rrtype == 'STAR':
self._redshifts = np.arange(-0.002, 0.00201, 4e-5)
if zscan_star is not None:
zmin, zmax, dz = zscan_star.split(',')
self._redshifts = np.arange(float(zmin), float(zmax), float(dz))
else:
self._redshifts = np.arange(-0.002, 0.00201, 4e-5)
elif self._rrtype == 'QSO':
self._redshifts = 10**np.arange(np.log10(1+0.05),
np.log10(1+6.0), 5e-4) - 1
if zscan_qso is not None:
zmin, zmax, dz = zscan_qso.split(',')
self._redshifts = 10**np.arange(np.log10(1+float(zmin)), np.log10(1+float(zmax)), float(dz)) - 1
else:
self._redshifts = 10**np.arange(np.log10(1+0.05), np.log10(1+6.0), 5e-4) - 1
else:
raise ValueError("Unknown redshift range to use for "
"template type {}".format(self._rrtype))
Expand Down Expand Up @@ -446,7 +455,9 @@ def cycle(self):
return True


def load_dist_templates(dwave, templates=None, comm=None, mp_procs=1, redistribute=False, use_gpu=False, gpu_mode=False):
def load_dist_templates(dwave, templates=None, comm=None, mp_procs=1,
zscan_galaxy=None, zscan_qso=None, zscan_star=None,
redistribute=False, use_gpu=False, gpu_mode=False):
"""Read and distribute templates from disk.

This reads one or more template files from disk and distributes them among
Expand Down Expand Up @@ -509,7 +520,8 @@ def load_dist_templates(dwave, templates=None, comm=None, mp_procs=1, redistribu
template_data = list()
if (comm is None) or (comm.rank == 0):
for t in template_files:
template_data.append(Template(filename=t))
template_data.append(Template(filename=t, zscan_galaxy=zscan_galaxy,
zscan_star=zscan_star, zscan_qso=zscan_qso))

if comm is not None:
template_data = comm.bcast(template_data, root=0)
Expand Down
Loading
Loading