コード例 #1
0
    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()
コード例 #2
0
ファイル: run_redmonster.py プロジェクト: ntejos/redmonster
#flags.append(ssp2_flags)
flags.append(star_flags)
flags.append(qso_flags)

zpick = zpicker2.ZPicker(specs, zfindobjs, zfitobjs, flags)

#zpick.plate = 0000
#zpick.mjd = 00000
#zpick.fiberid = [0]

''' Write output file.  Arguments are zpick object from above, and
    optionally dest and clobber, the path in which to write to file
    and whether or not to clobber old files with the same name,
    respectively.  See class documentation for more detail on
    WriteRedmonster behavior.'''

output = io2.WriteRedmonster(zpick)
output.write_fiber()

# Things left to do
#
# DONE 1. Incorporate flags into, probably, zpicker and
#         subseqently WriteRedmonster
# 2. Incorporate Adam's spCFrame fittings somewhere
# 3. Function to turn variable resolution data into coadded log(lambda) data?
# DONE 4. Quasar templates?
# DONE 5. BOSS CMASS data testing
# DONE      Look into delta chi2 thresholds to trigger failure
# DONE      Look at completeness vs. purity
# 6. WISE selected LRG targets (SEQUELS/SDSS-IV)
コード例 #3
0
    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()