Skip to content

Commit

Permalink
default DESI_SPECTRO_REDUX
Browse files Browse the repository at this point in the history
  • Loading branch information
sbailey committed Mar 4, 2025
1 parent 0852688 commit 59d4d2c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
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.expandvars('$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

0 comments on commit 59d4d2c

Please sign in to comment.