Esempio n. 1
0
def modelSpec(lib='GK',teff=4500,logg=2.5,metals=0.,
              cfe=0.,nfe=0.,afe=0.,vmicro=2.,
              dr=None,rmHDU1=True,rmHDU2=True):
    """
    NAME:
       modelSpec
    PURPOSE:
       download a model spectrum file
    INPUT:
       lib= ('GK') spectral library
       teff= (4500) grid-point Teff
       logg= (2.5) grid-point logg
       metals= (0.) grid-point metallicity
       cfe= (0.) grid-point carbon-enhancement
       nfe= (0.) grid-point nitrogen-enhancement
       afe= (0.) grid-point alpha-enhancement
       vmicro= (2.) grid-point microturbulence
       dr= return the path corresponding to this data release
       rmHUD1= (True) if True, rm the first (v. large) HDU with the high-resolution model spectrum
       rmHDU2= (True) if True, rm the second (quite large) HDU with the model spectrum convolved with the LSF
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2015-01-20 - Written - Bovy (IAS)
    """
    if dr is None: dr= path._default_dr()
    # First make sure the file doesn't exist
    filePath= path.modelSpecPath(lib=lib,teff=teff,logg=logg,metals=metals,
                                 cfe=cfe,nfe=nfe,afe=afe,vmicro=vmicro,dr=dr)
    if os.path.exists(filePath): return None
    # Create the file path    
    downloadPath= filePath.replace(os.path.join(path._APOGEE_DATA,
                                                _dr_string(dr)),
                                   _base_url(dr=dr))
    _download_file(downloadPath,filePath,dr,verbose=True)
    # Post-processing of the file, removing the big first HDU or the first two for local storage
    if rmHDU1 or rmHDU2:
        # Open the file, need to use astropy's fits reader, bc the file has issues
        import astropy.io.fits as apyfits
        from astropy.utils.exceptions import AstropyUserWarning
        import warnings
        warnings.filterwarnings('ignore',category=AstropyUserWarning)
        hdulist= apyfits.open(filePath)
        if rmHDU1:
            hdu= apyfits.PrimaryHDU(numpy.zeros((2,2)))
        else: 
            hdu= hdulist[0].copy()
        inp= [hdu]
        if rmHDU2:
            hdu2= apyfits.ImageHDU(numpy.zeros((2,2)))
        else: 
            hdu2= hdulist[1].copy()
        inp.append(hdu2)
        inp.extend(hdulist[2:])
        newHdulist= apyfits.HDUList(inp)
        # Fix any issues in the headers
        for ii in range(5):
            if '[A/M]' in newHdulist[ii].header:
                newHdulist[ii].header['AM']= newHdulist[ii].header.pop('[A/M]',None)
            if '[C/M]' in newHdulist[ii].header:
                newHdulist[ii].header['CM']= newHdulist[ii].header.pop('[C/M]',None)
            if '[N/M]' in newHdulist[ii].header:
                newHdulist[ii].header['NM']= newHdulist[ii].header.pop('[N/M]',None)
        # Overwrite file
        newHdulist.writeto(filePath,clobber=True,output_verify='silentfix')
    return None
Esempio n. 2
0
def modelSpec(lib='GK',
              teff=4500,
              logg=2.5,
              metals=0.,
              cfe=0.,
              nfe=0.,
              afe=0.,
              vmicro=2.,
              dr=None,
              header=True,
              ext=234,
              apStarWavegrid=None,
              **kwargs):
    """
    NAME:
       modelSpec
    PURPOSE:
       Read a model spectrum file
    INPUT:
       lib= ('GK') spectral library
       teff= (4500) grid-point Teff
       logg= (2.5) grid-point logg
       metals= (0.) grid-point metallicity
       cfe= (0.) grid-point carbon-enhancement
       nfe= (0.) grid-point nitrogen-enhancement
       afe= (0.) grid-point alpha-enhancement
       vmicro= (2.) grid-point microturbulence
       dr= return the path corresponding to this data release
       ext= (234) extension to load (if ext=234, the blue, green, and red spectra will be combined [onto the aspcapStar wavelength grid by default, just concatenated if apStarWavegrid=False), with NaN where there is no model)
       apStarWavegrid= (True) if False and ext=234, don't put the spectrum on the apStar wavelength grid, but just concatenate the blue, green, and red detector
       header= (True) if True, also return the header (not for ext=234)
       dr= return the path corresponding to this data release (general default)
       +download kwargs
    OUTPUT:
       model spectrum or (model spectrum file, header)
    HISTORY:
       2015-01-13 - Written - Bovy (IAS)
    """
    filePath = path.modelSpecPath(lib=lib,
                                  teff=teff,
                                  logg=logg,
                                  metals=metals,
                                  cfe=cfe,
                                  nfe=nfe,
                                  afe=afe,
                                  vmicro=vmicro,
                                  dr=dr)
    if not os.path.exists(filePath):
        download.modelSpec(lib=lib,
                           teff=teff,
                           logg=logg,
                           metals=metals,
                           cfe=cfe,
                           nfe=nfe,
                           afe=afe,
                           vmicro=vmicro,
                           dr=dr,
                           **kwargs)
    # Need to use astropy's fits reader, bc the file has issues
    import astropy.io.fits as apyfits
    from astropy.utils.exceptions import AstropyUserWarning
    import warnings
    warnings.filterwarnings('ignore', category=AstropyUserWarning)
    hdulist = apyfits.open(filePath)
    # Find index of nearest grid point in Teff, logg, and metals
    if dr is None: dr = path._default_dr()
    if dr == '12':
        logggrid = numpy.linspace(0., 5., 11)
        metalsgrid = numpy.linspace(-2.5, 0.5, 7)
        if lib.lower() == 'gk':
            teffgrid = numpy.linspace(3500., 6000., 11)
            teffIndx = numpy.argmin(numpy.fabs(teff - teffgrid))
        elif lib.lower() == 'f':
            teffgrid = numpy.linspace(5500., 8000., 11)
            teffIndx = numpy.argmin(numpy.fabs(teff - teffgrid))
        loggIndx = numpy.argmin(numpy.fabs(logg - logggrid))
        metalsIndx = numpy.argmin(numpy.fabs(metals - metalsgrid))
    if header and not ext == 234:
        return (hdulist[ext].data[metalsIndx, loggIndx,
                                  teffIndx], hdulist[ext].header)
    elif not ext == 234:
        return hdulist[ext].data[metalsIndx, loggIndx, teffIndx]
    else:  #ext == 234, combine 2,3,4
        out = numpy.zeros(7214)
        out[:2920] = hdulist[2].data[metalsIndx, loggIndx, teffIndx]
        out[2920:5320] = hdulist[3].data[metalsIndx, loggIndx, teffIndx]
        out[5320:] = hdulist[4].data[metalsIndx, loggIndx, teffIndx]
        return out
Esempio n. 3
0
def modelSpec(lib='GK',teff=4500,logg=2.5,metals=0.,
              cfe=0.,nfe=0.,afe=0.,vmicro=2.,
              dr=None,header=True,ext=234,apStarWavegrid=None,**kwargs):
    """
    NAME:
       modelSpec
    PURPOSE:
       Read a model spectrum file
    INPUT:
       lib= ('GK') spectral library
       teff= (4500) grid-point Teff
       logg= (2.5) grid-point logg
       metals= (0.) grid-point metallicity
       cfe= (0.) grid-point carbon-enhancement
       nfe= (0.) grid-point nitrogen-enhancement
       afe= (0.) grid-point alpha-enhancement
       vmicro= (2.) grid-point microturbulence
       dr= return the path corresponding to this data release
       ext= (234) extension to load (if ext=234, the blue, green, and red spectra will be combined [onto the aspcapStar wavelength grid by default, just concatenated if apStarWavegrid=False), with NaN where there is no model)
       apStarWavegrid= (True) if False and ext=234, don't put the spectrum on the apStar wavelength grid, but just concatenate the blue, green, and red detector
       header= (True) if True, also return the header (not for ext=234)
       dr= return the path corresponding to this data release (general default)
       +download kwargs
    OUTPUT:
       model spectrum or (model spectrum file, header)
    HISTORY:
       2015-01-13 - Written - Bovy (IAS)
    """
    filePath= path.modelSpecPath(lib=lib,teff=teff,logg=logg,metals=metals,
                                 cfe=cfe,nfe=nfe,afe=afe,vmicro=vmicro,dr=dr)
    if not os.path.exists(filePath):
        download.modelSpec(lib=lib,teff=teff,logg=logg,metals=metals,
                           cfe=cfe,nfe=nfe,afe=afe,vmicro=vmicro,dr=dr,
                           **kwargs)
    # Need to use astropy's fits reader, bc the file has issues
    import astropy.io.fits as apyfits
    from astropy.utils.exceptions import AstropyUserWarning
    import warnings
    warnings.filterwarnings('ignore',category=AstropyUserWarning)
    hdulist= apyfits.open(filePath)
    # Find index of nearest grid point in Teff, logg, and metals
    if dr is None: dr= path._default_dr()
    if dr == '12':
        logggrid= numpy.linspace(0.,5.,11)
        metalsgrid= numpy.linspace(-2.5,0.5,7)
        if lib.lower() == 'gk':
            teffgrid= numpy.linspace(3500.,6000.,11)
            teffIndx= numpy.argmin(numpy.fabs(teff-teffgrid))
        elif lib.lower() == 'f':
            teffgrid= numpy.linspace(5500.,8000.,11)
            teffIndx= numpy.argmin(numpy.fabs(teff-teffgrid))
        loggIndx= numpy.argmin(numpy.fabs(logg-logggrid))
        metalsIndx= numpy.argmin(numpy.fabs(metals-metalsgrid))
    if header and not ext == 234:
        return (hdulist[ext].data[metalsIndx,loggIndx,teffIndx],
                hdulist[ext].header)
    elif not ext == 234:
        return hdulist[ext].data[metalsIndx,loggIndx,teffIndx]
    else: #ext == 234, combine 2,3,4
        out= numpy.zeros(7214)
        out[:2920]= hdulist[2].data[metalsIndx,loggIndx,teffIndx]
        out[2920:5320]= hdulist[3].data[metalsIndx,loggIndx,teffIndx]
        out[5320:]= hdulist[4].data[metalsIndx,loggIndx,teffIndx]
        return out
Esempio n. 4
0
def modelSpec(lib='GK',
              teff=4500,
              logg=2.5,
              metals=0.,
              cfe=0.,
              nfe=0.,
              afe=0.,
              vmicro=2.,
              dr=None,
              rmHDU1=True,
              rmHDU2=True):
    """
    NAME:
       modelSpec
    PURPOSE:
       download a model spectrum file
    INPUT:
       lib= ('GK') spectral library
       teff= (4500) grid-point Teff
       logg= (2.5) grid-point logg
       metals= (0.) grid-point metallicity
       cfe= (0.) grid-point carbon-enhancement
       nfe= (0.) grid-point nitrogen-enhancement
       afe= (0.) grid-point alpha-enhancement
       vmicro= (2.) grid-point microturbulence
       dr= return the path corresponding to this data release
       rmHUD1= (True) if True, rm the first (v. large) HDU with the high-resolution model spectrum
       rmHDU2= (True) if True, rm the second (quite large) HDU with the model spectrum convolved with the LSF
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2015-01-20 - Written - Bovy (IAS)
    """
    if dr is None: dr = path._default_dr()
    # First make sure the file doesn't exist
    filePath = path.modelSpecPath(lib=lib,
                                  teff=teff,
                                  logg=logg,
                                  metals=metals,
                                  cfe=cfe,
                                  nfe=nfe,
                                  afe=afe,
                                  vmicro=vmicro,
                                  dr=dr)
    if os.path.exists(filePath): return None
    # Create the file path
    downloadPath = filePath.replace(
        os.path.join(path._APOGEE_DATA, _dr_string(dr)), _base_url(dr=dr))
    _download_file(downloadPath, filePath, dr, verbose=True)
    # Post-processing of the file, removing the big first HDU or the first two for local storage
    if rmHDU1 or rmHDU2:
        # Open the file, need to use astropy's fits reader, bc the file has issues
        import astropy.io.fits as apyfits
        from astropy.utils.exceptions import AstropyUserWarning
        import warnings
        warnings.filterwarnings('ignore', category=AstropyUserWarning)
        hdulist = apyfits.open(filePath)
        if rmHDU1:
            hdu = apyfits.PrimaryHDU(numpy.zeros((2, 2)))
        else:
            hdu = hdulist[0].copy()
        inp = [hdu]
        if rmHDU2:
            hdu2 = apyfits.ImageHDU(numpy.zeros((2, 2)))
        else:
            hdu2 = hdulist[1].copy()
        inp.append(hdu2)
        inp.extend(hdulist[2:])
        newHdulist = apyfits.HDUList(inp)
        # Fix any issues in the headers
        for ii in range(5):
            if '[A/M]' in newHdulist[ii].header:
                newHdulist[ii].header['AM'] = newHdulist[ii].header.pop(
                    '[A/M]', None)
            if '[C/M]' in newHdulist[ii].header:
                newHdulist[ii].header['CM'] = newHdulist[ii].header.pop(
                    '[C/M]', None)
            if '[N/M]' in newHdulist[ii].header:
                newHdulist[ii].header['NM'] = newHdulist[ii].header.pop(
                    '[N/M]', None)
        # Overwrite file
        newHdulist.writeto(filePath, clobber=True, output_verify='silentfix')
    return None
Esempio n. 5
0
    nfe= (0.) grid-point nitrogen-enhancement
    afe= (0.) grid-point alpha-enhancement
    vmicro= (2.) grid-point microturbulence
    dr= return the path corresponding to this data release
    ext= (234) extension to load (if ext=234, the blue, green, and red spectra will be combined [onto the aspcapStar wavelength grid by default, just concatenated if apStarWavegrid=False), with NaN where there is no model)
    apStarWavegrid= (True) if False and ext=234, don't put the spectrum on the apStar wavelength grid, but just concatenate the blue, green, and red detector
    header= (True) if True, also return the header (not for ext=234)
    dr= return the path corresponding to this data release (general default)
    +download kwargs
 OUTPUT:
    model spectrum or (model spectrum file, header)
 HISTORY:
    2015-01-13 - Written - Bovy (IAS)
    2018-02-05 - Updated to account for changing detector ranges - Price-Jones (UofT)
 """
 filePath= path.modelSpecPath(lib=lib,teff=teff,logg=logg,metals=metals,
                              cfe=cfe,nfe=nfe,afe=afe,vmicro=vmicro,dr=dr)
 if not os.path.exists(filePath):
     download.modelSpec(lib=lib,teff=teff,logg=logg,metals=metals,
                        cfe=cfe,nfe=nfe,afe=afe,vmicro=vmicro,dr=dr,
                        **kwargs)
 # Need to use astropy's fits reader, bc the file has issues
 import astropy.io.fits as apyfits
 from astropy.utils.exceptions import AstropyUserWarning
 import warnings
 warnings.filterwarnings('ignore',category=AstropyUserWarning)
 hdulist= apyfits.open(filePath)
 # Find index of nearest grid point in Teff, logg, and metals
 if dr is None: dr= path._default_dr()
 if dr == '12':
     logggrid= numpy.linspace(0.,5.,11)