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

default DESI_SPECTRO_REDUX #2448

Merged
merged 3 commits into from
Mar 6, 2025
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
3 changes: 3 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ desispec Change Log

* Fix installation when using desiutil/3.5.0, dropping support of
`python setup.py test` as a side-effect [PR `#2437`_]
* `$DESI_SPECTRO_REDUX` default to `$DESI_ROOT/spectro/redux` for
`desispec.io.findfile` [PR `#2448`_]

.. _`#2437`: https://github.com/desihub/desispec/pull/2437
.. _`#2448`: https://github.com/desihub/desispec/pull/2448

0.68.1 (2024-11-08)
-------------------
Expand Down
10 changes: 8 additions & 2 deletions py/desispec/io/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,10 @@ def rawdata_root():
Raises:
KeyError: if these environment variables aren't set.
"""
return os.environ['DESI_SPECTRO_DATA']
if 'DESI_SPECTRO_DATA' in os.environ:
return os.environ['DESI_SPECTRO_DATA']
else:
return os.path.join(os.environ['DESI_ROOT'], 'spectro', 'data')


def specprod_root(specprod=None, readonly=False):
Expand All @@ -808,7 +811,10 @@ def specprod_root(specprod=None, readonly=False):
specprod = os.environ['SPECPROD']

if '/' not in specprod:
specprod = os.path.join(os.environ['DESI_SPECTRO_REDUX'], specprod)
if 'DESI_SPECTRO_REDUX' in os.environ:
specprod = os.path.join(os.environ['DESI_SPECTRO_REDUX'], specprod)
else:
specprod = os.path.join(os.environ['DESI_ROOT'], 'spectro', 'redux', specprod)

if readonly:
specprod = get_readonly_filepath(specprod)
Expand Down
10 changes: 3 additions & 7 deletions py/desispec/skygradpca.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ def make_all_pcs(specprod, minnight=20200101,
dictionary[camera, petal] containing the corresponding SkyGradPCA
object.
"""
exps = Table.read(os.path.join(
os.environ['DESI_SPECTRO_REDUX'], specprod,
f'exposures-{specprod}.csv'))
exps = Table.read(desispec.io.findfile('exposures_csv', specprod=specprod))
m = ((exps['NIGHT'] >= minnight) &
(exps['SKY_MAG_R_SPEC'] < 19.5) &
(exps['EXPTIME'] > 60) &
Expand All @@ -261,10 +259,8 @@ def make_all_pcs(specprod, minnight=20200101,
combos = [[c, p] for c in cameras for p in petals]
fnall = []
for c, p in combos:
fn = [os.path.join(os.environ['DESI_SPECTRO_REDUX'],
specprod, 'exposures', f'{e["NIGHT"]:08d}',
f'{e["EXPID"]:08d}',
f'sframe-{c}{p}-{e["EXPID"]:08d}.fits')
fn = [desispec.io.findfile('sframe', night=e["NIGHT"], expid=e["EXPID"],
camera=f'{c}{p}', specprod=specprod)
for e in exps]
fnall.append(fn)

Expand Down
33 changes: 23 additions & 10 deletions py/desispec/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,20 +828,24 @@ def test_findfile(self):
the_exception = cm.exception
self.assertTrue(str(the_exception), "Missing inputs for")

#- Some findfile calls require $DESI_SPECTRO_DATA; others do not
#- $DESI_SPECTRO_DATA is used if set, but defaults to $DESI_ROOT/spectro/data
path1 = findfile('raw', night=20201020, expid=123)
del os.environ['DESI_SPECTRO_DATA']
x = findfile('spectra', night=20201020, tile=20111, spectrograph=2)
self.assertTrue(x is not None)
with self.assertRaises(KeyError):
x = findfile('raw', night='20150101', expid=123)
path2 = findfile('raw', night=20201020, expid=123)
self.assertEqual(path1, path2)
os.environ['DESI_SPECTRO_DATA'] = '/blat/foo'
path3 = findfile('raw', night=20201020, expid=123)
self.assertEqual(path3, path1.replace(os.path.expandvars('$DESI_ROOT/spectro/data'), '/blat/foo'))
os.environ['DESI_SPECTRO_DATA'] = self.testEnv['DESI_SPECTRO_DATA']

#- Some require $DESI_SPECTRO_REDUX; others to not
#- $DESI_SPECTRO_REDUX is used if set, but defaults to $DESI_ROOT/spectro/redux
path1 = findfile('spectra', night=20201020, tile=20111, spectrograph=2)
del os.environ['DESI_SPECTRO_REDUX']
x = findfile('raw', night='20150101', expid=123)
self.assertTrue(x is not None)
with self.assertRaises(KeyError):
x = findfile('spectra', night=20201020, tile=20111, spectrograph=2)
path2 = findfile('spectra', night=20201020, tile=20111, spectrograph=2)
self.assertEqual(path1, path2)
os.environ['DESI_SPECTRO_REDUX'] = '/blat/foo'
path3 = findfile('spectra', night=20201020, tile=20111, spectrograph=2)
self.assertEqual(path3, path1.replace(os.path.expandvars('$DESI_ROOT/spectro/redux'), '/blat/foo'))
os.environ['DESI_SPECTRO_REDUX'] = self.testEnv['DESI_SPECTRO_REDUX']

#- Camera is case insensitive
Expand Down Expand Up @@ -1747,3 +1751,12 @@ def test_specprod_root(self):
self.assertEqual(specprod_root('blat/foo'), 'blat/foo')
self.assertEqual(specprod_root('/blat/foo'), '/blat/foo')

#- $DESI_SPECTRO_REDUX overrides $DESI_ROOT/spectro/redux, but isn't required
del os.environ['DESI_SPECTRO_REDUX']
self.assertEqual(specprod_root(),
os.path.expandvars('$DESI_ROOT/spectro/redux/$SPECPROD'))
os.environ['DESI_SPECTRO_REDUX'] = '/blat/foo'
self.assertEqual(specprod_root(),
os.path.expandvars('/blat/foo/$SPECPROD'))


3 changes: 1 addition & 2 deletions py/desispec/tpcorrparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def gather_dark_tpcorr(specprod=None, nproc=4):
"""
if specprod is None:
specprod = os.environ.get('SPECPROD', 'daily')
expfn = os.path.join(os.environ['DESI_SPECTRO_REDUX'],
specprod, f'exposures-{specprod}.fits')
expfn = desispec.io.findfile('exposures', specprod=specprod)
exps = fits.getdata(expfn)
m = ((exps['EXPTIME'] > 300) & (exps['SKY_MAG_R_SPEC'] > 20.5) &
(exps['SKY_MAG_R_SPEC'] < 30) & (exps['FAPRGRM'] == 'dark'))
Expand Down
Loading