def parallel_rm(xxx_todo_changeme ): (plate,mjd,fiberid) = xxx_todo_changeme specs = spec.Spec(plate=plate, mjd=mjd, fiberid=fiberid) zssp = zfinder.ZFinder(fname='ndArch-ssp_em_galaxy-v000.fits', npoly=4, zmin=-0.01, zmax=1.2) zssp.zchi2(specs.flux, specs.loglambda, specs.ivar) # Write chi2 file with zbase prihdu = fits.PrimaryHDU(zssp.zchi2arr) col1 = fits.Column(name='ZBASE', format='E', array=zssp.zbase) cols = fits.ColDefs([col1]) tbhdu = fits.BinTableHDU.from_columns(cols) thdulist = fits.HDUList([prihdu,tbhdu]) thdulist.writeto('/uufs/astro.utah.edu/common/home/u0814744/scratch/screens/chi2arr-%s-%s.fits' % (plate, zssp.type), overwrite=True) # ---- zstar = zfinder.ZFinder(fname='ndArch-spEigenStar-55734.fits', npoly=4, zmin=-.005, zmax=.005) zstar.zchi2(specs.flux, specs.loglambda, specs.ivar) # Write chi2 file with zbase prihdu = fits.PrimaryHDU(zstar.zchi2arr) col1 = fits.Column(name='ZBASE', format='E', array=zstar.zbase) cols = fits.ColDefs([col1]) tbhdu = fits.BinTableHDU.from_columns(cols) thdulist = fits.HDUList([prihdu,tbhdu]) thdulist.writeto('/uufs/astro.utah.edu/common/home/u0814744/scratch/screens/chi2arr-%s-%s.fits' % (plate, zstar.type), overwrite=True) # ---- zfit_ssp = zfitter.ZFitter(zssp.zchi2arr, zssp.zbase) zfit_ssp.z_refine() zfit_star = zfitter.ZFitter(zstar.zchi2arr, zstar.zbase) zfit_star.z_refine() ssp_flags = misc.comb_flags(specs, zssp, zfit_ssp) star_flags = misc.comb_flags(specs, zstar, zfit_star) zpick = zpicker.ZPicker(specs, zssp, zfit_ssp, ssp_flags, zstar, zfit_star, star_flags) # Write flags file prihdu = fits.PrimaryHDU(zpick.zwarning) thdulist = fits.HDUList([prihdu]) thdulist.writeto('/uufs/astro.utah.edu/common/home/u0814744/scratch/screens/flags-%s.fits' % plate, overwrite=True) output = io.WriteRedmonster(zpick, dest='/uufs/astro.utah.edu/common/home/u0814744/scratch/screens', overwrite=True)
def parallel_rm(xxx_todo_changeme ): (plate,mjd,fiberid) = xxx_todo_changeme specs = spec.Spec(plate=plate, mjd=mjd, fiberid=fiberid) zssp = zfinder.ZFinder(fname='ndArch-ssp_em_galaxy-v000.fits', npoly=4, zmin=-0.01, zmax=1.2) zssp.zchi2(specs.flux, specs.loglambda, specs.ivar) # Write chi2 file with zbase prihdu = fits.PrimaryHDU(zssp.zchi2arr) col1 = fits.Column(name='ZBASE', format='E', array=zssp.zbase) cols = fits.ColDefs([col1]) tbhdu = fits.BinTableHDU.from_columns(cols) thdulist = fits.HDUList([prihdu,tbhdu]) thdulist.writeto('/uufs/astro.utah.edu/common/home/u0814744/scratch/screens/chi2arr-%s-%s.fits' % (plate, zssp.type), clobber=True) # ---- zstar = zfinder.ZFinder(fname='ndArch-spEigenStar-55734.fits', npoly=4, zmin=-.005, zmax=.005) zstar.zchi2(specs.flux, specs.loglambda, specs.ivar) # Write chi2 file with zbase prihdu = fits.PrimaryHDU(zstar.zchi2arr) col1 = fits.Column(name='ZBASE', format='E', array=zstar.zbase) cols = fits.ColDefs([col1]) tbhdu = fits.BinTableHDU.from_columns(cols) thdulist = fits.HDUList([prihdu,tbhdu]) thdulist.writeto('/uufs/astro.utah.edu/common/home/u0814744/scratch/screens/chi2arr-%s-%s.fits' % (plate, zstar.type), clobber=True) # ---- zfit_ssp = zfitter.ZFitter(zssp.zchi2arr, zssp.zbase) zfit_ssp.z_refine() zfit_star = zfitter.ZFitter(zstar.zchi2arr, zstar.zbase) zfit_star.z_refine() ssp_flags = misc.comb_flags(specs, zssp, zfit_ssp) star_flags = misc.comb_flags(specs, zstar, zfit_star) zpick = zpicker.ZPicker(specs, zssp, zfit_ssp, ssp_flags, zstar, zfit_star, star_flags) # Write flags file prihdu = fits.PrimaryHDU(zpick.zwarning) thdulist = fits.HDUList([prihdu]) thdulist.writeto('/uufs/astro.utah.edu/common/home/u0814744/scratch/screens/flags-%s.fits' % plate, clobber=True) output = io.WriteRedmonster(zpick, dest='/uufs/astro.utah.edu/common/home/u0814744/scratch/screens', clobber=True)
def reduce_gen(self, filepath=None, data_range=None, chi2file=False): self.chi2file = False if filepath is None: print("Invalid file path.") else: specs = io2.SpecGen(filepath=filepath) zfindobjs = [] zfitobjs = [] if (self.zmin is not None) & (self.zmax is not None): for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], group=self.group[i], npoly=self.npoly[i], zmin=self.zmin[i], zmax=self.zmax[i], nproc=self.nproc) ) zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], chi2file=self.chi2file) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase) ) zfitobjs[i].z_refine2() else: for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], group=self.group[i], npoly=self.npoly[i], npixstep=self.npixstep[i], nproc=self.nproc) ) zfindobjs[i].zchi2( specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], chi2file=self.chi2file ) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase) ) zfitobjs[i].z_refine2() # Flags flags = [] for i in range(len(zfindobjs)): flags.append( misc.comb_flags(specs, zfindobjs[i], zfitobjs[i])) # ZPicker zpick = zpicker2.ZPicker(specs, zfindobjs, zfitobjs, flags) output = None # Write output if self.dest is None: output = io2.WriteRedmonster(zpick, dest=filepath, overwrite=True) if output: output.write_gen()
def reduce_plate_mjd(self, plate, mjd, fiberid=None, chi2file=False): self.chi2file = chi2file # Check types and try to convert to proper types if necessary if fiberid is None: fiberid = [i for i in range(1000)] else: if type(fiberid) is not list: try: fiberid = [fiberid] fiberid = list(map(int, fiberid)) except: try: fiberid = fiberid.tolist() fiberid = list(map(int, fiberid)) except: print('fiberid not set properly - running full plate!') fiberid = [i for i in range(1000)] else: fiberid = list(map(int, fiberid)) # Spec specs = spec.Spec(plate=plate, mjd=mjd, fiberid=fiberid) # ZFinder, ZFitter zfindobjs = [] zfitobjs = [] if (self.zmin is not None) & (self.zmax is not None): for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], npoly=self.npoly[i], zmin=self.zmin[i], zmax=self.zmax[i])) zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine() else: for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], npoly=self.npoly[i], npixstep=self.npixstep[i])) zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine() # Flags flags = [] for i in range(len(zfindobjs)): flags.append(misc.comb_flags(specs, zfindobjs[i], zfitobjs[i])) # ZPicker if len(self.templates) == 1: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0]) elif len(self.templates) == 2: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1]) elif len(self.templates) == 3: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1], zfindobjs[2], zfitobjs[2], flags[2]) elif len(self.templates) == 4: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1], zfindobjs[2], zfitobjs[2], flags[2], zfindobjs[3], zfitobjs[3], flags[3]) elif len(self.templates) == 5: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1], zfindobjs[2], zfitobjs[2], flags[2], zfindobjs[3], zfitobjs[3], flags[3], zfindobjs[4], zfitobjs[4], flags[4]) output = None # Write output if self.dest is None: output = io.WriteRedmonster(zpick, overwrite=self.overwrite) else: if type(self.dest) is str: output = io.WriteRedmonster(zpick, dest=self.dest, overwrite=self.overwrite) else: try: self.dest = str(self.dest) output = io.WriteRedmonster(zpick, dest=self.dest, overwrite=self.overwrite) except: print( 'Could not convert dest to string - writing to default directory and NOT clobbering old files!' ) output = io.WriteRedmonster(zpick, overwrite=True) if output: if len(zpick.fiberid) == 1: output.write_fiberid() else: output.write_plate()
def reduce_plate_mjd(self, plate, mjd, fiberid=None, chi2file=False): self.chi2file = chi2file # Check types and try to convert to proper types if necessary if fiberid is None: fiberid = [i for i in range(1000)] else: if type(fiberid) is not list: try: fiberid = [fiberid] fiberid = list(map(int, fiberid)) except: try: fiberid = fiberid.tolist() fiberid = list(map(int, fiberid)) except: print('fiberid not set properly - running full plate!') fiberid = [i for i in range(1000)] else: fiberid = list(map(int, fiberid)) # Spec specs = spec.Spec(plate=plate, mjd=mjd, fiberid=fiberid) # ZFinder, ZFitter zfindobjs = [] zfitobjs = [] if (self.zmin is not None) & (self.zmax is not None): for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], npoly=self.npoly[i], zmin=self.zmin[i], zmax=self.zmax[i]) ) zfindobjs[i].zchi2( specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file ) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase) ) zfitobjs[i].z_refine() else: for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], npoly=self.npoly[i], npixstep=self.npixstep[i]) ) zfindobjs[i].zchi2( specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file ) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase) ) zfitobjs[i].z_refine() # Flags flags = [] for i in range(len(zfindobjs)): flags.append( misc.comb_flags(specs, zfindobjs[i], zfitobjs[i]) ) # ZPicker if len(self.templates) == 1: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0]) elif len(self.templates) == 2: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1]) elif len(self.templates) == 3: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1], zfindobjs[2], zfitobjs[2], flags[2]) elif len(self.templates) == 4: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1], zfindobjs[2], zfitobjs[2], flags[2], zfindobjs[3], zfitobjs[3], flags[3]) elif len(self.templates) == 5: zpick = zpicker.ZPicker(specs, zfindobjs[0], zfitobjs[0], flags[0], zfindobjs[1], zfitobjs[1], flags[1], zfindobjs[2], zfitobjs[2], flags[2], zfindobjs[3], zfitobjs[3], flags[3], zfindobjs[4], zfitobjs[4], flags[4]) output = None # Write output if self.dest is None: output = io.WriteRedmonster(zpick, clobber=self.clobber) else: if type(self.dest) is str: output = io.WriteRedmonster(zpick, dest=self.dest, clobber=self.clobber) else: try: self.dest = str(self.dest) output = io.WriteRedmonster(zpick, dest=self.dest, clobber=self.clobber) except: print('Could not convert dest to string - writing to default directory and NOT clobbering old files!') output = io.WriteRedmonster(zpick, clobber=True) if output: if len(zpick.fiberid) == 1: output.write_fiberid() else: output.write_plate()
''' Same as above for second template.''' #zfit_ssp2 = zfitter.ZFitter(zssp2.zchi2arr, zssp2.zbase) #zfit_ssp2.z_refine2() zfit_star = zfitter.ZFitter(zstar.zchi2arr, zstar.zbase) zfit_star.z_refine2() zfit_qso = zfitter.ZFitter(zqso.zchi2arr, zqso.zbase) zfit_qso.z_refine2() ''' Flagging throughout redmonster is done individually by the classes responsible for handling the relevant computations. To have an 'overall' flag for each fiber, the individual flags need to be combined. ''' ssp1_flags = misc.comb_flags(specs, zssp1, zfit_ssp1) #ssp2_flags = misc.comb_flags(specs, zssp2, zfit_ssp2) star_flags = misc.comb_flags(specs, zstar, zfit_star) qso_flags = misc.comb_flags(specs, zqso, zfit_qso) ''' Compare chi2 surfaces from each template and classify each object accordingly. Arguments are data object (in a format identical to that created by Spec), followed by each object created by ZFinder, ZFitter, and flags, in that order. This function can currently handle up to five objects from five separate templates. If specs is a user created data object rather than one created by redmonster.datamgr.spec, it must contain specs.npix, the number of pixels in a single spectrum. ''' #zpick = zpicker.ZPicker(specs, zssp, zfit_ssp, ssp_flags, zstar, zfit_star,
def reduce_gen(self, filepath=None, data_range=None, chi2file=False): self.chi2file = False if filepath is None: print("Invalid file path.") else: specs = io2.SpecGen(filepath=filepath) zfindobjs = [] zfitobjs = [] if (self.zmin is not None) & (self.zmax is not None): for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], group=self.group[i], npoly=self.npoly[i], zmin=self.zmin[i], zmax=self.zmax[i], nproc=self.nproc)) zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], chi2file=self.chi2file) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine2() else: for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], group=self.group[i], npoly=self.npoly[i], npixstep=self.npixstep[i], nproc=self.nproc)) zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], chi2file=self.chi2file) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine2() # Flags flags = [] for i in range(len(zfindobjs)): flags.append(misc.comb_flags(specs, zfindobjs[i], zfitobjs[i])) # ZPicker zpick = zpicker2.ZPicker(specs, zfindobjs, zfitobjs, flags) output = None # Write output if self.dest is None: output = io2.WriteRedmonster(zpick, dest=filepath, overwrite=True) if output: output.write_gen()
def reduce_plate_mjd(self, plate=None, mjd=None, fiberid=None, data_range=None, chi2file=False, platepath=None): print "\nPlate %s MJD %s Fiber %s" % (plate, mjd, fiberid) self.chi2file = chi2file # Check types and try to convert to proper types if necessary if fiberid is not None: if type(fiberid) is not list: try: fiberid = [fiberid] fiberid = list(map(int, fiberid)) except ValueError: try: fiberid = fiberid.tolist() fiberid = list(map(int, fiberid)) except ValueError: print('fiberid not set properly - running full plate!') else: fiberid = list(map(int, fiberid)) # Spec specs = spec.Spec(plate=plate, mjd=mjd, fiberid=fiberid, platepath=platepath) fiberid = specs.fiberid # ZFinder, ZFitter zfindobjs = [] zfitobjs = [] if (self.zmin is not None) & (self.zmax is not None): for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], group=self.group[i], npoly=self.npoly[i], zmin=self.zmin[i], zmax=self.zmax[i], nproc=self.nproc)) if self.mask: zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file, linelist=__linelist__) else: zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine2() else: for i in range(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], group=self.group[i], npoly=self.npoly[i], npixstep=self.npixstep[i], nproc=self.nproc)) if mask: zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file, linelist=__linelist__) else: zfindobjs[i].zchi2(specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file) zfitobjs.append( zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine2() # Flags flags = [] for i in range(len(zfindobjs)): flags.append(misc.comb_flags(specs, zfindobjs[i], zfitobjs[i])) # ZPicker zpick = zpicker2.ZPicker(specs, zfindobjs, zfitobjs, flags) output = None # Write output if self.dest is None: output = io2.WriteRedmonster(zpick, overwrite=True) else: if type(self.dest) is str: output = io2.WriteRedmonster(zpick, dest=self.dest, overwrite=True) else: try: self.dest = str(self.dest) output = io2.WriteRedmonster(zpick, dest=self.dest, overwrite=True) except Exception as e: print( 'Could not convert dest to string - writing to \ default directory and NOT clobbering old files! \ Exception: %r' % e) output = io2.WriteRedmonster(zpick, overwrite=True) if output: if len(zpick.fiberid) == 1: output.write_fiber() else: output.write_plate()
def reduce_plate_mjd(self, plate=None, mjd=None, fiberid=None, data_range=None, chi2file=False, platepath=None): self.chi2file = chi2file # Check types and try to convert to proper types if necessary if fiberid is not None: if type(fiberid) is not list: try: fiberid = [fiberid] fiberid = map(int, fiberid) except ValueError: try: fiberid = fiberid.tolist() fiberid = map(int, fiberid) except ValueError: print "fiberid not set properly - running full plate!" else: fiberid = map(int, fiberid) # Spec specs = spec.Spec(plate=plate, mjd=mjd, fiberid=fiberid, platepath=platepath) fiberid = specs.fiberid # ZFinder, ZFitter zfindobjs = [] zfitobjs = [] if (self.zmin is not None) & (self.zmax is not None): for i in xrange(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], npoly=self.npoly[i], zmin=self.zmin[i], zmax=self.zmax[i]) ) zfindobjs[i].zchi2( specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file, ) zfitobjs.append(zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine2() else: for i in xrange(len(self.templates)): zfindobjs.append( zfinder.ZFinder(fname=self.templates[i], npoly=self.npoly[i], npixstep=self.npixstep[i]) ) zfindobjs[i].zchi2( specs.flux, specs.loglambda, specs.ivar, npixstep=self.npixstep[i], plate=plate, mjd=mjd, fiberid=fiberid[0], chi2file=self.chi2file, ) zfitobjs.append(zfitter.ZFitter(zfindobjs[i].zchi2arr, zfindobjs[i].zbase)) zfitobjs[i].z_refine2() # Flags flags = [] for i in xrange(len(zfindobjs)): flags.append(misc.comb_flags(specs, zfindobjs[i], zfitobjs[i])) # ZPicker zpick = zpicker2.ZPicker(specs, zfindobjs, zfitobjs, flags) output = None # Write output if self.dest is None: output = io2.WriteRedmonster(zpick, clobber=True) else: if type(self.dest) is str: output = io2.WriteRedmonster(zpick, dest=self.dest, clobber=True) else: try: self.dest = str(self.dest) output = io2.WriteRedmonster(zpick, dest=self.dest, clobber=True) except Exception as e: print "Could not convert dest to string - writing to \ default directory and NOT clobbering old files! \ Exception: %r" % e output = io2.WriteRedmonster(zpick, clobber=True) if output: if len(zpick.fiberid) == 1: output.write_fiber() else: output.write_plate()