desihub / desisim

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

wavelength offset in stars #307

Closed sbailey closed 6 years ago

sbailey commented 6 years ago

There is a sudden jump in the wavelength solution of stars between TEFF=3500 and TEFF=3400. Plot and code below. Originally from desihub/redrock#63. star_caii

from desisim.templates import STAR
import numpy as np

nstar = 1000
flux, wave, meta = STAR().make_templates(nstar, restframe=True)

#- I didn't actually need to filter on these for plot below, but...
isMstar = (2400 <= meta['TEFF']) & (meta['TEFF'] <= 3700)
isKstar = (3700 <= meta['TEFF']) & (meta['TEFF'] <= 5200)

flux = flux[isMstar | isKstar]
meta = meta[isMstar | isKstar]

#- Reset filter on subset
isMstar = (2400 <= meta['TEFF']) & (meta['TEFF'] <= 3700)
isKstar = (3700 <= meta['TEFF']) & (meta['TEFF'] <= 5200)

#- Normalize flux to CaII region
ii = (8490 < wave) & (wave < 8560)
for i in range(flux.shape[0]):
    flux[i] /= np.sum(flux[i,ii])

clf()
for i, teff in enumerate(sorted(set(meta['TEFF']))):
    jj = meta['TEFF'] == teff
    y = 0.001*i + flux[jj].mean(axis=0)[ii]
    plot(wave[ii], y, label='{:.0f}'.format(teff))
    text(8491, y[0], '{:.0f}'.format(teff), verticalalignment='center')

xlim(8490, 8560)
moustakas commented 6 years ago

Some background: stars with temperatures below 3500 K were drawn from a separate set of models (the BT-Settle grid, computed using the Phoenix code) and I incorrectly assumed that the wavelengths of all the models were "in air".

I'll regenerate the stellar templates to fix this.

moustakas commented 6 years ago

I just generated a v2.2 set of stellar templates to address this bug, and bumped the version of the basis templates to v2.5. To get the latest set of templates (e.g., on your laptop) do

cd $DESI_ROOT/spectro/templates/basis_templates
svn export svn+ssh://portal-auth.nersc.gov/global/project/projectdirs/desi/spectro/calib/svn/basis_templates/tags/v2.5

and then be sure to update the corresponding environment variable

export DESI_BASIS_TEMPLATES=${DESI_ROOT}/spectro/templates/basis_templates/v2.5

For NERSC @sbailey or @weaverba137 should update the desisim.module file -- I won't mess with this.

See below for the QA. @londumas please let me know if this doesn't fix https://github.com/desihub/redrock/issues/63, or if you find any other problems. stars-v2 2

import numpy as np
import matplotlib.pyplot as plt
from desisim.io import read_basis_templates

flux, wave, meta = read_basis_templates(objtype='STAR')

isMstar = (2400 <= meta['TEFF']) & (meta['TEFF'] <= 3700)
isKstar = (3700 <= meta['TEFF']) & (meta['TEFF'] <= 5200)

flux = flux[isMstar | isKstar]
meta = meta[isMstar | isKstar]

isMstar = (2400 <= meta['TEFF']) & (meta['TEFF'] <= 3700)
isKstar = (3700 <= meta['TEFF']) & (meta['TEFF'] <= 5200)

#- Normalize flux to CaII region
ii = (8490 < wave) & (wave < 8560)
for i in range(flux.shape[0]):
    flux[i] /= np.sum(flux[i,ii])

for i, teff in enumerate(sorted(set(meta['TEFF']))):
    jj = meta['TEFF'] == teff
    y = 0.001*i + flux[jj].mean(axis=0)[ii]
    plt.plot(wave[ii], y, label='{:.0f}'.format(teff))
    plt.text(8491, y[0], '{:.0f}'.format(teff), verticalalignment='center')

plt.xlim(8490, 8560)
plt.ylabel('Flux + offset')
plt.xlabel('Rest wavelength')
plt.savefig('stars-v2.2.png')
sbailey commented 6 years ago

For the record: I updated desisim.modules in master to point to basis templates v2.5. Existing desisim tags will not be updated, but this will be included in the next desisim tag.