desihub / desispec

DESI spectral pipeline
BSD 3-Clause "New" or "Revised" License
33 stars 24 forks source link

Fix QuasarNet afterburner usage of Redrock QSO templates #2231

Closed sbailey closed 2 months ago

sbailey commented 2 months ago

The new redrock-templates organization includes historical templates along with the current ones, and also standardized upon UPPERCASE SPECTYPE instead of lowercase. This breaks this line from desispec.scripts.qsoqn:

    templates_default_qso = glob.glob(os.path.join(os.path.dirname(find_templates()[0]),
                                                   'rrtemplate-qso*.fits'))

as-is it will find zero templates because they are now named rrtemplate-QSO.fits instead of rrtemplate-qso.fits, and even if that capitalization is changed, it would find 4 templates instead of 2:

In [7]: glob.glob(os.path.join(os.path.dirname(find_templates()[0]),
   ...:                                                    'rrtemplate-QSO*.fits'))
DEBUG: Reading templates from /global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/redrock-templates/main
Out[7]: 
['/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/redrock-templates/main/rrtemplate-QSO-None-v0.1.fits',
 '/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/redrock-templates/main/rrtemplate-QSO-LOZ-v1.0.fits',
 '/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/redrock-templates/main/rrtemplate-QSO-HIZ-v1.1.fits',
 '/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/redrock-templates/main/rrtemplate-QSO-HIZ-v1.0.fits']

I think the right solution is to use find_templates() to return the names of the current default templates and then parse those filenames to find the QSO templates instead of re-grepping the directory.

Check whether there is similar code in zmtl too.