desihub / desisim

DESI simulations
BSD 3-Clause "New" or "Revised" License
16 stars 22 forks source link

io.py find_basis_template does not select most recent template file #575

Open paulmartini opened 1 year ago

paulmartini commented 1 year ago

find_basis_template() is supposed to return the most recent template file in DESI_BASIS_TEMPLATES, yet returns the last element from a glob return value and this is in arbitrary order

    objfile_wild = os.path.join(indir, objtype.lower()+'_templates_*.fits')
    objfiles = glob(objfile_wild)

    if len(objfiles) > 0:
        return objfiles[-1]

Sorting the list produced by glob will fix it:

objfile_wild = os.path.join(indir, objtype.lower()+'_templates_*.fits')
objfiles = glob(objfile_wild)
objfiles.sort(key=os.path.getmtime)

Will submit a PR shortly with this fix.