コード例 #1
0
 def create_model(self, fname, npoly, npixstep, minvector, zfindobj, flux,
                  ivar):
     """Return the best fit model for a given template at a
         given redshift.
     """
     try:
         pixoffset = zfindobj.pixoffset
         temps = read_ndArch(
             join(environ['REDMONSTER_TEMPLATES_DIR'], fname))[0]
         pmat = n.zeros((self.npixflux, npoly + 1))
         this_temp = temps[minvector[:-1]]
         pmat[:,0] = this_temp[(minvector[-1]*npixstep)+pixoffset:\
                               (minvector[-1]*npixstep)+pixoffset + \
                               self.npixflux]
         polyarr = poly_array(npoly, self.npixflux)
         pmat[:, 1:] = n.transpose(polyarr)
         ninv = n.diag(ivar)
         f = linalg.solve(n.dot(n.dot(n.transpose(pmat), ninv), pmat),
                          n.dot(n.dot(n.transpose(pmat), ninv), flux))             \
                             f = n.array(f)
         if f[0] < 0:
             try:
                 f = nnls(n.dot(n.dot(n.transpose(pmat), ninv), pmat),
                          n.dot(n.dot(n.transpose(pmat), ninv), flux))[0]                     \
                                             f = n.array(f)
                 return n.dot(pmat, f), tuple(f)
             except Exception as e:
                 print("Exception: %r" % e)
                 return n.zeros(self.npixflux), (0, )
         else:
             return n.dot(pmat, f), tuple(f)
     except Exception as e:
         print("Exception: %r" % e)
         return n.zeros(self.npixflux), (0, )
コード例 #2
0
 def create_model(self, fname, npoly, npixstep, minvector, zfindobj,
                  flux, ivar):
     """Return the best fit model for a given template at a
         given redshift.
     """
     try:
         pixoffset = zfindobj.pixoffset
         temps = read_ndArch( join( environ['REDMONSTER_TEMPLATES_DIR'],
                                   fname ) )[0]
         pmat = n.zeros( (self.npixflux, npoly+1) )
         this_temp = temps[minvector[:-1]]
         pmat[:,0] = this_temp[(minvector[-1]*npixstep)+pixoffset:\
                               (minvector[-1]*npixstep)+pixoffset + \
                               self.npixflux]
         polyarr = poly_array(npoly, self.npixflux)
         pmat[:,1:] = n.transpose(polyarr)
         ninv = n.diag(ivar)
         f = linalg.solve( n.dot(n.dot(n.transpose(pmat),ninv),pmat),
                            n.dot( n.dot(n.transpose(pmat),ninv),flux) ); \
                 f = n.array(f)
         if f[0] < 0:
             try:
                 f = nnls( n.dot(n.dot(n.transpose(pmat),ninv),pmat),
                          n.dot( n.dot(n.transpose(pmat),ninv),flux) )[0]; \
                         f = n.array(f)
                 return n.dot(pmat,f), tuple(f)
             except Exception as e:
                 print("Exception: %r" % e)
                 return n.zeros(self.npixflux), (0,)
         else:
             return n.dot(pmat,f), tuple(f)
     except Exception as e:
         print("Exception: %r" % e)
         return n.zeros(self.npixflux), (0,)
コード例 #3
0
# cap_ztemplate_v00.py
# Script to generate redshift templates at SDSS sampling
# from Carlos Allende-Prieto's theoretical stellar spectra.
# bolton@utah@iac 2014mayo


# Set this:
# export CAP_DATA_DIR=/data/CAP/bad

# Set the filename:
# Need to loop over 1--5 somehow...
fname = os.getenv('CAP_DATA_DIR') + '/ndArch-nsc5-bad00.fits'

# Get the data:
data, baselines, infodict = io.read_ndArch(fname)

# Build the log-lambda baseline and pixel boundaries:
hires_loglam_air = infodict['coeff0'] + infodict['coeff1'] * n.arange(infodict['nwave'])
hires_logbound_air = pxs.cen2bound(hires_loglam_air)
hires_wave_air = 10.**hires_loglam_air
hires_wavebound_air = 10.**hires_logbound_air
hires_dwave_air = hires_wavebound_air[1:] - hires_wavebound_air[:-1]

# Transform the baselines to vacuum wavelengths:
hires_wave = a2v.a2v(hires_wave_air)
hires_wavebound = a2v.a2v(hires_wavebound_air)
hires_dwave = hires_wavebound[1:] - hires_wavebound[:-1]

# Not sure what the interpretation is at wavelengths below 2000ang...
# We will probably cut that out for now anyway, since these are the
コード例 #4
0
### END code specific for the ELG case:


# Get the data:
SpC = sdss.SpCFrameAll(plate, mjd)
SpC.set_fiber(fiberid)

spZbest_file = os.getenv('BOSS_SPECTRO_REDUX') + '/' + os.getenv('RUN2D') + '/' + \
               str(plate).rjust(4,'0') + '/' + os.getenv('RUN1D') + '/spZbest-' + \
               str(plate).rjust(4,'0') + '-' + str(mjd) + '.fits'

spz = fits.getdata(spZbest_file, 1)


# Get the models:
data, baselines, infodict = io.read_ndArch('../../../templates/ndArch-ssp_hires_galaxy-v002.fits')
loglam_ssp = infodict['coeff0'] + infodict['coeff1'] * n.arange(infodict['nwave'])
logbound_ssp = misc.cen2bound(loglam_ssp)
wave_ssp = 10.**loglam_ssp
wavebound_ssp = 10.**logbound_ssp
n_vdisp = data.shape[0]
n_age = data.shape[1]


# Build the various wavelength arrays for the fiber:
logbound_fib = [misc.cen2bound(this_loglam) for this_loglam in SpC.loglam_fib]
wave_fib = [10.**this_loglam for this_loglam in SpC.loglam_fib]
wavebound_fib = [10.**this_logbound for this_logbound in logbound_fib]


# Convert sigma from SDSS-coadd-pixel units to Angstroms:
コード例 #5
0
from redmonster.physics import airtovac as a2v

# cap_ztemplate_v00.py
# Script to generate redshift templates at SDSS sampling
# from Carlos Allende-Prieto's theoretical stellar spectra.
# bolton@utah@iac 2014mayo

# Set this:
# export CAP_DATA_DIR=/data/CAP/bad

# Set the filename:
# Need to loop over 1--5 somehow...
fname = os.getenv('CAP_DATA_DIR') + '/ndArch-nsc5-bad00.fits'

# Get the data:
data, baselines, infodict = io.read_ndArch(fname)

# Build the log-lambda baseline and pixel boundaries:
hires_loglam_air = infodict['coeff0'] + infodict['coeff1'] * n.arange(
    infodict['nwave'])
hires_logbound_air = pxs.cen2bound(hires_loglam_air)
hires_wave_air = 10.**hires_loglam_air
hires_wavebound_air = 10.**hires_logbound_air
hires_dwave_air = hires_wavebound_air[1:] - hires_wavebound_air[:-1]

# Transform the baselines to vacuum wavelengths:
hires_wave = a2v.a2v(hires_wave_air)
hires_wavebound = a2v.a2v(hires_wavebound_air)
hires_dwave = hires_wavebound[1:] - hires_wavebound[:-1]

# Not sure what the interpretation is at wavelengths below 2000ang...
コード例 #6
0
### END code specific for the ELG case:


# Get the data:
SpC = sdss.SpCFrameAll(plate, mjd)
SpC.set_fiber(fiberid)

spZbest_file = os.getenv('BOSS_SPECTRO_REDUX') + '/' + os.getenv('RUN2D') + '/' + \
               str(plate).rjust(4,'0') + '/' + os.getenv('RUN1D') + '/spZbest-' + \
               str(plate).rjust(4,'0') + '-' + str(mjd) + '.fits'

spz = fits.getdata(spZbest_file, 1)


# Get the models:
data, baselines, infodict = io.read_ndArch('../../../templates/ndArch-ssp_hires_galaxy-v002.fits')
loglam_ssp = infodict['coeff0'] + infodict['coeff1'] * n.arange(infodict['nwave'])
logbound_ssp = misc.cen2bound(loglam_ssp)
wave_ssp = 10.**loglam_ssp
wavebound_ssp = 10.**logbound_ssp
n_vdisp = data.shape[0]
n_age = data.shape[1]


# Build the various wavelength arrays for the fiber:
logbound_fib = [misc.cen2bound(this_loglam) for this_loglam in SpC.loglam_fib]
wave_fib = [10.**this_loglam for this_loglam in SpC.loglam_fib]
wavebound_fib = [10.**this_logbound for this_logbound in logbound_fib]


# Convert sigma from SDSS-coadd-pixel units to Angstroms: