Beispiel #1
0
    def initialize(self,args):
        # load config files
        self.loadcfgfiles(args.cfgfile,
                            filt=args.filt,
                            extracfgfiles=args.extracfgfile,
                            params=args.params,
                            params4all=args.pall,
                            params4sections=args.pp,
                            verbose=args.verbose)

        snlistfilename = self.cfg.params['snlistfilename']
        if not(args.snlistfilename is None):
            snlistfilename = self.outrootdir+args.snlistfilename

        if not(os.path.isfile(snlistfilename)):
            raise RuntimeError("SN list file %s does not exist, exiting!!" % snlistfilename)
        
        self.setoutdir(args,outrootdir=args.outrootdir,outsubdir=args.outsubdir)
        self.verbose = args.verbose
        self.debug = args.debug
        self.flux_colname = self.cfg.params['flux_colname']
        self.dflux_colname = self.cfg.params['dflux_colname']
        self.api = self.cfg.params['api']
        if args.api is True:
            self.api = True

        self.RADECtable = pdastroclass(columns=['ControlID','PatternID','Ra','Dec','RaOffset','DecOffset','Radius','Ndet','Ndet_c','Ndet_o'])
        self.RADECtable.default_formatters = {'ControlID':'{:3d}'.format,
                                              'PatternID':'{:2d}'.format,
                                              'Ra':'{:.8f}'.format,
                                              'Dec':'{:.8f}'.format,
                                              'RaOffset':'{:.2f}'.format,
                                              'DecOffset':'{:.2f}'.format,
                                              'Radius':'{:.2f}'.format,
                                              'Ndet':'{:4d}'.format,
                                              'Ndet_c':'{:4d}'.format,
                                              'Ndet_o':'{:4d}'.format}


        self.averagelc = pdastroclass(columns=['ControlID','MJD','MJDbin',self.flux_colname,self.dflux_colname,'stdev','X2norm','Nclip','Ngood','Nexcluded','Mask'],hexcols='Mask')
        self.averagelc.default_formatters = {'ControlID':'{:3d}'.format,
                                            'MJD':'{:.6f}'.format,
                                            'MJDbin':'{:.2f}'.format,
                                            self.flux_colname:'{:.3f}'.format,
                                            self.dflux_colname:'{:.3f}'.format,
                                            'stdev':'{:.2f}'.format,
                                            'X2norm':'{:.3f}'.format,
                                            'Nclip':'{:4d}'.format,
                                            'Ngood':'{:4d}'.format,
                                            'Nexcluded':'{:4d}'.format,
                                            'Mask':'0x{:06x}'.format}

        self.load_spacesep(snlistfilename)
        if self.verbose>1:
            print(self.t)
        #print(args.SNlist)

        SNindexlist = self.getSNlist(args.SNlist)
        return(SNindexlist)
Beispiel #2
0
 def addnanrows(self,indices=None):
     # make new lc
     lc2 = pdastroclass(hexcols='Mask')
     lc2.t = pd.DataFrame(columns=self.lc.t.columns)
     print(lc2.t)
     # get indices
     if indices is None:
         indices = self.lc.getindices()
     print('Indices: ',indices)
     # get MJD and mjd range
     MJD = int(np.amin(self.lc.t['MJD']))
     print('MJD range: ',MJD,' to ',MJD+1)
     
     MJDbin = self.lc.t.loc[0,'MJDbin'] # get first MJD bin
     index = min(indices)
     while index < max(indices):
         if (self.lc.t.loc[index,'MJDbin']==MJDbin): # check to see if MJD bin matches
             # add row with MJDbin and other columns
             lc2.t = lc2.t.append(self.lc.t.loc[index],ignore_index=True)
             index += 1
         else:
             # add row with MJDbin and nans
             row = pd.DataFrame([[self.lc.t.loc[index,'ControlID'],np.nan,MJDbin,np.nan,np.nan,np.nan,np.nan,0,0,0,0x800000]],columns=self.lc.t.columns)
             lc2.t = lc2.t.append(row,ignore_index=True)
         MJDbin += 1 
     lc2.t['Mask'] = lc2.t['Mask'].astype(np.int32)
     return(lc2.t)
Beispiel #3
0
    def __init__(self):
        SNloopclass.__init__(self)

        self.cfg = yamlcfgclass()
        self.debug = False
        self.outrootdir = None
        self.snlist = pdastroclass(columns=[
            'atlasdesignation', 'otherdesignation', 'ra', 'dec',
            'spectraltype', 'earliestmjd', 'tnsname', 'closebrightRA',
            'closebrightDec', 'MJDpreSN'
        ])
        self.snlistsurvey = pdastroclass(columns=[
            'atlasdesignation', 'otherdesignation', 'ra', 'dec',
            'spectraltype', 'earliestmjd', 'tnsname', 'closebrightRA',
            'closebrightDec', 'MJDpreSN'
        ])
Beispiel #4
0
    def __init__(self):
        pdastroclass.__init__(self)

        self.lctype = None # can be 'avg' or 'single'

        # config file
        self.cfg = yamlcfgclass()

        # miscellaneous vars
        self.verbose = 0
        self.debug = False
        self.outrootdir = None
        self.filt = None
        self.api = False
        
        # tables
        self.lc = pdastrostatsclass(hexcols=['Mask'])
        self.RADECtable = pdastroclass()
        self.averagelc = pdastrostatsclass(hexcols=['Mask'])

        # FLAGS
        self.flag_c0_X2norm      = 0x1 
        self.flag_c0_uncertainty = 0x2
        self.flag_c0_X2norm_dynamic = 0x4
        
        self.flag_c1_X2norm      = 0x10
        self.flag_c1_absnormmean = 0x20
        
        self.flag_c2_X2norm      = 0x100
        self.flag_c2_absnormmean = 0x200
        self.flag_c2_Nclip       = 0x400
        self.flag_c2_Nused       = 0x800

        self.flag_daysigma       = 0x1000
        self.flag_daysmallnumber = 0x2000

        self.flag_c2_ok          = 0x80000

        self.flag_c0_bad         = 0x100000
        self.flag_c2_bad         = 0x400000
        self.flag_day_bad        = 0x800000

        self.flags={'flag_c0_uncertainty':self.flag_c0_uncertainty,
                    'flag_c0_X2norm':self.flag_c0_X2norm,
                    'flag_c1_X2norm':self.flag_c1_X2norm,
                    'flag_c1_absnormmean':self.flag_c1_absnormmean,
                    'flag_c2_X2norm':self.flag_c2_X2norm,
                    'flag_c2_absnormmean':self.flag_c2_absnormmean,
                    'flag_c2_Nclip':self.flag_c2_Nclip,
                    'flag_c2_Nused':self.flag_c2_Nused,
                    'flag_c2_ok':self.flag_c2_ok,
                    'flag_daysigma':self.flag_daysigma,
                    'flag_daysmallnumber':self.flag_daysmallnumber,
                    'flag_c0_bad':self.flag_c0_bad,
                    'flag_c2_bad':self.flag_c2_bad,
                    'flag_day_bad':self.flag_day_bad}
        
        self.flags_c1c2 = self.flag_c1_X2norm|self.flag_c1_absnormmean|self.flag_c2_X2norm|self.flag_c2_absnormmean|self.flag_c2_Nclip|self.flag_c2_Nused|self.flag_c2_bad|self.flag_c2_ok#|self.flag_c1_good|self.flag_c2_good
    def __init__(self):
        pdastroclass.__init__(self)

        self.qcinv = pdastroclass()
        self.minimal_overhead = 28  # in seconds

        self.verbose = 0
        self.debug = 0

        self.warnings = []

        self.t = pd.DataFrame(columns=[
            'blockID', 'assigned_program', 'program', 'UTfirst', 'UTlast',
            'dt_block_h', 'dt_prevgap_sec', 'dt_nextgap_sec', 'dt_gaps_sec',
            'dt_block_full_h', 'twi', 'dt_charged_h'
        ])
        self.summary = pdastroclass()
        self.summary.t = pd.DataFrame(columns=['assigned_program', 't_total'])

        self.programcol_formatter = '{:<24}'.format

        self.horizons = [18, 15, 12]
        self.twi_charge_fraction = (1.0, 2 / 3, 1 / 3, 0.0)
Beispiel #6
0
    def c0_PSF_X2norm_cut(self, X2norm_max):
        if self.cfg.params['cleanlc']['cut0']['dynamic_X2_cut'] is False:
            print('Using static chi-square cut instead of dynamic...')
            if X2norm_max is None:
                if self.verbose > 1: print('No cut on the X2norm...')
                return (0)

            print('Flagging all measurements with chi/N bigger than %f...' %
                  X2norm_max)
            a_indices = self.lc.ix_inrange('chi/N', X2norm_max, None)
            if len(a_indices) > 0:
                print('# chi/N above %f: %i/%i' %
                      (X2norm_max, len(a_indices), len(self.lc.getindices())))
            else:
                print('# No measurements flagged!')
                return (0)

            # update mask column
            flag_c0_X2norm = np.full(self.lc.t.loc[a_indices, 'Mask'].shape,
                                     self.flag_c0_X2norm | self.flag_c0_bad)

            self.lc.t.loc[a_indices, 'Mask'] = np.bitwise_or(
                self.lc.t.loc[a_indices, 'Mask'], flag_c0_X2norm)
            return (0)
        else:
            print('Using dynamic chi-square cut instead of static...')
            table_type = self.cfg.params['cleanlc']['cut0']['table_type']
            table_type_options = ['flux_dflux', 'flux_median']
            if table_type in table_type_options:
                print('Valid table type chosen: ' + table_type)
            else:
                raise RuntimeError(
                    'Table type entered is not a valid option. Please select a table type of the following options: ',
                    table_type_options)

            # get table
            filename = self.outrootdir + '/' + table_type + '_table.txt'
            reftable = pdastroclass()
            reftable.load_spacesep(filename, delim_whitespace=True)

            # make spline
            f = interp1d(reftable.t['center_bin'],
                         reftable.t['upper_limit'],
                         kind='cubic')  # specify edges
            # use spline function to get chi-square upper limit for a given input flux/dflux or flux median array
            if table_type == 'flux_dflux':
                self.lc.t['upper_limit'] = np.nan
                notnans = self.lc.ix_remove_null(colnames=['uJy', 'duJy'])
                self.lc.t.loc[notnans, 'upper_limit'] = f(
                    self.lc.t.loc[notnans, 'uJy'] /
                    self.lc.t.loc[notnans, 'duJy'])  # fluxdflux or fluxmedian
            else:
                # calculate flux median
                MJD = int(np.amin(self.lc.t['MJD']))
                MJDmax = int(np.amax(self.lc.t['MJD'])) + 1
                MJDbinsize = 1
                self.lc.t['uJy_median'] = np.nan
                while MJD <= MJDmax:
                    # get MJD range for the bin size of 1 day
                    ix_mjds = self.lc.ix_inrange(colnames=['MJD'],
                                                 lowlim=MJD,
                                                 uplim=MJD + MJDbinsize,
                                                 exclude_uplim=True)
                    if len(ix_mjds) < 1:
                        MJD += MJDbinsize
                        continue
                    # calculate median uJy for that day
                    uJy_median = np.median(self.lc.t.loc[ix_mjds, 'uJy'])
                    # add uJy_median to new column
                    self.lc.t.loc[ix_mjds, 'uJy_median'] = uJy_median
                    MJD += MJDbinsize
                # spline
                self.lc.t['upper_limit'] = f(self.lc.t['uJy_median'])

            # cut light curve according to chi-square upper limit
            ix = np.where(self.lc.t['chi/N'].ge(self.lc.t['upper_limit']))[0]

            # update mask column
            flag_c0_X2norm_dynamic = np.full(
                self.lc.t.loc[ix, 'Mask'].shape,
                self.flag_c0_X2norm_dynamic | self.flag_c0_bad)
            self.lc.t.loc[ix,
                          'Mask'] = np.bitwise_or(self.lc.t.loc[ix, 'Mask'],
                                                  flag_c0_X2norm_dynamic)

            sys.exit(0)