def build_observation_list(observations, start_wlen, end_wlen, delta_wlen): ''' This function takes a list of observations and redshifts them and resamples them to be on the same grid. ''' wlen_range = np.arange(start_wlen, end_wlen, delta_wlen) qsos = list() for info, qso in observations.items(): rest_frame = redshift(z_in=qso.z, z_out=0, data_in=qso.data, rules=[dict(name='wavelength', exponent=1), dict(name='flux', exponent=-1), dict(name='dflux', exponent=-1)]) resampled = resample(rest_frame, x_in='wavelength', x_out=wlen_range, y=('flux', 'dflux')) qsos.append(resampled) return qsos
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Build the chi2 grid.') parser.add_argument('-v', '--verbose', action='store_true', help='toggle on verbose output') parser.add_argument('--zmin', type=float, default=0.5, metavar='', help='minimum redshift') parser.add_argument('--zmax', type=float, default=1.0, metavar='', help='maximum redshift') parser.add_argument('--zbin', type=float, default=0.25, metavar='', help='redshift bin size') args = parser.parse_args() # Set the debugging level if args.verbose: lvl = logging.DEBUG else: lvl = logging.INFO logging.basicConfig(format='%(message)s', level=lvl, stream=sys.stdout) log = logging.getLogger('__name__') topdir = os.getenv('SEQUELS_DIR') outdir = os.path.join(topdir, 'stacks') # Build the redshift bin (centers). Only works if ZBIN is an integer # multiple of [ZMIN,ZMAX]. zbins = np.concatenate( ([zmin], np.arange(zmin, zmax, zbin) + zbin / 2, [zmax])) # Loop on all the plates plates = ['7280'] for pl in plates: platefile = glob( os.path.join(topdir, pl, 'spPlate-' + pl + '-?????.fits'))[0] zbestfile = glob( os.path.join(topdir, pl, 'spZbest-' + pl + '-?????.fits'))[0] zall = fits.getdata(zbestfile, 1) plug = fits.getdata(platefile, 5) fluxall, hdr = fits.getdata(platefile, 0, header=True) wave = 10**(hdr['CRVAL1'] + np.arange(hdr['NAXIS1']) * hdr['CD1_1']) ivarall = fits.getdata(platefile, 1) # Pick out the "good" LRGs iz_wise = (plug['EBOSS_TARGET0'] & 2) > 0 ri_wise = (plug['EBOSS_TARGET0'] & 4) > 0 zcut = (zall['Z'] > args.zmin) * (zall['Z'] < args.zmax) * ( zall['RCHI2DIFF_NOQSO'] > 0.005) lrg = np.where(np.logical_and(np.logical_or(iz_wise, ri_wise), zcut))[0] if len(lrg) > 0: flux = fluxall[lrg, :] ivar = ivarall[lrg, :] zlrg = zall[lrg] # Assign each object to the right redshift bin. idx = np.digitize(x, bins) #print(nbin, bins, xmin, xmax) for ib in range(len([0, 1])): zflux = flux[lrg[ib], :] zivar = ivar[lrg[ib], :] rules = [ dict(name='wave', exponent=+1, array_in=wave), dict(name='flux', exponent=-1, array_in=zflux), dict(name='ivar', exponent=+2, array_in=zivar) ] out = redshift(zbest['z'][lrg[ib]], 0.2, rules=rules) print(out.shape)
def main(): parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Build the chi2 grid.') parser.add_argument('-v', '--verbose', action='store_true', help='toggle on verbose output') parser.add_argument('--zmin', type=float, default=0.5, metavar='', help='minimum redshift') parser.add_argument('--zmax', type=float, default=1.0, metavar='', help='maximum redshift') parser.add_argument('--zbin', type=float, default=0.25, metavar='', help='redshift bin size') args = parser.parse_args() # Set the debugging level if args.verbose: lvl = logging.DEBUG else: lvl = logging.INFO logging.basicConfig(format='%(message)s',level=lvl,stream=sys.stdout) log = logging.getLogger('__name__') topdir = os.getenv('SEQUELS_DIR') outdir = os.path.join(topdir,'stacks') # Build the redshift bin (centers). Only works if ZBIN is an integer # multiple of [ZMIN,ZMAX]. zbins = np.concatenate(([zmin],np.arange(zmin,zmax,zbin)+zbin/2,[zmax])) # Loop on all the plates plates = ['7280'] for pl in plates: platefile = glob(os.path.join(topdir,pl,'spPlate-'+pl+'-?????.fits'))[0] zbestfile = glob(os.path.join(topdir,pl,'spZbest-'+pl+'-?????.fits'))[0] zall = fits.getdata(zbestfile,1) plug = fits.getdata(platefile,5) fluxall, hdr = fits.getdata(platefile,0,header=True) wave = 10**(hdr['CRVAL1'] + np.arange(hdr['NAXIS1'])*hdr['CD1_1']) ivarall = fits.getdata(platefile,1) # Pick out the "good" LRGs iz_wise = (plug['EBOSS_TARGET0'] & 2)>0 ri_wise = (plug['EBOSS_TARGET0'] & 4)>0 zcut = (zall['Z']>args.zmin)*(zall['Z']<args.zmax)*(zall['RCHI2DIFF_NOQSO']>0.005) lrg = np.where(np.logical_and(np.logical_or(iz_wise,ri_wise),zcut))[0] if len(lrg)>0: flux = fluxall[lrg,:] ivar = ivarall[lrg,:] zlrg = zall[lrg] # Assign each object to the right redshift bin. idx = np.digitize(x,bins) #print(nbin, bins, xmin, xmax) for ib in range(len([0,1])): zflux = flux[lrg[ib],:] zivar = ivar[lrg[ib],:] rules = [dict(name='wave', exponent=+1, array_in=wave), dict(name='flux', exponent=-1, array_in=zflux), dict(name='ivar', exponent=+2, array_in=zivar)] out = redshift(zbest['z'][lrg[ib]],0.2,rules=rules) print(out.shape)
# STACKING QUSARS DR12Q = bossdata.meta.Database(finder, mirror, quasar_catalog=True, lite=False) qso_table = DR12Q.select_all(where="PLATE=6641 and ZWARNING=0", what="PLATE,MJD,FIBER,Z_VI") print "Found {0} QSO targets for plate 6641.".format(len(qso_table)) fiducial_grid = np.arange(1000.0, 3000.0) rest_frame, resampled, spec_qso = None, None, None for row in qso_table: filename = finder.get_spec_path(plate=row["PLATE"], mjd=row["MJD"], fiber=row["FIBER"], lite=True) spectrum = bossdata.spec.SpecFile(mirror.get(filename)) data = spectrum.get_valid_data(use_ivar=True, fiducial_grid=True) rest_frame = speclite.redshift( z_in=row["Z_VI"], z_out=0, data_in=data, data_out=rest_frame, rules=[dict(name="wavelength", exponent=+1), dict(name="flux", exponent=-1), dict(name="ivar", exponent=+2)], ) resampled = speclite.resample( rest_frame, x_in="wavelength", x_out=fiducial_grid, y=("flux", "ivar"), data_out=resampled ) spec_qso = speclite.accumulate(spec_qso, resampled, data_out=spec_qso, join="wavelength", add="flux", weight="ivar") plot_stack(spec_qso, truncate_percentile=99.5) filename = finder.get_plate_spec_path(plate=6641, mjd=56383) plate = bossdata.plate.PlateFile(mirror.get(filename)) plate_data = plate.get_valid_data(qso_table["FIBER"], use_ivar=True, fiducial_grid=True) zorder = np.argsort(qso_table["Z_VI"])