IDL Help for KCORRECT

This page was created by the IDL library routine make_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? make_html_help

at the IDL command line prompt.

Last modified: Wed Sep 21 18:27:43 2005.


List of Routines


Routine Descriptions

DEEP_KCORRECT

[Next Routine] [List of Routines]
 NAME:
   deep_kcorrect
 PURPOSE:
   calculate K-corrections for standard DEEP input (from BRI to NUB)
 CALLING SEQUENCE:
   kcorrect= deep_kcorrect(redshift [, nmgy=, ivar=, mag=, err=, $
                           zcat=, /sdss, band_shift=, chi2=, rmaggies=, $
                           omaggies=, vname=, oivar=, mass=, mtol=, $
                           absmag=, amivar=, omega0=, omegal0= ])
 INPUTS:
   redshift - [N] redshifts
   zcat - [N] DEEP zcat-style structure, containing:
                  .MAGB
                  .MAGR
                  .MAGI
                  .SFD_EBV
   nmgy, ivar - [3, N] nanomaggies, Galactic-reddening corrected, and inverse
                variance of same
   mag, err - [3, N] Pogson magnitudes, Galactic-reddening corrected and
              errors of same
 OPTIONAL INPUTS:
   band_shift    - blueshift of output bandpasses (to get ^{z}b
                   type bands) [default 0.]
   vname - name of fit to use (defaults to 'default')
   omega0, omegal0 - cosmological parameters for calculating distance
                     moduli [default 0.3, 0.7]
 OPTIONAL KEYWORDS:
   /closest - use closest bands for K-corrections
 OUTPUTS:
   kcorrect - [3, N] K-corrections from BRI to NUV, U, and B (or NUV,
              u, g if /sdss is set) satisfying
                m_R = M_Q + DM(z) + K_QR(z)
              based on the best fit sum of templates. All magnitudes
              are AB.
   mtol - [3, N] mass-to-light ratios from model in each output band
   mass - [N] total current stellar mass from model in each band
   absmag - [3, N] absolute magnitude (for missing data, substitutes
            model fit) in each output band
   amivar - [3, N] inverse variance of absolute magnitude (for
            missing data = 0) in each output band
 OPTIONAL OUTPUTS:
   coeffs - coefficients of fit
   chi2 - chi^2 of fit
   rmaggies - [3, N] reconstructed maggies from the fit (BRI)
   omaggies, oivar - [3, N] maggies and inverse variances used for fit
                           (after extinction, AB correction, etc)
                           (BRI)
   obands - [3, N] which input bands the K-corrections refer to 
 COMMENTS:
   This is a simple wrapper on kcorrect.pro.  It keeps a version of
   rmatrix and zvals in memory to save time, recalculating them each
   time you change band_shift.

   You must specify nmgy,ivar OR mag,err OR zcat. If
   nmgy or mag, make sure they are AB calibrated and Galactic
   extinction corrected.

   Uses deep_to_maggies to convert zcat structure to Galactic
   extinction corrected maggies with errors.

   For v4_0b templates and later, coefficients are in units of: 
 
     1 solar mass / (D/10pc)^2 

   That is, sum the coefficients and multiply by (D/10pc)^2 to get
   TOTAL INTEGRATED STAR FORMATION. (In fact, for Omega0=0.3 and
   OmegaL0=0.7, this is what the "mass" keyword returns). Note that
   the total integrated star formation DIFFERS from the current
   stellar mass --- which is returned in the mass and mtol variables.
 REVISION HISTORY:
   07-Apr-2005  Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/deep_kcorrect.pro)


DEEP_TO_MAGGIES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   deep_to_maggies
 PURPOSE:
   convert DEEP zcat input to Galactic-extinction corrected AB maggies 
 CALLING SEQUENCE:
   deep_to_maggies, zcat, maggies, ivar
 INPUTS:
   zcat - [N] DEEP style input, with:
               .MAGB
               .MAGR
               .MAGI
 OUTPUTS:
   maggies - [3, N] output in AB maggies in BRI
   ivar - [3, N] inverse variance of maggies
 COMMENTS:
   Calculates an approximate error based on the flux.
 
   It ALWAYS applies a minimum error of [0.02, 0.02, 0.02] in
   BRI.

   The v4_0 version incorrectly applied SFD extinction, which is
   already applied to the DEEP magnitudes.
 REVISION HISTORY:
   07-Apr-2005  Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/deep_to_maggies.pro)


FIT_SDSS_FIBER

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   fit_sdss_fiber
 PURPOSE:
   fit an sdss fiber spectro to a nonnegative sum of templates
 CALLING SEQUENCE:
   fit_sdss_fiber [, plate, fiberid, mjd=, slist=, model=, coeffs=, $
          vname=, cmodel, /usevdisp ]
 INPUTS:
   plate, fiberid, mjd - SDSS id numbers 
     OR
   slist - structure containing above id numbers in .PLATE, .FIBERID,
           and .MJD
 OPTIONAL INPUTS:
   vname - name of fit to use (default 'default')
   omega0, omegal0 - cosmological parameters for calculating distance
                     moduli [default 0.3, 0.7]
   range - [2] range of fit in wavelength
 OPTIONAL KEYWORDS:
   usevdisp - use correct vdisp for fit 
   nolines - output model without lines
   plot - splot the results
 OUTPUTS:
   coeffs - coefficients fit to each template 
   model - model spectrum
   cmodel - model of continuum (no lines, and with large scale
            differences median smoothed out with 200 Angstrom box)
   mass, metallicity - properties of template fit;
                       mass is in units of solar masses and is the
                       currently remaining stellar mass
   b300 - star-formation within last 300Myrs relative to average
          star-formation rate
   b1000 - star-formation within last 1Gyrs relative to average
           star-formation rate
 EXAMPLE:
  To get a believable galaxy continuum, use the following, and it
  will return the galaxy flux in "flux", the weighting in "ivar", and
  the best fit continuum model in "cmodel."
 
  fit_sdss_fiber, 401, 35, mjd=51788, loglam=loglam, flux=flux, $
     ivar=ivar, cmodel=cmodel, /usevdisp
 
 REVISION HISTORY:
   21-Apr-2005  MRB, NYU

(See /home/users/mb144/kcorrect/pro/fit/fit_sdss_fiber.pro)


GALEX_KCORRECT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   galex_kcorrect
 PURPOSE:
   calculate K-corrections for GALEX+SDSS input
 CALLING SEQUENCE:
   kcorrect= galex_kcorrect(redshift [, nmgy=, ivar=, mag=, err=, $
                            galex=, calibobj=, tsobj=, flux=, band_shift=, $
                            chi2=, rmaggies=, omaggies=, oivar=, $
                            mass=, mtol=, absmag=, amivar=, omega0=, $
                            omegal0= ])
 INPUTS:
   redshift - [N] redshifts
   galex - [N] GALEX "mcat" style input, with:
            .ALPHA_J2000
            .DEC_J2000
            .NUV_MAG
            .NUV_MAGERR
            .FUV_MAG
            .FUV_MAGERR
   calibobj - [N] photoop-style SDSS structure, containing:
                  .PETROFLUX[5]
                  .PETROFLUX_IVAR[5]
                  .MODELFLUX[5]
                  .MODELFLUX_IVAR[5]
                  .PSFFLUX[5]
                  .PSFFLUX_IVAR[5]
                  .EXTINCTION[5]
   tsobj - [N] opdb-style SDSS structure, containing:
                  .PETROCOUNTS[5]
                  .PETROCOUNTSERR[5]
                  .COUNTS_MODEL[5]
                  .COUNTS_MODELERR[5]
                  .PSFCOUNTS[5]
                  .PSFCOUNTSERR[5]
                  .REDDENINg[5]
   nmgy, ivar - [7, N] nanomaggies, Galactic-reddening corrected, and inverse
                variance of same
   mag, err - [7, N] standard Pogson magnitudes, Galactic-reddening
              corrected, and errors of same
 OPTIONAL INPUTS:
   flux - use this version of the SDSS fluxes ('PETRO', 'MODEL', or 'PSF')
          [defaults to 'PETRO'] if tsobj or calibobj keywords are
          used 
   band_shift - blueshift of bandpasses to apply (to get ^{z}b
                type bands) [default 0.]
   vname - name of fit to use (defaults to 'default')
   omega0, omegal0 - cosmological parameters for calculating distance
                     moduli [default 0.3, 0.7]
 OUTPUTS:
   kcorrect - [7, N] K-corrections in FNugriz satisfying
                m = M + DM(z) + K(z)
              based on the best fit sum of templates
   mtol - [5, ngals] mass-to-light ratios from model in each band
   mass - [ngals] total mass from model in each band
   absmag - [5, ngals] absolute magnitude (for missing data, substitutes
            model fit)
   amivar - [5, ngals] inverse variance of absolute magnitude (for
            missing data = 0)
 OPTIONAL OUTPUTS:
   coeffs - coefficients of fit
   chi2 - chi^2 of fit
   rmaggies - [7, N] reconstructed maggies from the fit (FNugriz)
   omaggies, oivar - [7, N] maggies and inverse variances used for fit
                     (after extinction, AB correction, etc) (FNugriz)
 COMMENTS:
   This is a simple wrapper on kcorrect.pro which is designed for
   users with GALEX data matched to SDSS data. It will deal
   appropriately if you leave out the SDSS or GALEX data (but not
   both!).

   Uses galex_to_maggies to convert a GALEX-style catalog to maggies
   and inverse variances.

   Uses sdss_to_maggies to convert tsobj or calibobj structure to
   AB, Galactic extinction corrected maggies. Passes optional
   argument "flux" to sdss_to_maggies.

   You must specify nmgy,ivar OR mag,err OR calibobj OR tsobj OR
   galex.  If nmgy or mag, make sure they are Galactic extinction
   corrected and AB calibrated.

   For v4_0b templates and later, coefficients are in units of: 
 
     1 solar mass / (D/10pc)^2 

   That is, sum the coefficients and multiply by (D/10pc)^2 to get
   TOTAL INTEGRATED STAR FORMATION. (In fact, for Omega0=0.3 and
   OmegaL0=0.7, this is what the "mass" keyword returns). Note that
   the total integrated star formation DIFFERS from the current
   stellar mass --- which is returned in the mass and mtol variables.
 REVISION HISTORY:
   07-Apr-2005  Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/galex_kcorrect.pro)


GALEX_TO_MAGGIES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   galex_to_maggies
 PURPOSE:
   convert GALEX catalog input to Galactic-extinction corrected AB maggies 
 CALLING SEQUENCE:
   galex_to_maggies,galex,maggies,ivar
 INPUTS:
   galex - [N] GALEX "mcat" style input, with:
            .ALPHA_J2000
            .DELTA_J2000
            .NUV_A_IMAGE
            .NUV_B_IMAGE
            .NUV_KRON_RADIUS
            .NUV_FLUX_AUTO
            .NUV_SKYBG
            .NUV_WEIGHT
            .NUV_MAG_AUTO
            .NUV_ZERO_POINT
            .NUV_EXTINCTION
            .NUV_FLUX_APER_N [in ORDER!]
            .FUV_A_IMAGE
            .FUV_B_IMAGE
            .FUV_KRON_RADIUS
            .FUV_FLUX_AUTO
            .FUV_SKYBG
            .FUV_WEIGHT
            .FUV_MAG_AUTO
            .FUV_ZERO_POINT
            .FUV_EXTINCTION
            .FUV_FLUX_APER_N [in ORDER!]
  
 OUTPUTS:
   maggies - [2, N] output in AB maggies in FUV and NUV filters
   ivar - [2, N] inverse variance of maggies

 OPTIONAL INPUTS:
   aper - set to 1-7 to use GALEX aperture magnitudes
           (diameters 2, 3, 5, 8, 12, 17, 23 pixels)
   apcor - [2] set for FUV, NUV to apply an aperture correction (x). 
            Default 1.0
   zero_point - [2] set to pass different zero point FUV, NUV
            Default: FUV 18.82, NUV: 20.08
   galext - Use the galex default ratio for afuv/ebv and anuv/ebv
        
 COMMENTS:
   It also ALWAYS applies a minimum error of [0.02, 0.02] in [FUV, NUV]

   If the GALEX structure has a .E_BV entry, we use that for the
   GALEX extinction, but we call dust_getval() to read the SFD maps
   otherwise.
 REVISION HISTORY:
   07-Apr-2005  Mike Blanton, NYU
   23-June-2005 David Schiminovich, Columbia
           added some fixes for errors, etc
   20-July-2005 David Schiminovich, Columbia
           added aperture photometry

(See /home/users/mb144/kcorrect/pro/utils/galex_to_maggies.pro)


GET_D4000N

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   get_d4000n
 PURPOSE:
   get "narrow" D4000 measure from a spectrum
 CALLING SEQUENCE:
   d4000n= get_d4000n(loglam, flux, flux_ivar, ivar= )
 INPUTS:
   loglam - log base 10 rest-frame wavelength (angstroms)
   flux - flux in flambda units
   flux_ivar - inverse variance of flux
 OUTPUTS:
   d4000n - ratio of red to blue continuum
   ivar - inverse variance of d4000n
 REVISION HISTORY:
   05-May-2005  Written by M. Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/get_d4000n.pro)


GET_LINE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   get_line
 PURPOSE:
   measures a line flux and equivalent width
 CALLING SEQUENCE:
   lstruct= get_line(loglam, flux, flux_ivar [, blim=, rlim=, llim=, lname=]
 INPUTS:
   loglam - log base 10 rest-frame wavelength (angstroms)
   flux - flux in flambda units
   flux_ivar - inverse variance of flux
 OPTIONAL INPUTS
   lname - name of line (default to 'LINE')
   blim - [2] limits in Angstroms of blue continuum defn
   rlim - [2] limits in Angstroms of red continuum defn
   llim - [2] limits to integrate line over
 OUTPUTS:
   lstruct - structure with the elements:
      .[LNAME]_FLUX - flux in line (units are flambda*Angstroms)
      .[LNAME]_FLUX_IVAR - flux in line (units are flambda*Angstroms)
      .[LNAME]_CONTINUUM - flux density in continuum
      .[LNAME]_EQW - equivalent widths
 COMMENTS:
   If "lname" is known, uses a standard set of rlim, blim, and
   llmin. Otherwise those must be set.

   Known lnames are:
       HDELTA
 
   Only *really* makes sense to measure absorption lines with such a
   crude measure of the continnum.
 REVISION HISTORY:
   05-May-2005  Written by M. Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/get_line.pro)


GOODS_KCORRECT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   goods_kcorrect
 PURPOSE:
   calculate K-corrections for GOODS catalog (BVizJHK)
 CALLING SEQUENCE:
   kcorrect= goods_kcorrect(redshift [, nmgy=, ivar=, mag=, err=, $
                            goods=, /sdss, band_shift=, chi2=, rmaggies=, $
                            omaggies=, vname=, oivar=, mass=, mtol=, $
                            absmag=, amivar=, omega0=, omegal0= ])
 INPUTS:
   redshift - [N] redshifts
   goods - [N] GOODS-style structure, containing:
               .RA (J2000 degrees)
               .DEC (J2000 degrees)
               .BMAG_MAGAUTO
               .BMAGERR_MAGAUTO
               .VMAG_MAGAUTO
               .VMAGERR_MAGAUTO
               .IMAG_MAGAUTO
               .IMAGERR_MAGAUTO
               .ZMAG_MAGAUTO
               .ZMAGERR_MAGAUTO
               .JMAG_MAGAUTO
               .JMAGERR_MAGAUTO
               .HMAG_MAGAUTO
               .HMAGERR_MAGAUTO
               .KMAG_MAGAUTO
               .KMAGERR_MAGAUTO
   nmgy, ivar - [7, N] nanomaggies, Galactic-reddening corrected, and inverse
                variance of same
   mag, err - [7, N] Pogson magnitudes, Galactic-reddening corrected and
              errors of same
 OPTIONAL INPUTS:
   band_shift    - blueshift of output bandpasses (to get ^{z}b
                   type bands) [default 0.]
   vname - name of fit to use [defaults to 'default']
   omega0, omegal0 - cosmological parameters for calculating distance
                     moduli [default 0.3, 0.7]
   filterlist - [Nf] output filter list; default is:
                   ['galex_NUV.par', $
                    'bessell_U.par', $
                    'bessell_B.par', $
                    'bessell_V.par', $
                    'bessell_R.par', $
                    'bessell_I.par']
                unless /sdss is set, in which case: 	
                   ['galex_NUV.par', $
                    'sdss_u0.par', $
                    'sdss_g0.par', $
                    'sdss_r0.par', $
                    'sdss_i0.par', $
                    'sdss_z0.par']
 OUTPUTS:
   kcorrect - [Nf, N] K-corrections from BVizJHK to NUBVRI (or Nugriz 
              /sdss is set). The closest input band is used for each
              output band (which ones are decided upon is output in
              "obands"). K-corrections satisfy
                m_R = M_Q + DM(z) + K_QR(z)
              based on the best fit sum of templates. All magnitudes
              are AB. 
   mtol - [Nf, N] mass-to-light ratios from model in each output band
   mass - [N] total mass from model in each band
   absmag - [Nf, N] absolute magnitude (for missing data, substitutes
            model fit) in each output band
   amivar - [Nf, N] inverse variance of absolute magnitude (for
            missing data = 0) in each output band
 OPTIONAL OUTPUTS:
   coeffs - coefficients of fit
   chi2 - chi^2 of fit
   rmaggies - [7, N] reconstructed maggies from the fit (BVizJHK)
   omaggies, oivar - [7, N] maggies and inverse variances used for fit
                           (after extinction correction, etc)
                           (BVizJHK)
   obands - [Nf, N] which input bands the K-corrections refer to 
   appm - [Nf, N] apparent magnitudes in output bands
 COMMENTS:
   This is a simple wrapper on kcorrect.pro.  It keeps a version of
   rmatrix and zvals in memory to save time, recalculating them each
   time you change band_shift.

   You must specify nmgy,ivar OR mag,err OR goods. If
   nmgy or mag, make sure they are AB calibrated and Galactic
   extinction corrected.

   Uses goods_to_maggies to convert goods structure to Galactic
   extinction corrected maggies with errors. This ignores the H band,
   which we think is crap.

   For v4_0b templates and later, coefficients are in units of: 
 
     1 solar mass / (D/10pc)^2 

   That is, sum the coefficients and multiply by (D/10pc)^2 to get
   TOTAL INTEGRATED STAR FORMATION. (In fact, for Omega0=0.3 and
   OmegaL0=0.7, this is what the "mass" keyword returns). Note that
   the total integrated star formation DIFFERS from the current
   stellar mass --- which is returned in the mass and mtol variables.
 REVISION HISTORY:
   07-Apr-2005  Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/goods_kcorrect.pro)


GOODS_TO_MAGGIES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   goods_to_maggies
 PURPOSE:
   convert GOODS catalog input to Galactic-extcintion corrected AB maggies 
 CALLING SEQUENCE:
   goods_to_maggies,goods,maggies,ivar
 INPUTS:
   goods - [N] GOODS style input
               .RA (J2000 degrees)
               .DEC (J2000 degrees)
               .BMAG_MAGAUTO
               .BMAGERR_MAGAUTO
               .VMAG_MAGAUTO
               .VMAGERR_MAGAUTO
               .IMAG_MAGAUTO
               .IMAGERR_MAGAUTO
               .ZMAG_MAGAUTO
               .ZMAGERR_MAGAUTO
               .JMAG_MAGAUTO
               .JMAGERR_MAGAUTO
               .HMAG_MAGAUTO
               .HMAGERR_MAGAUTO
               .KMAG_MAGAUTO
               .KMAGERR_MAGAUTO
 OUTPUTS:
   maggies - [7, N] output in AB maggies in BVizJHK
   ivar - [7, N] inverse variance of maggies
 COMMENTS:
   It ALWAYS applies a minimum error of 0.02 in all
   bandpasses. Except in H band it ALWAYS sets the inverse variance
   to zero since I don't believe the H band calibration.

   Requires you to have the dust maps so that dust_getval can find
   them. (If somebody wants me to set "default" columns in the
   goods structure that this code looks for, let me know).
 REVISION HISTORY:
   07-Apr-2005  Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/goods_to_maggies.pro)


GST_KCORRECT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   gst_kcorrect
 PURPOSE:
   calculate K-corrections for GALEX+SDSS+2MASS input
 CALLING SEQUENCE:
   kcorrect= gst_kcorrect(redshift [, nmgy=, ivar=, mag=, err=, $
                          galex=, twomass=, calibobj=, tsobj=, flux=, $
                          band_shift=, chi2=, rmaggies=, omaggies=, $
                          oivar=, mass=, mtol=, absmag=, amivar=, $
                          omega0=, omegal0= ])
 INPUTS:
   redshift - [N] redshifts
   galex - [N] GALEX "mcat" style input, with:
            .ALPHA_J2000
            .DEC_J2000
            .NUV_MAG
            .NUV_MAGERR
            .FUV_MAG
            .FUV_MAGERR
   twomass - [N] 2MASS "mcat" style input, with:
               .RA
               .DECL
               .J_M_EXT
               .J_MSIG_EXT
               .J_FLG_EXT
               .H_M_EXT
               .H_MSIG_EXT
               .H_FLG_EXT
               .K_M_EXT
               .K_MSIG_EXT
               .K_FLG_EXT
   calibobj - [N] photoop-style SDSS structure, containing:
                  .PETROFLUX[5]
                  .PETROFLUX_IVAR[5]
                  .MODELFLUX[5]
                  .MODELFLUX_IVAR[5]
                  .PSFFLUX[5]
                  .PSFFLUX_IVAR[5]
                  .EXTINCTION[5]
   tsobj - [N] opdb-style SDSS structure, containing:
                  .PETROCOUNTS[5]
                  .PETROCOUNTSERR[5]
                  .COUNTS_MODEL[5]
                  .COUNTS_MODELERR[5]
                  .PSFCOUNTS[5]
                  .PSFCOUNTSERR[5]
                  .REDDENINg[5]
   nmgy, ivar - [10, N] nanomaggies, Galactic-reddening corrected, and inverse
                variance of same (in FNugrizJHK)
   mag, err - [10, N] standard Pogson magnitudes, Galactic-reddening
              corrected, and errors of same (in FNugrizJHK)
 OPTIONAL INPUTS:
   flux - use this version of the SDSS fluxes ('PETRO', 'MODEL', or 'PSF')
          [defaults to 'PETRO'] if tsobj or calibobj keywords are
          used 
   band_shift - blueshift of bandpasses to apply (to get ^{z}b
                type bands) [default 0.]
   vname - name of fit to use (defaults to 'default')
   omega0, omegal0 - cosmological parameters for calculating distance
                     moduli [default 0.3, 0.7]
 OUTPUTS:
   kcorrect - [10, N] K-corrections in FNugrizJHK satisfying
                m = M + DM(z) + K(z)
              based on the best fit sum of templates
   mtol - [5, ngals] mass-to-light ratios from model in each band
   mass - [ngals] total current stellar mass from model in each band
   absmag - [5, ngals] absolute magnitude (for missing data, substitutes
            model fit)
   amivar - [5, ngals] inverse variance of absolute magnitude (for
            missing data = 0)
 OPTIONAL OUTPUTS:
   coeffs - coefficients of fit
   chi2 - chi^2 of fit
   rmaggies - [10, N] reconstructed maggies from the fit (FNugrizJHK)
   omaggies, oivar - [10, N] maggies and inverse variances used for fit
                     (after extinction, AB correction, etc) (FNugrizJHK)
 COMMENTS:
   This is a simple wrapper on kcorrect.pro which is designed for
   users with GALEX and 2MASS data matched to SDSS data. It will deal
   appropriately if you leave out the SDSS or GALEX or 2MASS data (but not
   all three!).

   Uses galex_to_maggies to convert a GALEX-style catalog to maggies
   and inverse variances.

   Uses sdss_to_maggies to convert tsobj or calibobj structure to
   AB, Galactic extinction corrected maggies. Passes optional
   argument "flux" to sdss_to_maggies.

   Uses twomass_to_maggies to convert a 2MASS-style catalog to maggies
   and inverse variances.

   You must specify nmgy,ivar OR mag,err OR calibobj OR tsobj OR
   galex.  If nmgy or mag, make sure they are Galactic extinction
   corrected and AB calibrated.

   For v4_0b templates and later, coefficients are in units of: 
 
     1 solar mass / (D/10pc)^2 

   That is, sum the coefficients and multiply by (D/10pc)^2 to get
   TOTAL INTEGRATED STAR FORMATION. (In fact, for Omega0=0.3 and
   OmegaL0=0.7, this is what the "mass" keyword returns). Note that
   the total integrated star formation DIFFERS from the current
   stellar mass --- which is returned in the mass and mtol variables.
 REVISION HISTORY:
   07-Apr-2005  Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/gst_kcorrect.pro)


KCORRECT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   kcorrect
 PURPOSE:
   Given a set of AB maggies, returns the K-correction for each band.
 CALLING SEQUENCE:
   kcorrect, maggies, maggies_ivar, redshift, kcorrect [ , $
        band_shift=, /magnitude, /stddev, lfile=, absmag=, $
        vfile=, vpath=, filterlist=, filterpath=, rmatrix=, $
        zvals=, lambda=, vmatrix=, /sdssfix, /abfix, minerrors=, $
        coeffs=, chi2=, maxiter=, zmin=, zmax=, nz=, /verbose ]
 INPUTS:
   maggies    - [nk, ngals] AB maggies of galaxies (magnitudes if
                /magnitude set, asinh magnitudes if /sdssfix set)
   maggies_ivar - [nk, ngals] inverse variance in maggies (magnitudes if
                  /magnitude set, std. dev. if /stddev set; if
                  /sdssfix set, is std. dev. of asinh magnitudes)
   redshift      - [ngals] redshifts of galaxies 
 OPTIONAL INPUTS:
   band_shift    - blueshift of bandpasses to apply (to get ^{z}b
                   type bands) [default 0]
   magnitude     - set if input and output in -2.5 log_10(maggies)
   stddev        - maggies_ivar actual contains standard dev.
   minerrors     - [nk] add this set of errors (in magnitude units)
                   in quadrature to all uncertainties
   vname         - name of fit to us (default 'default')
   lfile         - wavelength file for vmatrix [default
                   lambda.[vname].dat]
   vfile         - vmatrix file [default vmatrix.[vname].dat]
   vpath         - path to templates [default $KCORRECT_DIR/data/templates]
   filterlist    - [nk] list of filters [default
                                         ['sdss_u0.par', 'sdss_g0.par',
                                          'sdss_r0.par', 'sdss_i0.par',
                                          'sdss_z0.par']]
   filterpath    - path to filters [default $KCORRECT_DIR/data/filters]
   /verbose      - call k_fit_nonneg verbosely
   maxiter       - maximum number of iterations for fit [default 3000]
   omega0, omegal0 - cosmological parameters for calculating distance
                     moduli [default 0.3, 0.7]
 DEPRECATED INPUTS:
   /abfix        - uses k_abfix to fix input SDSS maggies to AB
                   (better to just call with 'sdss_kcorrect')
   /sdssfix      - uses k_sdssfix to "fix" input SDSS asinh magnitudes and 
                   standard deviations; treats as if /abfix, and
                   minerrors=[0.05,0.02,0.02,0.02,0.03] are all set
                   (better to just call with 'sdss_kcorrect')
 OUTPUTS:
   kcorrect   - [nk, ngals] K-corrections satisfying
                   m = M + DM(z) + K(z)
                based on the best fit sum of templates
   chi2       - chi^2 of fit
   rmaggies      - reconstructed maggies from the fit
 OPTIONAL INPUT/OUTPUTS:
   rmaggies      - [nk, ngals] reconstructed maggies in each bands
   coeffs        - [nt, ngals] coefficients fit to each template (if maggies
                   input are nonexistent, just use these input
                   coeffs)
   mass          - [ngals] model mass derived from the coeffs (current
                   surviving stellar mass)
   intsfh        - [ngals] total integrated star-formation history (number of
                   stars formed total)
   mets          - [ngals] average metallicity of currently surviving stars

   absmag        - [nk, ngals] absolute magnitude (for missing data,
                   substitutes model fit)

   amivar        - [nk, ngals] absolute magnitude invvar (for missing
                   data = 0) 
   mtol          - [nk, ngals] model mass-to-light in each *final*
                   bandpass (the bandpass you are kcorrecting *to*)
                   in SOLAR UNITS!
   lambda        - [nl+1] wavelengths for templates (to use)/(which were used)
                   (pixel edges)
   vmatrix       - [nl, nv] templates (to use)/(which were used)
   rmatrix       - [nz, nv, nk] look up table for bmatrix and filter
                   information
   zvals         - [nz] look up redshift table for rmatrix [N_z]
   zmin,zmax     - minimum and maximum redshifts for lookup table
                   (default 0., 2.)
   nz            - number of redshifts in lookup table (default 1000)
   b300          - star-formation within last 300Myrs relative to
                   average star-formation rate
   b1000         - star-formation within last 1Gyrs relative to
                   average star-formation rate
 COMMENTS:

   For v4_0b templates and later, coefficients are in units of: 
 
     1 solar mass / (D/10pc)^2 

   That is, sum the coefficients and multiply by (D/10pc)^2 to get
   TOTAL INTEGRATED STAR FORMATION. (In fact, for Omega0=0.3 and
   OmegaL0=0.7, this is what the "mass" keyword returns). Note that
   the total integrated star formation DIFFERS from the current
   stellar mass --- which is returned in the mass and mtol variables.

   If you just want to do SDSS kcorrections, it is better to use the
   wrapper 'sdss_kcorrect'. 
 
   If you want to do GALEX kcorrections (perhaps including matched
   SDSS data) use the wrapper 'galex_kcorrect'.
 
   If you want to do 2MASS kcorrections (perhaps including matched
   SDSS data) use the wrapper 'twomass_kcorrect'.
 
   If you want to do DEEP kcorrections use the wrapper 'deep_kcorrect'.

   Allows the user to shift the bandpasses by a factor band_shift. 
   If no band_shift is specified, the K-correction is to z=0.
 
   Defaults to SDSS filters.  
 REVISION HISTORY:
   24-Jan-2002  Translated to IDL by Mike Blanton, NYU
   19-Jul-2002  Major bug fix (pointed out by I. Baldry) MRB, NYU
   02-Jun-2003  Updated to new v3_0 standards MRB, NYU

(See /home/users/mb144/kcorrect/pro/fit/kcorrect.pro)


KCORRECT_SO_EXT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   kcorrect_so_ext
 PURPOSE:
   returns appropriate dynamic library extension given arch
 CALLING SEQUENCE:
   so_ext= kcorrect_so_ext()
 COMMENTS:
   necessary to deal with non-standard .dylib extension on darwin
 REVISION HISTORY:
   20-Feb-2004  Written by M. Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/kcorrect_so_ext.pro)


KEYNOTE_PLOTS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   keynote_plots
 PURPOSE:
   make presentation plots
 CALLING SEQUENCE:
   keynote_plots
 REVISION HISTORY:
   2005-06-23 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/keynote_plots.pro)


KLOG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   klog

 PURPOSE:
   Logging routine for writing to standard output and/or a log file.

 CALLING SEQUENCE:
   klog, v1, v2 ..., [, _EXTRA=extra, /noname, prelog=, filename=, $
    /append, /close ]

 INPUTS:
   v1, v2 ... - The expressions to be passed to PRINT or PRINTF

 OPTIONAL KEYWORDS:
   _EXTRA     - Any keywords for PRINT or PRINTF, such as FORMAT
   noname     - If set, then suppress printing name of calling routine
   prelog     - If set, then print this string immediately after the
                name of the calling routine on each line, i.e. 'b1'
   filename   - If specified, then open this file for text output
   append     - If set at the same time as FILENAME, then append to this file;
                default is to overwrite file
   close      - If set, then close the output file

 OUTPUTS:

 OPTIONAL OUTPUTS:

 COMMENTS:
   The output is formatted just like with the IDL PRINT command, except
   that extraneous whitespace is removed from non-STRING elements unless
   a FORMAT keyword is used.

 EXAMPLES:
   Open a file for text output, write to it, then close it:
     klog, filename='test.log'
     klog, 'This is a test', 123.4, format='(a,f8.2)'
     klog, /close
   Alternatively, this can all be done on one line
     klog, filename='test.log', /close, $
      'This is a test', 123.4, format='(a,f8.2)'

 BUGS:

 PROCEDURES CALLED:

 REVISION HISTORY:
   17-Nov-1999  Written by D. Schlegel, Princeton
   23-Jan-2002  Branched from idlutils to eliminate dependency by MB, NYU

(See /home/users/mb144/kcorrect/pro/utils/klog.pro)


KPHOTOZ

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   kphotoz
 PURPOSE:
   Given AB maggies estimate the redshift of a galaxy
 CALLING SEQUENCE:
   kphotoz, maggies, maggies_ivar, photoz [ , $
        /magnitude, /stddev, lfile=, $
        vfile=, vpath=, filterlist=, filterpath=, rmatrix=, $
        zvals=, lambda=, vmatrix=, /sdssfix, coeffs=, chi2=, $
        maxiter=, zmin=, zmax=, nz=, /verbose ]
 INPUTS:
   maggies    - AB maggies of galaxies [N_band, N_gal] (magnitudes if
                /magnitude set)
   maggies_ivar - inverse variance in maggies (magnitudes if
                  /magnitude set, std. dev. if /stddev set)
 OPTIONAL INPUTS:
   vname         - name of fit to us (default 'default')
   lfile    - wavelength file for vmatrix [default lambda.default.dat]
   vfile         - vmatrix file [default vmatrix.default.dat]
   vpath         - path to templates [default $KCORRECT_DIR/data/templates]
   maxiter       - maximum number of iterations for fit [default
                   3000]
   filterlist    - list of filters [default
                                    ['sdss_u0.par', 'sdss_g0.par',
                                     'sdss_r0.par', 'sdss_i0.par',
                                     'sdss_z0.par']]
   filterpath    - path to filters [default $KCORRECT_DIR/data/filters]
   /magnitude     - set if input and output in -2.5 log_10(maggies)
   /stddev        - maggies_ivar actual contains standard dev.
   /verbose      - call k_fit_nonneg verbosely
   /noprior      - don't use any prior (by default uses a prior which
                   slightly discourages low redshifts). overridden by
                   lprior and zprior
   zprior/lprior - grid of redshift and -2ln(prior) values to apply
   /sdssfix      - uses k_sdssfix to "fix" input SDSS magnitudes and 
                   standard deviations (treats as if /magnitude and
                   /stddev are also set) DEPRECATED: use
                   SDSS_KPHOTOZ() instead.
 OUTPUTS:
   photoz     - photometric redshift
   coeffs     - coefficients fit to each template
   chi2       - chi^2 of fit
 OPTIONAL INPUT/OUTPUTS:
   lambda        - wavelengths for templates (to use)/(which were used)
   vmatrix       - templates (to use)/(which were used)
   rmatrix       - look up table for bmatrix and filter information 
                   [N_z, N_dim, N_band]
   zvals         - look up redshift table for rmatrix [N_z]
   zmin,zmax     - minimum and maximum redshifts for lookup table
                   (default 0., 2.)
   nz            - number of redshifts in lookup table (default 1000)
 COMMENTS:
   When /sdssfix is set, deals with SDSS database-style input,
   including  wacky values for magnitgude errors, adding zeropoint
   uncertainties, and dealing with asinh magnitudes. Uses k_sdssfix
   for this. 
 REVISION HISTORY:
   04-Jun-2003  converted from kcorrect MRB, NYU

(See /home/users/mb144/kcorrect/pro/fit/kphotoz.pro)


K_ABFIX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_abfix
 PURPOSE:
   Take SDSS pipeline maggies and return AB maggies
 CALLING SEQUENCE:
   k_abfix, maggies, maggies_ivar [ aboff=]
 INPUTS/OUTPUTS:
   maggies - input maggies (changed on output)
   maggies_ivar - input inverse variances (changed on output)
 OPTIONAL KEYWORDS:
   /ab02 - use 2002 version of AB corrections (overrides aboff keyword)
 OPTIONAL INPUTS:
   aboff - [5] AB offsets (defaults to list below)
 COMMENTS:
   Uses the AB conversions posted by D. Eisenstein (sdss-calib/???)
     u(AB,2.5m) = u(database, 2.5m) - 0.036
     g(AB,2.5m) = g(database, 2.5m) + 0.012
     r(AB,2.5m) = r(database, 2.5m) + 0.010
     i(AB,2.5m) = i(database, 2.5m) + 0.028
     z(AB,2.5m) = z(database, 2.5m) + 0.040
   You can specify your own with the "aboff" input.

   Note that older ("2002") versions (v3_2 and previous) used a different set
   of corrections: 
     u(AB,2.5m) = u(database, 2.5m) - 0.042   (NOT WHAT WE DO HERE)
     g(AB,2.5m) = g(database, 2.5m) + 0.036   (NOT WHAT WE DO HERE)
     r(AB,2.5m) = r(database, 2.5m) + 0.015   (NOT WHAT WE DO HERE)
     i(AB,2.5m) = i(database, 2.5m) + 0.013   (NOT WHAT WE DO HERE)
     z(AB,2.5m) = z(database, 2.5m) - 0.002   (NOT WHAT WE DO HERE)
   You can use these if you set the /ab02 flag
 REVISION HISTORY:
   05-Apr-2005  Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_abfix.pro)


K_ADD_STACK

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_add_stack
 PURPOSE:
   adds stack of observations for multiple bands/objects
 CALLING SEQUENCE:
   k_add_stack, stack, stack_ivar, stacked, stacked_ivar
 INPUTS:
   stack - [Nbands, Ngalaxies, Nobs] maggies in each band for each
           galaxy for each observation
   stack_ivar - [Nbands, Ngalaxies, Nobs] inverse variance for each
                observation
 OUTPUTS:
   stacked - [Nbands, Ngalaxies] average maggies
   stacked_ivar - [Nbands, Ngalaxies] inverse variance of average
 COMMENTS:
   Weights average by inverse variance.
 REVISION HISTORY:
   18-Jan-2003  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/samples/k_add_stack.pro)


K_BINSPEC[1]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_binspec
 PURPOSE:
   bins spectrum by integrating over pixels to convert flux density to flux
 CALLING SEQUENCE:
   newspec= k_rebin(lambda, spec, newlambda)
 INPUTS:
   lambda - [N] wavelength
   spec - [N] flux density (in same units as wavelength)
   newlambda - [Nout] centers of new pixels
 OUTPUTS:
   newspec - [Nout] total flux in each pixel
 COMMENTS: 
   Uses k_lambda_to_edges to infer pixel edges from centers.
 REVISION HISTORY:
   21-Sept-2005  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_binspec.pro)


K_BINSPEC[2]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_binspec
 PURPOSE:
   bins spectrum just by integrating over pixels 
 CALLING SEQUENCE:
   newspec= k_rebin(lambda, spec, newlambda)
 INPUTS:
   lambda - [N] wavelength
   spec - [N] flux density (in same units as wavelength)
   newlambda - [N] centers of new pixels
 REVISION HISTORY:
   21-Sept-2005  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_rebin.pro)


K_BSPLINE2

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_bspline2
 PURPOSE:
   return value of a second-order B-spline basis function centered at zero
 CALLING SEQUENCE:
   vals= k_bspline2(x)
 INPUTS:
   x - [N] positions
 OUTPUTS:
   vals - [N] value of basis function at positions
 COMMENTS:
   A very specialized function. 
 REVISION HISTORY:
   26-Feb-2003  Written by M. Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_bspline2.pro)


K_DEEP_TESTS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_deep_tests
 PURPOSE:
   runs tests on DEEP data
 CALLING SEQUENCE:
   k_deep_tests
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_deep_tests.pro)


K_DERIVED

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_derived
 PURPOSE:
   create derived quantities file 
 CALLING SEQUENCE:
   k_derived [, vname= ]
 OPTIONAL INPUTS:
   vname - name of set of templates to use (default 'default')
 COMMENTS:
   Create k_nmf_derived.vname.fits file, with the HDUs:
       HDU0: [nbasis, nt] coefficients of each template
       HDU1: [nspec, nt] spectrum of each template
       HDU2: [nspec, nt] spectrum of each template (no lines)
       HDU3: [nspec, nt] spectrum of each template (no dust)
       HDU4: [nspec, nt] spectrum of each template (no lines or dust)
       HDU5: [nspec, nt] spectrum of each template (unsmoothed)
       HDU6: [nspec, nt] spectrum of each template (no lines; unsmoothed)
       HDU7: [nspec, nt] spectrum of each template (no dust; unsmoothed)
       HDU8: [nspec, nt] spectrum of each template (no lines or dust;
                          unsmoothed)
       HDU9: [nspec, nt] emission line spectrum of each template 
       HDU10: [nspec, nt] dust extinction factor of each template
       HDU11: [nspec] wavelengths for each spectrum
       HDU12: [nage, nt] SFR for each template
       HDU13: [nage, nt] metallicity for each template
       HDU14: [nage] ages at which SFR given
       HDU15: [nage] age differential (multiply SFR to get number of stars) 
       HDU16: [nt] total mass formed in each template
       HDU17: [nt] total current mass in each template
       HDU18: [nt] metallicity of current stars in each template 
       HDU19: [nt] total mass formed in each template in past 300 Myrs
       HDU20: [nt] total mass formed in each template in past 1 Gyrs
       HDU21: ages of each basis vector [Nages, Nmets, Ndust]
       HDU22: metallicities of each basis vector [Nages, Nmets, Ndust]
       HDU23: dust properties of each basis vector [Nages, Nmets, Ndust]
       HDU24: fraction of original stellar mass surviving at age 
              of this basis vector [Nages, Nmets, Ndust]
 REVISION HISTORY:
   2005-08-15 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_derived.pro)


K_END_PRINT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_end_print
 PURPOSE:
   end a postscript file and return plotting device to X
 CALLING SEQUENCE:
   k_end_print [, pold=, xold=, yold= ]
 OPTIONAL INPUTS:
   pold, xold, yold - if these exist, resets !P, !X, !Y to these values
 COMMENTS:
   A very specialized function. 
 REVISION HISTORY:
   26-Feb-2003  Written by M. Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_end_print.pro)


K_EVOLVE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_evolve
 PURPOSE:
   returns "evolved" absolute magnitude using simple evolution model
 CALLING SEQUENCE:
   absm_evolved= k_evolve(absm, z, q0, q1, qz0)
 INPUTS:
   absm - absolute magnitude
   z - redshift
   q0, q1, qz0 - parameters in formula:
     absm_evolved = absm+(q0*(1.+q1*(z-qz0)))*(z-qz0)
 REVISION HISTORY:
   2005-3-17  written - Blanton

(See /home/users/mb144/kcorrect/pro/lf/k_evolve.pro)


K_FIT_IMAGE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_fit_image
 PURPOSE:
   fit a lowz sample image pixel-by-pixel 
 COMMENTS:
   currently experimental
 REVISION HISTORY:
   06-Jul-2005  MRB, NYU

(See /home/users/mb144/kcorrect/pro/fit/k_fit_image.pro)


K_FIT_NONNEG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_fit_nonneg
 PURPOSE:
   Fit nonnegative sum of given templates to given set of maggies
 CALLING SEQUENCE:
   coeffs= k_fit_nonneg(maggies, maggies_ivar, vmatrix, lambda, redshift=, $
      filterlist= [, chi2=, rmatrix=, zvals=, maxiter=, filterpath=, $ 
      zmin=, zmax=, nz=, band_shift=, /verbose])
 INPUTS:
   maggies - fluxes in each band for each galaxy
   maggies_var - inverse variance in each band for each galaxy
   vmatrix - templates
   lambda - pixel edges for all templates
   redshift - redshift of galaxies
   filterlist - list of filternames
 OPTIONAL INPUTS:
   filterpath - path to look for filters on
   maxiter - maximum number of iterations in fit
   z[min|max] - limits for redshift to use in making lookup table
   nz - number of redshift rows in lookup table
   band_shift - shifted bands if desired
   /verbose - verbose output
 OUTPUTS:
   coeffs - best-fit coefficients
   rmatrix - projection table used
   zvals - redshift list for projection table used
   chi2 - chi^2 value for each fit
   niter - number of iterations used
 EXAMPLE:
    maggies=[1.,2.,3.,4.,5]
    maggies_fracerr=[0.2, 0.2, 0.2, 0.2, 0.2]
    maggies_ivar=1./(maggies*maggies_fracerr)^2
    filterlist= 'sdss_'+['u', 'g', 'r', 'i', 'z']+'0.par'
    k_load_vmatrix, vmatrix, lambda
    redshift=0.1
    coeffs= k_fit_nonneg(maggies, maggies_ivar, vmatrix, lambda, $
      redshift=redshift, filterlist=filterlist)
 REVISION HISTORY:
   01-May-2003  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/k_fit_nonneg.pro)


K_FIT_PHOTOZ

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_fit_photoz
 PURPOSE:
   Fit photometric redshift using nonnegative sum of templates
 CALLING SEQUENCE:
   photoz= k_fit_photoz(maggies, maggies_ivar, vmatrix, lambda, $
      filterlist= [, chi2=, rmatrix=, zvals=, maxiter=, filterpath=, $ 
      zmin=, zmax=, nz=, band_shift=, /verbose])
 INPUTS:
   maggies - fluxes in each band for each galaxy
   maggies_var - inverse variance in each band for each galaxy
   vmatrix - templates
   lambda - pixel edges for all templates
   filterlist - list of filternames
 OPTIONAL INPUTS:
   filterpath - path to look for filters on
   maxiter - maximum number of iterations in fit
   z[min|max] - limits for redshift to use in making lookup table
   nz - number of redshift rows in lookup table
   band_shift - shifted bands if desired
   zprior/lprior - grid of redshift and -2ln(prior) values to apply
   /verbose - verbose output
 OUTPUTS:
   photoz - estimated redshift
   chi2 - chi^2 value for each fit
   coeffs - coeffs for each fit
   rmatrix - projection table used
   zvals - redshift list for projection table used
   niter - number of iterations for last fit
 REVISION HISTORY:
   01-May-2003  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/k_fit_photoz.pro)


K_FIT_SPEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_fit_spec
 PURPOSE:
   fit a spectrum to the sum of templates 
 CALLING SEQUENCE:
   k_fit_spec, lambda, flux, ivar, coeffs [, vname=, vdisp= ]
 INPUTS:
   flux - [nl] fluxes (aligned with wavelength grid of models)
   ivar - [nl] inverse variances (aligned with wavelength grid of models)
 OPTIONAL INPUTS:
   lambda - [nl] wavelenths (if flux not aligned)
   oflux - [nm] aligned version of flux
   oivar - [nm] aligned version of ivar
   olambda - [nm] model wavelength grid
   vname - name of fit to use (default 'default')
   vdisp - velocity dispersion to smooth fit to
 OUTPUTS:
   coeffs - [nt] coefficients fit to each template 
   templates - [nl, nt] template fluxes
 REVISION HISTORY:
   21-Apr-2005  MRB, NYU

(See /home/users/mb144/kcorrect/pro/fit/k_fit_spec.pro)


K_FIT_TEMPLATES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_fit_templates
 PURPOSE:
   run the template fitting code, with priming
 CALLING SEQUENCE:
   k_fit_templates [, nt= ]
 OPTIONAL INPUTS:
   nt - maximum number of templates to fit for (default 4)
 REVISION HISTORY:
   09-Apr-2005  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/fit/k_fit_templates.pro)


K_GALEX_TESTS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_galex_tests
 PURPOSE:
   runs tests on GALEX+SDSS test data
 CALLING SEQUENCE:
   k_galex_tests
 DATA DEPENDENCIES:
   $KCORRECT_DIR/data/test/galex_tests.fits (builds if not there)
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_galex_tests.pro)


K_GOODS_TESTS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_goods_tests
 PURPOSE:
   runs tests on GOODS test data
 CALLING SEQUENCE:
   k_goods_tests
 DATA DEPENDENCIES:
   $KCORRECT_DIR/data/test/goods_tests.fits (builds if not there)
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_goods_tests.pro)


K_GST_TESTS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_gst_tests
 PURPOSE:
   runs tests on GALEX+SDSS+2MASS test data
 CALLING SEQUENCE:
   k_gst_tests
 DATA DEPENDENCIES:
   $KCORRECT_DIR/data/test/gst_tests.fits (builds if not there)
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_gst_tests.pro)


K_IM_READ_BC03()

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       K_IM_READ_BC03()

 PURPOSE:
       Read the Bruzual & Charlot (2003) binary format population
       synthesis models into a convenient data structure.

 CALLING SEQUENCE:
       bc03 = k_im_read_bc03(isedfile=,isedpath,metallicity=,$
          age=,minwave=,maxwave=,bc03_extras=,/salpeter,/lr,$
          /silent)

 INPUTS:
       None required.  By default this routine reads the high
       resolution (hr), solar metallicity (m62), Chabrier SSP
       models. 

 OPTIONAL INPUTS:
       isedfile - read this binary SED rather than the default SSP
                  models 
       isedpath - full data path (with trailing slash) to ISEDFILE
       metallicity - SSP metallicity
          0 - Z=0.0001 (m22)
          1 - Z=0.0004 (m32)
          2 - Z=0.004  (m42)
          3 - Z=0.008  (m52)
          4 - Z=0.02   (m62) (Solar, default)
          5 - Z=0.05   (m72)
       age - return the SSP(s) corresponding to this scalar or vector
             age(s) [Gyr]
       minwave - crop the SSP spectra to this minimum wavelength (Angstrom)
       maxwave - crop the SSP spectra to this maximum wavelength (Angstrom)
       isolib - Isochrone library to use (default 'Padova1994')

 KEYWORD PARAMETERS:
       salpeter - read the Salpeter IMF models (default is to read
                  the Chabrier models)
       lr       - read the low resolution models (default is to read
                  the high resolution models)
       silent   - do not print any messages to STDOUT
       vac      - translate wavelengths to vacuum

 OUTPUTS:
       bc03 - data structure with the following fields:
          age  - vector of SSP ages [NAGE] (yr)
          wave - wavelength array [NPIX] (Angstrom)
          flux - SSP models [NPIX,NAGE] (L_sun/M_sun/A)

 OPTIONAL OUTPUTS:
       bc03_extras - data structure containing the extra parameters
                     associated with each SSP (see the BC03
                     documentation) 

 COMMENTS:
       N.B.  The environment variable ${bc03_dir} must be defined in
       your '.cshrc' indicating the *root* directory of the BC03
       models.  For example, in my '.cshrc' I have

              setenv bc03_dir ${HOME}/synthesis/bc03

       Note that this routine works with the Padova (1994) binary
       isochrones by default. Use ISOLIB input to use others. Using
       the ISEDFILE and ISEDPATH optional inputs you can read in an
       arbitrary BC03 SED in binary format.

 BUGS:
       It does not appear that this routine works with BC03 models
       *other* than the instantaneous burst models.  For example, if
       you use 'csp_galexev.f' to generate SFH-convolved models then
       those outputted models cannot be read with IM_READ_BC03().  I
       think the reason is that the time steps and spacing are
       modified, which changes the format of the binary file.

       If you solve this please let me know!

 INTERNAL SUPPORT ROUTINES:
       READ_EXTRAS(), GET_ELEMENT

 PROCEDURES USED:
       READFAST, STRUCT_TRIMTAGS(), STRUCT_ADDTAGS(), MATCH

 EXAMPLES:
       [1] Read the high-resolution, Salpeter IMF, Solar metallicity
           (Z=0.02) SSP models:

          IDL> bc03 = k_im_read_bc03()
          IDL> help, bc03, /str

       [2] Read the low-resolution, Salpeter IMF, LMC metallicity
           (Z=0.004) SSP models:

          IDL> bc03 = k_im_read_bc03(metallicity=2,/lr,/salpeter)

       [3] Read the high-resolution, Chabrier IMF, twice-solar
           metallicity (Z=0.05) SSP models and plot the 10 Gyr model: 

          IDL> bc03 = k_im_read_bc03(metallicity=5)
          IDL> indx = where(bc03.age eq 1E10)
          IDL> plot, bc03.wave, bc03.flux[*,indx], /xlog, /ylog

       [4] Read the high-resolution, Chabrier IMF, solar metallicity
           (Z=0.02) SSP models and extras and plot D4000 versus
           H-delta_A:  

          IDL> bc03 = k_im_read_bc03(bc03_extras=bce)
          IDL> plot, bce.d_4000_, bce.h_delta_a, xsty=3, ysty=3

       [5] Read a non-SSP SED in my temp subdirectory:

          IDL> bc03 = k_im_read_bc03(isedfile='mysed.ised',isedpath='temp/')

       [6] Retrieve the 12 Gyr Salpeter IMF, high-resolution SSP
           between 3000 and 10000 Angstroms.

          IDL> bc03 = k_im_read_bc03(/salpeter,age=12.0,minwave=3000,maxwave=1E4)

 MODIFICATION HISTORY:
       J. Moustakas, 2003 October 29, U of A, based in some part on
          IDL code originally written by C. Papovich
       jm03nov12uofa - added ISEDFILE and ISEDPATH optional inputs
                       and various bug fixes
       jm04mar01uofa - added AGE, MINWAVE, and MAXWAVE optional
                       inputs; changed wave, flux, and age to double
                       precision 

(See /home/users/mb144/kcorrect/pro/seds/k_im_read_bc03.pro)


K_INTERP_PEGASE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_interp_pegase
 PURPOSE:
   interpolate a set of PEGASE spectra to a specific time
 CALLING SEQUENCE:
   k_interp_pegase, peg, time [,nl=, lmin=, lmax=, /nolines, $
      /nocontinuum]
 INPUTS:
   peg - structure returned by read_peg
   time - desired time (in Myrs)
 OPTIONAL INPUTS:
   nl, lmin, lmax - structure of output spectrum
 KEYWORDS:
   /nolines - leave out the lines
   /nocontinuum - leave out the continuum
 REVISION HISTORY:
   25-Jul-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/seds/k_interp_pegase.pro)


K_LAMBDA_EFF

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_lambda_eff
 PURPOSE:
   Get effective wavelengths of filters in Angstroms
 CALLING SEQUENCE:
   efflam=k_lambda_eff([filterlist=, filterpath=, band_shift=])
 OPTIONAL INPUTS:
   filterlist - list of filter names (default
                ['sdss_u0.par','sdss_g0.par', 'sdss_r0.par',
                'sdss_i0.par', 'sdss_z0.par'])
   filterpath - path for filter files; default to kcorrect repository
   band_shift - blueshift to apply to bandpass; default to 0.0
 COMMENTS:
   Calculates the effective wavelength using the Schneider et al 1983
   defn (as quoted in Fukugita et al 1996). Returns results in
   Angstroms.
 PROCEDURES CALLED:
   k_load_filters
 REVISION HISTORY:
   17-Jan-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_lambda_eff.pro)


K_LAMBDA_TO_CENTERS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_lambda_to_centers
 PURPOSE:
   convert set of pixel edges to equivalent pixels centers
 CALLING SEQUENCE:
   lambda_centers=k_lambda_to_centers(lambda_edges)
 INPUTS:
   lambda_edges - [N+1] pixel edges 
 OUPUTS:
   lambda_centers - [N] pixel centers 
 REVISION HISTORY:
   05-Apr-2005  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_lambda_to_centers.pro)


K_LAMBDA_TO_EDGES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_lambda_to_edges
 PURPOSE:
   convert set of pixel centers to equivalent pixels edges
 CALLING SEQUENCE:
   lambda_edges=k_lambda_to_edges(lambda_centers)
 INPUTS:
   lambda_centers - [N] pixel centers 
 OUPUTS:
   lambda_edges - [N+1] pixel edges 
 REVISION HISTORY:
   30-Apr-2003  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_lambda_to_edges.pro)


K_LINEAR_TRANSFORMS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_linear_transforms
 PURPOSE:
   calculate transformations between filter systems
 CALLING SEQUENCE:
   k_linear_tranforms
 COMMENTS:
   Creates plots in k_linear_transforms.ps
   Prints lineareqs.tex format linear equations to screen for input into
 REVISION HISTORY:
   10-Feb-2004  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_linear_transforms.pro)


K_LOAD_FILTERS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_load_filters
 PURPOSE:
   Load the filter information from a list of files
 CALLING SEQUENCE:
   k_load_filters, filterlist, filter_nlambda, filter_lambda, filter_pass [, $
       filterpath=filterpath
 INPUTS:
   filterlist      - list of files with filter information
 OPTIONAL INPUTS:
   filterpath      - path to use for filters if the filterlist files 
                     do not exist (if this has more than one element
                     they are checked in order)
 OUTPUTS:
   filter_nlambda  - number of elements in each filter specification
   filter_lambda   - wavelength for each element
   filter_pass     - value for each element
 OPTIONAL INPUT/OUTPUTS:
 COMMENTS:
   Filters should be in the Yanny parameter format with columns:
          lambda
          pass
   This code caches the filters it reads in. 
 PROCEDURES CALLED:
   yanny_readone (idlutils)
 REVISION HISTORY:
   04-Jan-2002  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_load_filters.pro)


K_LOAD_VMATRIX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_load_vmatrix
 PURPOSE:
   Load the template information 
 CALLING SEQUENCE:
   k_load_vmatrix, vmatrix, lambda [, vfile=, vpath=, lfile=, vname= ]
 OPTIONAL INPUTS:
   vname - name of fit (default 'default')
   vfile - ascii format file with vmatrix in it (default
           vmatrix.[vname].dat)
   lfile - ascii format file with wavelengths in it (in Angstroms)
           (default lambda.[vname].dat)
   vpath - path to use for vfile if it does not exist 
           (if this has more than one element they are checked in order)
           [default $KCORRECT_DIR/data/templates]
 OUTPUTS:
   vmatrix   - [nl,nv] template
   lambda    - [nl+1] pixel edges of template
 COMMENTS:
   Use lambda=k_lambda_to_centers(lambda) to get [nl] pixel centers
   from [nl+1] pixel edges.
 REVISION HISTORY:
   04-Jun-2003  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_load_vmatrix.pro)


K_LUPS2MAGGIES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_lups2maggies
 PURPOSE:
   Convert SDSS luptitudes ("asinh" magnitudes) to maggies
 CALLING_SEQUENCE:
   maggies= k_lups2maggies(lups [, lups_err, maggies_err=, bvalues=])
 INPUTS:
   lups - [Nb, N] luptitudes (the "asinh" magnitudes from the
          SDSS databases). Unless you set bvalues yourself, Nb=5
 OUTPUTS:
   maggies - [Nb,N] maggies (10.^(-0.4*magnitude))
 OPTIONAL INPUTS:
   lups_err - [Nb, N] 1 sigma errors in luptitudes
   bvalues - "b" value for luptitude definition for each band
             (default [1.4D-10, 0.9D-10, 1.2D-10, 1.8D-10, 7.4D-10])
 OPTIONAL OUTPUTS:
   maggies_err - [Nb, N] 1 sigma errors in maggies
                 (fails if lups_err not set)
 COMMENTS:
   Conversion from luptitudes to maggies is:
      maggies = 2 b sinh( - ln(b) - 0.4 ln(10) lups)
   This is linear when maggies ~ b, identical to maggies 
   for maggies >> b

   Conversion of the errors is:
      maggies_err = 2 b cosh( -ln(b) - 0.4 ln(10) lups) (0.4 ln 10) lups_err
 
   If you set bvalues yourself, the code assumes Nb=n_elements(bvalues)
   for the purposes of intepreting the "lups" input.
 REVISION HISTORY:
   28-Mar-2002  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_lups2maggies.pro)


K_MAGGIES2LUPS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_maggies2lups
 PURPOSE:
   Convert maggies to SDSS luptitudes ("asinh" magnitudes) 
 CALLING_SEQUENCE:
   lups= k_maggies2lups(maggies [, maggies_err, lups_err=, bvalues=])
 INPUTS:
   maggies - [Nb,N] maggies (10.^(-0.4*magnitude)). Unless you set
             bvalues yourself, Nb=5
 OUTPUTS:
   lups - [Nb, N] luptitudes (the "asinh" magnitudes used by the
          SDSS databases). 
 OPTIONAL INPUTS:
   bvalues - "b" value for luptitude definition for each band
             (default [1.4D-10, 0.9D-10, 1.2D-10, 1.8D-10, 7.4D-10])
   maggies_err - [Nb, N] 1 sigma errors in maggies
 OPTIONAL OUTPUTS:
   lups_err - [Nb, N] 1 sigma errors in luptitudes
              (fails if maggies_err not set)
 COMMENTS:
   Conversion from maggies to lups is:
      lups = - 2.5 ln(b) / ln(10) - 2.5 asinh( 0.5 maggies/b) / ln(10)
   This is linear when maggies ~ b, identical to maggies 
   for maggies >> b

   Conversion of the errors is:
      lups_err = 2.5 maggies_err / ( 2 b ln(10) sqrt(1 + (m/2b)^2)) 
 
   If you set bvalues yourself, the code assumes Nb=n_elements(bvalues)
   for the purposes of intepreting the "lups" input.
 REVISION HISTORY:
   28-Mar-2002  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_maggies2lups.pro)


K_MINERROR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_minerror
 PURPOSE:
   apply a minimum magnitude to error to a set of inverse variances
 CALLING SEQUENCE:
   k_minerror, maggies, maggies_ivar [, minerrors]
 INPUTS:
   maggies - [nk, n] maggies
 INPUTS/OUTPUTS:
   maggies_ivar - [nk, n] inverse variances (changed on output)
 OPTIONAL INPUTS:
   minerrors - [nk] minimum errors to apply (default [0.05, 0.02,
               0.02, 0.02, 0.03] to represent calibration
               uncertainties in SDSS ugriz bands)
 COMMENTS:
   Adds minerror in quadrature to each band.
 BUGS:
   check "factor"
 REVISION HISTORY:
   07-Feb-2002  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_minerror.pro)


K_MKSPEC_PEGASE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_mkspec_pegase
 PURPOSE:
   read in PEGASE.2 models, add dust, convolve with SFH
 CALLING SEQUENCE:
   k_mkspec_pegase, vmatrix, lambda, metallicity, dust, sfhpars [, $
      pegasepath=, attime=, maxage=, minage=, lmin=, lmax=, nl=, /nolines]
 INPUTS:
   metallicity - string with metallicity name
   dust - witt dust name 
   sfhpars - structure describing SFH
 OPTIONAL INPUTS:
   pegasepath - directory with PEGASE results (default
                $DATA/specmodels/PEGASE.2)
   attime - observe at look back time of this (default 0.)
   [min|max]age - minimum and maximum ages of populations (default none)
   l[min|max] - wavelength limits (default 1250., 33333.)
   nl - number of pixels (default 5000)
   pversion - prefix for spectra names (default 'mrb')
 KEYWORDS:
   /nolines - don't use the lines
 OUTPUTS:
   vmatrix - [nl, n_spectra] output spectra
   lambda - [nl+1] pixel edges
 COMMENTS:
   Requires you have created PEGASE.2 models in the files:
     $DATA/specmodels/PEGASE.2/[pversion]_spectra.0.[metallicity].dat
 PROCEDURES CALLED:
   k_load_ascii_table
   k_read_peg 
 REVISION HISTORY:
   25-Jul-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/seds/k_mkspec_pegase.pro)


K_NMF_MMATRIX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_mmatrix
 PURPOSE:
   make grid of BC03 model spectra for fitting
 CALLING SEQUENCE:
   k_nmf_mmatrix [, prefix=, back=, lmin=, lmax=, dusts= ]
 OPTIONAL INPUTS:
   prefix - prefix to use for output files (default 'k_nmf')
   back - # of Gyrs in the past to use for 'early' file and in future
          for 'late' file
   lmin, lmax - limits of spectrum output (Angstroms; default 600, 30000)
   navloglam - number of wavelengths in final output
   nagesmax - maximum number of instantantaneous burst ages to use
   vdisp - smooth models to this velocity dispersion, in km/s (default 300)
   minzf, maxzf - minimum and maximum redshifts of observation
                  (default 0., 1.)
   nzf - number of redshifts of observations
   dusts - dust models (Witt & Gordon) to use for
           extinction. Structure with elements:
              .GEOMETRY - geometry from WG (default 'dusty', 'dusty', 'dusty')
              .DUST - type of dust from WG (default 'MW', 'MW', 'MW')
              .STRUCTURE - structure of dust from WG (default 'c', 'c', 'c')
              .TAUV - optical depth at V (default 0., 1., 3.)
 COMMENTS:
   makes [Nobs, Nsfh] matrix where 
        Nobs = nlambda + nz*nfilters
   units are absolute maggies per solar mass
 BUGS:
   needs to output *unsmoothed* spectra 
   should have better constrained emission lines
   make sure DEEP filters are fixed 
   include Draine & Li templates
 REVISION HISTORY:
   29-Jul-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/seds/k_nmf_mmatrix.pro)


K_NMF_MMATRIX_LRG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_mmatrix_lrg
 PURPOSE:
   make grid of BC03 model spectra for fitting
 CALLING SEQUENCE:
   k_nmf_mmatrix [, prefix=, back=, lmin=, lmax=, dusts= ]
 OPTIONAL INPUTS:
   prefix - prefix to use for output files (default 'k_nmf')
   back - # of Gyrs in the past to use for 'early' file
   lmin, lmax - limits of spectrum output (Angstroms; default 600, 30000)
   navloglam - number of wavelengths in final output
   nagesmax - maximum number of instantantaneous burst ages to use
   vdisp - smooth models to this velocity dispersion, in km/s (default 300)
   minzf, maxzf - minimum and maximum redshifts of observation
                  (default 0., 1.)
   nzf - number of redshifts of observations
   dusts - dust models (Witt & Gordon) to use for
           extinction. Structure with elements:
              .GEOMETRY - geometry from WG (default 'dusty', 'dusty', 'dusty')
              .DUST - type of dust from WG (default 'MW', 'MW', 'MW')
              .STRUCTURE - structure of dust from WG (default 'c', 'c', 'c')
              .TAUV - optical depth at V (default 0., 1., 3.)
 COMMENTS:
   makes [Nobs, Nsfh] matrix where 
        Nobs = nlambda + nz*nfilters
   units are absolute maggies per solar mass
 BUGS:
   needs to output *unsmoothed* spectra 
   should have better constrained emission lines
   make sure DEEP filters are fixed 
   include Draine & Li templates
 REVISION HISTORY:
   29-Jul-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/seds/k_nmf_mmatrix_lrg.pro)


K_NMF_MMATRIX_PHOTOZ

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_mmatrix_photoz
 PURPOSE:
   make grid of BC03 model spectra for fitting
 CALLING SEQUENCE:
   k_nmf_mmatrix [, prefix=, back=, lmin=, lmax=, dusts= ]
 OPTIONAL INPUTS:
   prefix - prefix to use for output files (default 'k_nmf')
   back - # of Gyrs in the past to use for 'early' file
   lmin, lmax - limits of spectrum output (Angstroms; default 600, 30000)
   navloglam - number of wavelengths in final output
   nagesmax - maximum number of instantantaneous burst ages to use
   vdisp - smooth models to this velocity dispersion, in km/s (default 300)
   minzf, maxzf - minimum and maximum redshifts of observation
                  (default 0., 1.)
   nzf - number of redshifts of observations
   dusts - dust models (Witt & Gordon) to use for
           extinction. Structure with elements:
              .GEOMETRY - geometry from WG (default 'dusty', 'dusty', 'dusty')
              .DUST - type of dust from WG (default 'MW', 'MW', 'MW')
              .STRUCTURE - structure of dust from WG (default 'c', 'c', 'c')
              .TAUV - optical depth at V (default 0., 1., 3.)
 COMMENTS:
   makes [Nobs, Nsfh] matrix where 
        Nobs = nlambda + nz*nfilters
   units are absolute maggies per solar mass
 BUGS:
   needs to output *unsmoothed* spectra 
   should have better constrained emission lines
   make sure DEEP filters are fixed 
   include Draine & Li templates
 REVISION HISTORY:
   29-Jul-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/seds/k_nmf_mmatrix_photoz.pro)


K_NMF_SPDATA[1]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata
 PURPOSE:
   put together sparse data for nmf fitting
 CALLING SEQUENCE:
   k_nmf_spdata
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Takes data from sources:
     1. SDSS photometric survey
             ugrizJHK magnitudes
     2. SDSS spectroscopic survey
             optical spectrum smoothed to 300 km/s resolution
     3. GALEX-SDSS matrix
             FNugriz magnitudes
     4. DEEP data
     5. GOODS redshift sample data
 
   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_goods.pro)


K_NMF_SPDATA[2]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata
 PURPOSE:
   put together sparse data for nmf fitting
 CALLING SEQUENCE:
   k_nmf_spdata
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Takes data from sources:
     1. SDSS photometric survey
             ugrizJHK magnitudes
     2. SDSS spectroscopic survey
             optical spectrum smoothed to 300 km/s resolution
     3. GALEX-SDSS matrix
             FNugriz magnitudes
     4. DEEP data
     5. GOODS redshift sample data
 
   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_lrg.pro)


K_NMF_SPDATA[2]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata
 PURPOSE:
   put together sparse data for nmf fitting
 CALLING SEQUENCE:
   k_nmf_spdata
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Takes data from sources:
     1. SDSS photometric survey
             ugrizJHK magnitudes
     2. SDSS spectroscopic survey
             optical spectrum smoothed to 300 km/s resolution
     3. GALEX-SDSS matrix
             FNugriz magnitudes
     4. DEEP data
     5. GOODS redshift sample data
 
   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_photoz.pro)


K_NMF_SPDATA[3]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata
 PURPOSE:
   put together sparse data for nmf fitting
 CALLING SEQUENCE:
   k_nmf_spdata
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Takes data from sources:
     1. SDSS photometric survey
             ugrizJHK magnitudes
     2. SDSS spectroscopic survey
             optical spectrum smoothed to 300 km/s resolution
     3. GALEX-SDSS matrix
             FNugriz magnitudes
     4. DEEP data
     5. GOODS redshift sample data
 
   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata.pro)


K_NMF_SPDATA[4]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata
 PURPOSE:
   put together sparse data for nmf fitting
 CALLING SEQUENCE:
   k_nmf_spdata
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Takes data from sources:
     1. SDSS photometric survey
             ugrizJHK magnitudes
     2. SDSS spectroscopic survey
             optical spectrum smoothed to 300 km/s resolution
     3. GALEX-SDSS matrix
             FNugriz magnitudes
     4. DEEP data
     5. GOODS redshift sample data
 
   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_save.pro)


K_NMF_SPDATA_SPEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata_spec
 PURPOSE:
   put together spectroscopic data for nmf fitting
 CALLING SEQUENCE:
   k_nmf_spdata_spec
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Takes data from sources:
     1. SDSS spectroscopic survey
             optical spectrum smoothed to 300 km/s resolution
 
   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_spec.pro)


K_NMF_SPDATA_SWIRE_BLUE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata_swire_blue
 PURPOSE:
   put together blue SWIRE catalog to fit
 CALLING SEQUENCE:
   k_nmf_spdata_swire_blue
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_swire_blue.pro)


K_NMF_SPDATA_SWIRE_RED[1]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata_swire_red
 PURPOSE:
   put together red SWIRE catalog to fit
 CALLING SEQUENCE:
   k_nmf_spdata_swire_red
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_swire.pro)


K_NMF_SPDATA_SWIRE_RED[2]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_nmf_spdata_swire_red
 PURPOSE:
   put together red SWIRE catalog to fit
 CALLING SEQUENCE:
   k_nmf_spdata_swire_red
 COMMENTS:
   Assumes k_nmf_mmatrix has been run.

   Creates a file k_nmf_spdata.fits of the following form:
     HDU0: NULL
     HDU1: single-element structure of the form:
              .NX - number of possible observations for each galaxy
              .NY - number of galaxies
              .ROWSTART[NY] - starting position in data block for
                              each galaxy
              .NXROW[NY] - number of observations for each galaxy
     HDU2: [NVAL] data block of floating-point values in absolute
           maggies. If you constructed this sparse-sampling into a 
           [NX, NY] matrix it would look like (ROWSTART and NXROW
           tell you how to do so):
            NY=Ngals
            NX=Ndata= nlambda+nfilter*nz
            [0:nlambda-1L, *] is the spectral information
            [nlambda:Ndata-1, *] is through the filters at each redshift
     HDU3: [NVAL] data block of floating-point inverse variances
     HDU4: [NVAL] block of column positions for each row (ie. which
           observations exist for each galaxy (ROWSTART and NXROW
           tell you to index this list)
     HDU5: [Ndata]; effective central wavelength for each data point
     HDU6: [Ngals]; distance (in redshift units) to each object
     HDU7: [Ngals]; heliocentric redshift of each object
   This file is readable by k_nmf_run.pro
   
 REVISION HISTORY:
   23-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/samples/k_nmf_spdata_swire_red.pro)


K_PHOTOZ_TEST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_photoz_test
 PURPOSE:
   test photometric redshifts on SDSS data
 CALLING SEQUENCE:
   k_photoz_test
 REVISION HISTORY:
   June 22, 2005 MRB

(See /home/users/mb144/kcorrect/pro/utils/k_photoz_test.pro)


K_PLOT_BC_COLORS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_plot_bc_colors
 PURPOSE:
   plot colors vs time for various models
 CALLING SEQUENCE:
   k_plot_bc_colors
 REVISION HISTORY:
   02-May-2005  MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_plot_bc_colors.pro)


K_PLOT_FITS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_plot_fits
 COMMENTS:
   Selects some representative galaxies and plots their fit SFH.
 REVISION HISTORY:
   30-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/utils/k_plot_fits.pro)


K_PLOT_TEMPLATES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_plot_templates
 COMMENTS:
   Creates:
     templates_spec.ps - summary plot of the spectra of each template
     templates_sfh.ps - summary plot of SFH of each template
 REVISION HISTORY:
   30-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/utils/k_plot_templates.pro)


K_PRINT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_print
 PURPOSE:
   set up a postscript file output
 CALLING SEQUENCE:
   k_print, filename= [, tiny=, axis_char_scale=, pold=, xold=, $
       yold=, colorname=, xsize=, ysize= ]
 INPUTS:
   filename - postscript file name for output
 OPTIONAL INPUTS:
   xsize, ysize - size (inches) of output file
 OPTIONAL INPUT/OUTPUTS:
   axis_char_scale - scaling of fonts
   tiny - value for tiny numbers
 OPTIONAL OUTPUTS:
   colorname - names of available colors
   pold, xold, yold - if these exist, sets to old values of !P, !X, !Y 
                      (for input into k_end_print)
 REVISION HISTORY:
   26-Feb-2003  Written by M. Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_print.pro)


K_PROJECTION_TABLE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_projection_table
 PURPOSE:
   Create lookup table for calculating maggies corresponding to spectra
 CALLING SEQUENCE:
   k_projection_table, rmatrix, vmatrix, lambda, zvals, filterlist, $
      [zmax=, zmin=, nz=, filterpath=, band_shift= ]
 INPUTS:
   vmatrix       - templates spanning SED space [N_lambda, N_dim]
   lambda        - wavelengths for orthogonal templates [N_lambda]
   filterlist    - list of files with filter information [N_band]
 OPTIONAL INPUTS:
   filterpath    - path for filters (default '$KCORRECT_DIR/data/filters')
   band_shift    - shift the bands blueward by factor (1+band_shift)
 KEYWORDS:
   silent        - shut up
 OUTPUTS:
   rmatrix       - look up table for vmatrix and filter information 
                   [N_z, N_dim, N_band]
   zvals         - look up table for rmatrix [N_z]
 OPTIONAL INPUT/OUTPUTS:
   zmin, zmax, nz  - settings for setting zvals (default 0., 2., 1000)
 COMMENTS:
   This tabulates the projection of each basis element v onto each
   filter k, as a function of redshift. You only have to perform this
   projection once, since every spectrum we will deal with will be a
   linear combination of the basis elements b. To get a particular
   redshift, you interpolate the rmatrix in the z direction.  Keep in
   mind that this only creates the r matrix for a specific redshift
   range; e.g. you have to change the defaults in order to consider
   redshifts greater than unity.
 PROCEDURES CALLED:
   k_load_filters
   Dynamic link to idl_k_projection_table.c in libkcorrect.so
 REVISION HISTORY:
   05-Jan-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/k_projection_table.pro)


K_PROJECT_FILTERS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_project_filters
 PURPOSE:
   project a flux onto a bandpass or set of bandpasses
 CALLING SEQUENCE:
   maggies=k_project_filters(lambda, flux [, filterlist=, $
      filterpath=, band_shift=])
 INPUTS:
   lambda - [N+1] wavelength in angstroms at pixel edges
   flux   - [N] flux in ergs/cm^2/s/A at pixel centers
 OPTIONAL INPUTS:
   filterlist - list of filters (default to sdss set)
   filterpath - paths to look for filters in
   band_shift - blueward shift of bandpasses
 COMMENTS:
   More or less a wrapper on k_projection_table.
   Outputs are in maggies (10.^(-0.4*magnitude)). 
 REVISION HISTORY:
   17-Jan-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_project_filters.pro)


K_QA_NMF

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_qa_nmf
 COMMENTS:
   Creates k_qa_nmf.ps, which has a number of QA plots on the NMF 
     fitting results, including colors as a function of redshift,
     color-color plots, spectra vs. model spectra, star-formation 
     histories, etc.
   Also determines:
     mass-weighted metallicity of each template
     mass-weighted age of each template 
     passive evolution estimates for each template, assuming constant
       SFR into the future, based on looking 0.5 Gyr younger
     makes standard vmatrix/lambda files 
 REVISION HISTORY:
   30-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/seds/k_qa_nmf.pro)


K_READ_ASCII_TABLE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_read_ascii_table
 PURPOSE:
   Read an ascii file in my standard format, which is:
 
  <ndim> <size_{0}> ... <size_{ndim-1}>
  <entry_0>
  <entry_1>
  ...
  <entry_n>
  ...
  <entry_{size_0*size_1*..*size_{ndim-1}-1>
 
  where the table element [k,j,i] (for ndim==3) would be the 
  entry element n, where n=i*size_2*size1+j*size2+k
 CALLING SEQUENCE:
   k_read_ascii_table,table,filename
 INPUTS:
   filename  - file containing table
 OPTIONAL INPUTS:
 OUTPUTS:
   table   - table to read
 OPTIONAL INPUT/OUTPUTS:
 COMMENTS:
   Only reads floating point tables.
 EXAMPLES:
    Here is an example of reading a [500,10] array from a file:
 
    IDL> $wc bmatrix.default.dat   
       5001    5003  130037 bmatrix.default.dat
    IDL> $head bmatrix.default.dat
               2          10         500
       4.1921895303265806e-04
       4.1921245277927205e-04
       4.1920432703966440e-04
       4.1919374271866136e-04
       4.1918060198276090e-04
       4.1916390305939648e-04
       4.1914261546946777e-04
       4.1911632959028446e-04
       4.1908366349717002e-04
    IDL> k_read_ascii_table,bmatrix,'bmatrix.default.dat'
    % Compiled module: K_READ_ASCII_TABLE.
    IDL> help,bmatrix
    BMATRIX         DOUBLE    = Array[500, 10]

 REVISION HISTORY:
   17-Jan-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_read_ascii_table.pro)


K_READ_BASEL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_read_basel
 PURPOSE:
   read in spectrum from a Basel spectrum file
 CALLING SEQUENCE:
   k_read_basel, lambda, flux, filename [, teff=, logg=, mh=, vturb=, xh= ]
 INPUTS:
   filename - file containing Basel format spectrum
 OUTPUTS:
   lambda - wavelengths at pixel centers
   flux - flux at each pixel
   teff, logg, mh, vturb, xh - basel parameters in file
 COMMENTS:
   1221 elements *hard-coded*
 REVISION HISTORY:
   17-Jan-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/seds/k_read_basel.pro)


K_READ_DALE.PRO

[Previous Routine] [Next Routine] [List of Routines]
NAME:
  k_read_dale.pro
PURPOSE:
  reads the Dale SEDs
CALLING SEQUENCE:
  dale=k_read_dale()
OUTPUTS:
  dale - structure with 
             .LAMBDA - wavelength in angstroms
             .FLUX - flux 
BUGS:
  What units are fluxes in?
  Untested?
REVISION HISTORY:
  2004-Dec-20  started by Hogg
_

(See /home/users/mb144/kcorrect/pro/seds/k_read_dale.pro)


K_READ_TBL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_read_tbl
 PURPOSE:
   Read 2MASS style table into IDL structure
 CALLING SEQUENCE:
   tbl= k_read_tbl(filename)
 INPUTS:
   filename - file name
 BUGS:
   not well commented
 REVISION HISTORY:
   Spring 2003, Written Malcolm Britton

(See /home/users/mb144/kcorrect/pro/utils/k_read_tbl.pro)


K_RECONSTRUCT_MAGGIES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_reconstruct_maggies
 PURPOSE:
   Reconstruct AB galaxy maggies given an observed redshift 
 CALLING SEQUENCE:
   k_reconstruct_maggies,coeffs,redshift,reconstruct_maggies [, $
       band_shift=, zvals=, rmatrix=, vmatrix=, lambda=, $
       filterpath=, filterlist=, zmin=, zmax=, nz= ]
 INPUTS:
   coeffs        - [nv, ngals] coefficients 
   redshift      - [ngals] redshift for each galaxy (where you want to
                   calculate maggies in model) 
 KEYWORDS:
   silent        - shut up
 OUTPUTS:
   reconstruct_maggies - [nk, ngals] maggies of each
 OPTIONAL INPUT/OUTPUTS:
   filterlist    - [nk] list of files with filter information 
   filterpath    - path for filterlist (default $KCORRECT_DIR/data/filters)
   vmatrix       - [nl,nk] templates spanning SED space 
   lambda        - [nl+1] wavelengths for templates 
   rmatrix       - [nz, nv, nk] look up table for bmatrix and filter 
                   information 
   zvals         - [nz] look up table for rmatrix 
   zmin, zmax    - redshifts limits of lookup table (default 0., 2)
   nz            - number of redshifts in lookup table (default 1000)
   band_shift    - shift to apply to bandpasses (default 0.)
 COMMENTS:
   Reconstruct AB galaxy maggies given an observed redshift and a
   shift to apply to the bandpasses (band_shift) under the assumption
   that the bolometric flux is conserved. To reconstruct the
   observed galaxy maggies:
 
      k_reconstruct_maggies,coeffs,redshift,reconstruct_maggies
 
   To construct what would be observed if the galaxies were observed 
   at z=0. through a bandpass blueshifted by z=0.1:
 
      k_reconstruct_maggies,coeffs,replicate(0.,ngals),reconstruct_maggies, $
         band_shift=replicate(0.1,ngals)
 EXAMPLES:
   Given coeffs from a call to k_fit_coeff or kcorrect, create 
   reconstructed maggies for each galaxy using default templates
 
   IDL> k_reconstruct_maggies,coeffs,redshift,reconstruct_maggies
  
   To K-correct all the maggies to the same redshift (0.1):

   IDL> k_reconstruct_maggies, coeffs,replicate(0.1,n_elements(redshift)), $
        reconstruct_maggies
 REVISION HISTORY:
   05-Jan-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/k_reconstruct_maggies.pro)


K_RECONSTRUCT_SPEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_reconstruct_spec
 PURPOSE:
   Reconstruct galaxy rest-frame spectrum given a fit
 CALLING SEQUENCE:
   k_reconstruct_spec, coeffs, loglam, flux [, vname=, vdisp=, $
        /nolines, /noextinct, /init, nt=, mass=, metallicity=, $
        b300=, b1000=]
 INPUTS:
   coeffs - [NT, NGALS] coefficients 
 OUTPUTS:
   loglam - [NL, NGALS] wavelengths
   flux - [NL, NGALS] fluxes (ergs cm-2 s-1 A-1)
 OPTIONAL KEYWORDS
   /nolines - do not include lines
   /noextinct - show unextincted spectra
   /init - don't make a spectrum, just initialize
   /reset - create the k_nmf_tspec.fits file if it doesn't exist
 OPTIONAL INPUTS:
   vname - name of fit to use (default 'default')
   vdisp - smooth with this velocity dispersion
 OPTIONAL OUTPUTS:
   nt - total number of templates
   mass, metallicity - properties of template fit;
                       mass is current stellar mass and is in units of 
                       1 solar mass / (D/10pc)^2
   b300 - star-formation within last 300Myrs relative to average
          star-formation rate
   b1000 - star-formation within last 1Gyrs relative to average
           star-formation rate
 COMMENTS:
   If coeffs are standard, returns units of erg/cm^2/s/A
   If vdisp, /nolines, and /noextinct 
   If lines are included, they are always smoothed at 300 km/s vdisp
   Bases fit on file:
      $KCORRECT_DIR/data/templates/k_nmf_derived.[vname].fits
 REVISION HISTORY:
   21-Apr-2005  Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/fit/k_reconstruct_spec.pro)


K_RUN_NMF

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_run_nmf
 PURPOSE:
   run the nmf fitting code to get basis spectra
 CALLING SEQUENCE:
   k_run_nmf [, nt=, niter= ]
 OPTIONAL INPUTS:
   nt - number of templates to fit for (default 6)
   niter - number of iterations of fit (default 1000)
 OPTIONAL KEYWORDS:
   /qa - make qa plots at end
   /reset - ignore k_nmf_soln file if it exists
 COMMENTS:
   Requires k_nmf_mmatrix and k_nmf_spdata to have been run. 
   Uses nmf_sparse for fitting. Puts results in k_nmf_soln.fits.
   Checks for existing k_nmf_soln.fits to use as starting
   point. Otherwise nmf_sparse chooses random starting point.
 REVISION HISTORY:
   29-Nov-2004  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/fit/k_run_nmf.pro)


K_RUN_TESTS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_run_tests
 PURPOSE:
   runs tests on test data
 CALLING SEQUENCE:
   k_run_tests
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_run_tests.pro)


K_SDSSFIX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_sdssfix
 PURPOSE:
   Take SDSS database asinh magnitudes and errors and "fixes" them
 CALLING SEQUENCE:
   k_sdssfix, mags, mags_err, maggies, maggies_ivar [, /standard, aboff=]
 INPUTS:
   mags - input asinh magnitudes (luptitudes)
   mags_err - input uncertainties in mags
 OUTPUTS:
   maggies - best AB maggies to use 
   maggies_ivar - best inverse variance to use
 KEYWORDS:
   /standard - assume standard magnitudes, not luptitudes
 COMMENTS:
   This converts from SDSS database asinh magnitudes to AB maggies. 

   It "fixes" errors in the sense that for "bad" measurements or
   errors you assign values which are not absurd. Not necessary for
   Princeton-style input (which sets ivar to zero as
   appropriate). 
  
   Also adds errors in quadrature:
     sigma(ugriz) = [0.05, 0.02, 0.02, 0.02, 0.03]
   to account for calibration uncertainties.
 BUGS:
   Needs better tracking of Eisenstein numbers
 REVISION HISTORY:
   07-Feb-2002  Written by Mike Blanton, NYU
   03-Jun-2003  Updated to v3_0 by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_sdssfix.pro)


K_SDSS_BELL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_sdss_bell
 PURPOSE:
   Bell and de Jong stellar masses given SDSS absolute magnitudes
 CALLING SEQUENCE:
   smass= k_sdss_bell(absmag)
 INPUTS:
   absmag - [5, N] SDSS ugriz absolute magnitudes
 OUTPUTS:
   smass - stellar mass in solar masses
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_sdss_bell.pro)


K_SDSS_ERR2IVAR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_sdss_err2ivar
 PURPOSE:
   convert SDSS database magnitude error values to inverse variances
 CALLING SEQUENCE:
   k_sdss_err2ivar, err [, /verbose]
 INPUTS:
   err - [5, N] error values
 KEYWORDS:
   /verbose - loud about possible mistakes
 COMMENTS:
   This "fixes" errors in the sense that for "bad" measurements or
   errors you assign values which are not absurd. Not necessary for
   Princeton-style input (which sets ivar to zero as
   appropriate). 
 REVISION HISTORY:
   07-Feb-2002  Written by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_sdss_err2ivar.pro)


K_SDSS_TESTS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_sdss_tests
 PURPOSE:
   runs tests on SDSS test data
 CALLING SEQUENCE:
   k_sdss_tests
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_sdss_tests.pro)


K_SDSS_TESTS_GENERIC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_sdss_tests_generic
 PURPOSE:
   runs tests on SDSS test data
 CALLING SEQUENCE:
   k_sdss_tests
 COMMENTS:
   Reads in spobj_test.fits and runs:
      sdss_kcorrect to get corrections, evaluates chi2
      does own corrections, runs kcorrect, evaluates chi2
      compares these two
   Reads in obj_test.fits and runs:
      sdss_kcorrect to get corrections, evaluates chi2
      does own corrections, runs kcorrect, evaluates chi2
      compares these two
   Compares all four of the above results.
 DATA DEPENDENCIES:
   $KCORRECT_DIR/data/test/obj_test.fits    (calibObj version)
   $KCORRECT_DIR/data/test/spobj_test.fits  (tsObj version)
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_sdss_tests_generic.pro)


K_SDSS_TESTS_LRG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_sdss_tests_lrg
 PURPOSE:
   runs tests on SDSS test data
 CALLING SEQUENCE:
   k_sdss_tests_main
 DATA DEPENDENCIES:
   $KCORRECT_DIR/data/test/sdss_tests_lrg.fits (builds if not there)
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_sdss_tests_lrg.pro)


K_SDSS_TESTS_MAIN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_sdss_tests_main
 PURPOSE:
   runs tests on SDSS test data
 CALLING SEQUENCE:
   k_sdss_tests_main
 DATA DEPENDENCIES:
   $KCORRECT_DIR/data/test/sdss_tests_main.fits (builds if not there)
 REVISION HISTORY:
   2005-04-07 MRB, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_sdss_tests_main.pro)


K_SMOOTH

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_smooth
 PURPOSE:
   gaussian smooth a spectrum
 CALLING SEQUENCE:
   outflux= k_smooth(loglam, flux, vdisp)
 INPUTS:
   loglam - log_{10} of the wavelength in Angstroms
   flux - input flux
   vdisp - gaussian velocity width in km/s (ignores if < 10 km/s)
 OUTPUTS:
   outflux - smoothed flux
 WARNINGS:
   Does NOTHING if vdisp < 10 km/s
 REVISION HISTORY:
   05-May-2005  Michael Blanton (NYU)

(See /home/users/mb144/kcorrect/pro/utils/k_smooth.pro)


K_SOLAR_MAGNITUDES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   k_solar_magnitudes
 PURPOSE:
   calculate the solar magnitudes for bandpasses
 CALLING SEQUENCE:
   solar_magnitudes= k_solar_magnitudes([band_shift=, filterlist=, $
                       filterpath=, solarname=]) 
 OPTIONAL INPUTS:
   filterlist - list of filters (default
                ['sdss_u0.par','sdss_g0.par','sdss_r0.par','sdss_i0.par', $
                 'sdss_z0.par'])
   filterpath - path in which to look for filters
   band_shift - shift to apply to band passes
   solarname - name of solar model
 OUTPUTS:
   solar_magnitudes - absolute magnitude of sun in specified bands
 EXAMPLES:
   IDL> print,k_solar_magnitudes()
    K_READ_BASEL: 1 block(s) of spectra
     K_PROJECTION_TABLE: Creating rmatrix ...
     K_PROJECTION_TABLE: Done.
          6.3800855       5.1210220       4.6432452       4.5322263       4.5107040
   IDL> print,k_solar_magnitudes(band_shift=0.1)
    K_READ_BASEL: 1 block(s) of spectra
     K_PROJECTION_TABLE: Creating rmatrix ...
     K_PROJECTION_TABLE: Done.
          6.7792312       5.4336204       4.7553857       4.5749466       4.5155073
 REVISION HISTORY:
   17-Jan-2002  Translated to IDL by Mike Blanton, NYU

(See /home/users/mb144/kcorrect/pro/utils/k_solar_magnitudes.pro)


K_SPEC_PEGASE