Ejemplo n.º 1
0
def create_cif_table():
    """
    Create Calibration Database Index File binary table
    """
    # Create binary table
    table = gammalib.GFitsBinTable()

    # Append columns. Reference: CAL/GEN/92-008
    table.append(gammalib.GFitsTableStringCol("TELESCOP", 0, 10))
    table.append(gammalib.GFitsTableStringCol("INSTRUME", 0, 10))
    table.append(gammalib.GFitsTableStringCol("DETNAM", 0, 20))
    table.append(gammalib.GFitsTableStringCol("FILTER", 0, 10))
    table.append(gammalib.GFitsTableStringCol("CAL_DEV", 0, 20))
    table.append(gammalib.GFitsTableStringCol("CAL_DIR", 0, 70))
    table.append(gammalib.GFitsTableStringCol("CAL_FILE", 0, 40))
    table.append(gammalib.GFitsTableStringCol("CAL_CLAS", 0, 3))
    table.append(gammalib.GFitsTableStringCol("CAL_DTYP", 0, 4))
    table.append(gammalib.GFitsTableStringCol("CAL_CNAM", 0, 20))
    table.append(gammalib.GFitsTableStringCol("CAL_CBD", 0, 70, 9))
    table.append(gammalib.GFitsTableShortCol("CAL_XNO", 0))
    table.append(gammalib.GFitsTableStringCol("CAL_VSD", 0, 10))
    table.append(gammalib.GFitsTableStringCol("CAL_VST", 0, 8))
    table.append(gammalib.GFitsTableDoubleCol("REF_TIME", 0))
    table.append(gammalib.GFitsTableShortCol("CAL_QUAL", 0))
    table.append(gammalib.GFitsTableStringCol("CAL_DATE", 0, 8))
    table.append(gammalib.GFitsTableStringCol("CAL_DESC", 0, 70))

    # Set keywords. Reference: CAL/GEN/92-008
    table.extname("CIF")
    table.card("CIFVERSN", "1992a", "Version of CIF format")

    # Return table
    return table
Ejemplo n.º 2
0
    def create_cif(self):
        """
        Create Calibration Index File (CIF) extension in CIF FITS file.

        Parameters:
         None
        Keywords:
         None
        """
        # Create binary table
        table = gammalib.GFitsBinTable()

        # Set boundary

        # Attach columns. Reference: CAL/GEN/92-008
        table.append(gammalib.GFitsTableStringCol("TELESCOP", 0, 10))
        table.append(gammalib.GFitsTableStringCol("INSTRUME", 0, 10))
        table.append(gammalib.GFitsTableStringCol("DETNAM", 0, 20))
        table.append(gammalib.GFitsTableStringCol("FILTER", 0, 10))
        table.append(gammalib.GFitsTableStringCol("CAL_DEV", 0, 20))
        table.append(gammalib.GFitsTableStringCol("CAL_DIR", 0, 70))
        table.append(gammalib.GFitsTableStringCol("CAL_FILE", 0, 40))
        table.append(gammalib.GFitsTableStringCol("CAL_CLAS", 0, 3))
        table.append(gammalib.GFitsTableStringCol("CAL_DTYP", 0, 4))
        table.append(gammalib.GFitsTableStringCol("CAL_CNAM", 0, 20))
        table.append(gammalib.GFitsTableStringCol("CAL_CBD", 0, 70, 9))
        table.append(gammalib.GFitsTableShortCol("CAL_XNO", 0))
        table.append(gammalib.GFitsTableStringCol("CAL_VSD", 0, 10))
        table.append(gammalib.GFitsTableStringCol("CAL_VST", 0, 8))
        table.append(gammalib.GFitsTableDoubleCol("REF_TIME", 0))
        table.append(gammalib.GFitsTableShortCol("CAL_QUAL", 0))
        table.append(gammalib.GFitsTableStringCol("CAL_DATE", 0, 8))
        table.append(gammalib.GFitsTableStringCol("CAL_DESC", 0, 70))

        # Set keywords. Reference: CAL/GEN/92-008
        table.extname("CIF")
        table.card("CIFVERSN", "1992a", "Version of CIF format")

        # Attach table to FITS file. Note that at this moment the
        # FITS table gets connected to the FITS file. Yet since
        # nothing was yet written to the FITS file, we cannot read
        # anything from it.
        self.cif.append(table)

        # Return
        return
Ejemplo n.º 3
0
    def _make_caldb_index(self):
        """
        Creates an IRF index FITS file.
        """
        # Write header into logger
        if self._logTerse():
            self._log("\n")
            self._log.header2("Creating database index file")

        # Open calibration database index
        indx_file = self._base_dir+"/caldb.indx"
        
        # Open index file (or create one if it does not exist)
        cif = gammalib.GFits(indx_file, True)
        
        # Retrieve "CIF" table
        if cif.contains("CIF"):
            table = cif.table("CIF")

        # ... or create binary table if no "CIF" table exists yet
        else:       

            # Create empty binary table
            bintable = gammalib.GFitsBinTable()
            bintable.extname("CIF")
            bintable.card("CIFVERSN", "1992a", "Version of CIF format")     

            # Append table to FITS file and recover a reference to the
            # appended table
            table = cif.append(bintable)
            
            # Attach columns. Reference: CAL/GEN/92-008
            table.append(gammalib.GFitsTableStringCol("TELESCOP", 0, 10))
            table.append(gammalib.GFitsTableStringCol("INSTRUME", 0, 10))
            table.append(gammalib.GFitsTableStringCol("DETNAM", 0, 20))
            table.append(gammalib.GFitsTableStringCol("FILTER", 0, 10))
            table.append(gammalib.GFitsTableStringCol("CAL_DEV", 0, 20))
            table.append(gammalib.GFitsTableStringCol("CAL_DIR", 0, 70))
            table.append(gammalib.GFitsTableStringCol("CAL_FILE", 0, 40))
            table.append(gammalib.GFitsTableStringCol("CAL_CLAS", 0, 3))
            table.append(gammalib.GFitsTableStringCol("CAL_DTYP", 0, 4))
            table.append(gammalib.GFitsTableStringCol("CAL_CNAM", 0, 20))
            table.append(gammalib.GFitsTableStringCol("CAL_CBD", 0, 70, 9))
            table.append(gammalib.GFitsTableShortCol("CAL_XNO", 0))
            table.append(gammalib.GFitsTableStringCol("CAL_VSD", 0, 10))
            table.append(gammalib.GFitsTableStringCol("CAL_VST", 0, 8))
            table.append(gammalib.GFitsTableDoubleCol("REF_TIME", 0))
            table.append(gammalib.GFitsTableShortCol("CAL_QUAL", 0))
            table.append(gammalib.GFitsTableStringCol("CAL_DATE", 0, 8))
            table.append(gammalib.GFitsTableStringCol("CAL_DESC", 0, 70))

        # Check if output config already exist
        has_config = False
        row_index = -1
        for caldir in table["CAL_DIR"]:
            row_index += 1
            if caldir == self._cal_dir:
                has_config = True
                break
         
        # Create columns if not available   
        if not has_config:           
            # Append 4 rows to CIF extension
            table.append_rows(4)
            row_index = table.nrows()
        else:
            row_index += 4

        # Add generic information for these 4 rows
        for i in range(4):

            # Set row number
            row = i + row_index-4

            # Set date
            now = str(datetime.datetime.now())
            today, time = now.split()
            
            # Set element
            table["TELESCOP"][row] = self._mission
            table["INSTRUME"][row] = self._caldb
            table["DETNAM"][row]   = "NONE"
            table["FILTER"][row]   = "NONE"
            table["CAL_DEV"][row]  = "ONLINE"
            table["CAL_CLAS"][row] = "BCF"
            table["CAL_DTYP"][row] = "DATA"
            table["CAL_VSD"][row]  = today
            table["CAL_VST"][row]  = time.split(".")[0]
            table["REF_TIME"][row] = 51544.0
            table["CAL_QUAL"][row] = 0
            table["CAL_CBD"][row]  = "NAME("+self["irf"].string()+")"
            table["CAL_DATE"][row] = today.replace("-","/")[2:]
            table["CAL_DIR"][row]  = self._cal_dir
            table["CAL_FILE"][row] = self._outfile

        # Add effective area information
        row = row_index-4
        table["CAL_CNAM"][row] = "EFF_AREA"
        table["CAL_DESC"][row] = self._caldb+" effective area"

        # Add point spread function information
        row = row_index-3
        table["CAL_CNAM"][row] = "RPSF"
        table["CAL_DESC"][row] = self._caldb+" point spread function"
        
        # Add energy dispersion information
        row = row_index-2
        table["CAL_CNAM"][row] = "EDISP"
        table["CAL_DESC"][row] = self._caldb+" energy dispersion"

        # Add background information
        row = row_index-1
        table["CAL_CNAM"][row] = "BGD"
        table["CAL_DESC"][row] = self._caldb+" background"

        # Log resulting FITS table and header
        if self._logNormal():
            self._log(str(table))
            self._log("\n")
        if self._logExplicit():
            self._log(str(table.header()))
            self._log("\n")
        
        # Return CIF FITS file
        return cif
Ejemplo n.º 4
0
        spec = models[nameSource].spectral()

        flux = spec.eval(e_ref, gammalib.GTime())
        theo_flux += flux

    print('\t* dF/dE(@ {:.2f} TeV): {:.3e} ph/(MeV cm**2 s)'.format(
        thiseref, theo_flux))

    #   Creating th fits file to save all the relevant results
    dmfits = gammalib.GFits()

    #   Creating table with number of rows equal to the number of sims
    table = gammalib.GFitsBinTable(args.nsims)

    #   Creating columns for every parameter to save
    col_runID = gammalib.GFitsTableShortCol('RunID', args.nsims)
    col_events = gammalib.GFitsTableDoubleCol('CubeEvents', args.nsims)
    # col_oevents = gammalib.GFitsTableDoubleCol( 'ObsEvents' , args.nsims )
    col_ts = gammalib.GFitsTableDoubleCol('TS', args.nsims)
    col_ulflux = gammalib.GFitsTableDoubleCol('ULFlux', args.nsims)
    col_scale = gammalib.GFitsTableDoubleCol('ScaleFactor', args.nsims)

    if is_anna_or_decs:

        col_cs = gammalib.GFitsTableDoubleCol('LogCrossSection', args.nsims)

    else:

        col_cs = gammalib.GFitsTableDoubleCol('LogLifetime', args.nsims)

    #   List of GFitsColumns