コード例 #1
0
    def __init__(self,
                 Burst='130427A',
                 redshift=0.34,
                 eblModel='Dominguez',
                 instrument='VERITAS',
                 zenith=20):

        self.redshift = redshift
        self.eblModel = eblModel
        self.instrument = instrument
        self.zenith = zenith

        # this finds the GRB file and reads it
        GRB = 'GRBs/' + Burst + '.csv'
        burst = asciitable.read(GRB, delimiter=',')

        # this makes the arrays to which we will add values from the GRB table
        start_time = []
        stop_time = []
        PI = []
        PI_err = []
        EF_erg = []
        PF = []
        PF_err = []
        EF_erg_err = []
        Flux_erg = []
        Flux_erg_error = []
        One_GeV = []
        One_GeV_P = []
        One_GeV_M = []
        Four_GeV = []
        Four_GeV_P = []
        Four_GeV_M = []
        One_TeV = []
        One_TeV_P = []
        One_TeV_M = []
        # this takes the values found under start time, stop time, etc. and places them in the arrays we made before
        for x_1 in burst['start time']:
            start_time.append(x_1)
        for x_2 in burst['stop time']:
            stop_time.append(x_2)
        for y in burst['photon flux']:
            PF.append(y)
        for y_1 in burst['photon flux err']:
            PF_err.append(y_1)
        for p in burst['Photon index']:
            PI.append(p)
        for p_1 in burst['Photon index error']:
            PI_err.append(p_1)
        for E_1 in burst['Energy flux (erg/cm2/s)']:
            Flux_erg.append(E_1)
        for E_e in burst['Energy flux error']:
            Flux_erg_error.append(E_e)

        self.PI = PI
        self.PI_err = PI_err
        # these make new arrays. One is the average time and the other is the time between the start time and the average
        time, time_err = zip(*[(((y - x) / 2) + x, (y - x) / 2)
                               for x, y in zip(start_time, stop_time)])
        self.time = time
        self.time_err = time_err
        # this changes ergs to GeV
        Flux_GeV = [624.150934 * x for x in Flux_erg]
        self.Flux_GeV = Flux_GeV
        Flux_GeV_error = [624.150934 * x for x in Flux_erg_error]
        self.Flux_GeV_error = Flux_GeV_error
        #The energy range for the LAT goes from 0.1 GeV to 100 GeV
        E2 = 100  # GeV
        E1 = 0.1  # GeV
        Norm = []
        Norm_P = []
        Norm_M = []
        for F, F_err, I in zip(PF, PF_err, PI):
            Norm.append(
                (F / (E2 - E1)) * ((E2**(1 - I) - E1**(1 - I)) / (1 - I)))
            Norm_P.append(((F + F_err) / (E2 - E1)) *
                          ((E2**(1 - I) - E1**(1 - I)) / (1 - I)))
            Norm_M.append(((F - F_err) / (E2 - E1)) *
                          ((E2**(1 - I) - E1**(1 - I)) / (1 - I)))
        self.Norm = Norm
        self.Norm_P = Norm_P
        self.Norm_M = Norm_M
        detTimes = []
        detTimes_p = []
        detTimes_m = []
        dNdE_new = np.array([])
        int_flux = []
        self.int_flux = int_flux
        int_flux_p = []
        self.int_flux_p = int_flux_p
        int_flux_m = []
        self.int_flux_m = int_flux_m
        crab_flux = []
        crab_flux_p = []
        crab_flux_m = []
        self.crab_flux = crab_flux
        self.crab_flux_p = crab_flux_p
        self.crab_flux_m = crab_flux_m
        for i, v in zip(Norm, PI):
            myVOT = VOT("custom",
                        eMin=0.001,
                        emax=100000,
                        Nbins=100000,
                        redshift=self.redshift,
                        eblModel=self.eblModel,
                        instrument=self.instrument,
                        zenith=self.zenith,
                        spectralModel='PowerLaw',
                        N0=i,
                        index=v,
                        E0=1)

            # makes a boolean array (Trues and Falses) of all the energy bins depending on whether 100 GeV > E > 0.1 GeV
            mymask = (myVOT.VS.EBins > 200)
            #print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
            #print mask

            # makes a new array of energies above 200 GeV
            E_new = [200] + myVOT.VS.EBins[mymask]
            # makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
            dNdE_new = [np.interp(200, myVOT.VS.EBins, myVOT.VS.dNdE)
                        ] + np.array(myVOT.VS.dNdE)[mymask]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV.append(np.interp(1, myVOT.VS.EBins, myVOT.VS.dNdE))
            Four_GeV.append(np.interp(400, myVOT.VS.EBins, myVOT.VS.dNdE))
            One_TeV.append(np.interp(1000, myVOT.VS.EBins, myVOT.VS.dNdE))
            self.One_GeV = One_GeV
            self.Four_GeV = Four_GeV
            self.One_TeV = One_TeV

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux.append(np.trapz(dNdE_new, x=E_new))

            #checks how long detection takes

            crabFlux = 100 * myVOT.rate * 60. / myVOT.VR.crabRate
            crab_flux.append(myVOT.VR.crabRate)
            detTime = np.interp([crabFlux * 0.01], myVOT.VR.SensCurve[:, 0],
                                myVOT.VR.SensCurve[:, 1])
            detTimes.append(detTime[0])
            self.detTimes = detTimes

        for i, v in zip(Norm_P, PI):
            myVOT_PFP = VOT("custom",
                            eMin=0.001,
                            emax=100000,
                            Nbins=100000,
                            redshift=self.redshift,
                            eblModel=self.eblModel,
                            instrument=self.instrument,
                            zenith=self.zenith,
                            spectralModel='PowerLaw',
                            N0=i,
                            index=v,
                            E0=1)

            # makes a boolean array (Trues and Falses) of all the energy bins depending on whether 100 GeV > E > 0.1 GeV
            mymask_p = (myVOT_PFP.VS.EBins > 200)

            # makes a new array of energies above 200 GeV
            E_new_p = [200] + myVOT_PFP.VS.EBins[mymask_p]
            # makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
            dNdE_new_p = [
                np.interp(200, myVOT_PFP.VS.EBins, myVOT_PFP.VS.dNdE)
            ] + np.array(myVOT_PFP.VS.dNdE)[mymask_p]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV_P.append(
                np.interp(1, myVOT_PFP.VS.EBins, myVOT_PFP.VS.dNdE))
            Four_GeV_P.append(
                np.interp(400, myVOT_PFP.VS.EBins, myVOT_PFP.VS.dNdE))
            One_TeV_P.append(
                np.interp(1000, myVOT_PFP.VS.EBins, myVOT_PFP.VS.dNdE))
            self.One_GeV_P = One_GeV_P
            self.Four_GeV_P = Four_GeV_P
            self.One_TeV_P = One_TeV_P

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux_p.append(np.trapz(dNdE_new_p, x=E_new_p))

            #checks how long detection takes

            crabFlux_p = 100 * myVOT_PFP.rate * 60. / myVOT_PFP.VR.crabRate
            crab_flux_p.append(myVOT_PFP.VR.crabRate)
            detTime_P = np.interp([crabFlux_p * 0.01],
                                  myVOT_PFP.VR.SensCurve[:, 0],
                                  myVOT_PFP.VR.SensCurve[:, 1])
            detTimes_p.append(detTime_P[0])
            self.detTimes_p = detTimes_p
        for i, v in zip(Norm_M, PI):
            myVOT_PFM = VOT("custom",
                            eMin=0.001,
                            emax=100000,
                            Nbins=100000,
                            redshift=self.redshift,
                            eblModel=self.eblModel,
                            instrument=self.instrument,
                            zenith=self.zenith,
                            spectralModel='PowerLaw',
                            N0=i,
                            index=v,
                            E0=1)

            # makes a boolean array (Trues and Falses) of all the energy bins depending on whether 100 GeV > E > 0.1 GeV
            mymask_m = (myVOT_PFM.VS.EBins > 200)
            #print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
            #print mask

            # makes a new array of energies above 200 GeV
            E_new_m = [200] + myVOT_PFM.VS.EBins[mymask_m]
            # makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
            dNdE_new_m = [
                np.interp(200, myVOT_PFM.VS.EBins, myVOT_PFM.VS.dNdE)
            ] + np.array(myVOT_PFM.VS.dNdE)[mymask_m]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV_M.append(
                np.interp(1, myVOT_PFM.VS.EBins, myVOT_PFM.VS.dNdE))
            Four_GeV_M.append(
                np.interp(400, myVOT_PFM.VS.EBins, myVOT_PFM.VS.dNdE))
            One_TeV_M.append(
                np.interp(1000, myVOT_PFM.VS.EBins, myVOT_PFM.VS.dNdE))
            self.One_GeV_M = One_GeV_M
            self.Four_GeV_M = Four_GeV_M
            self.One_TeV_M = One_TeV_M

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux_m.append(np.trapz(dNdE_new_m, x=E_new_m))

            #checks how long detection takes

            crabFlux_m = 100 * myVOT_PFM.rate * 60. / myVOT_PFM.VR.crabRate
            crab_flux_m.append(myVOT_PFM.VR.crabRate)
            detTime_m = np.interp([crabFlux_m * 0.01],
                                  myVOT_PFM.VR.SensCurve[:, 0],
                                  myVOT_PFM.VR.SensCurve[:, 1])
            detTimes_m.append(detTime_m[0])
            self.detTimes = detTimes_m
        perror = []
        self.perror = perror
        for err, perr in zip(int_flux, int_flux_p):
            perror.append(perr - err)
        merror = []
        self.merror = merror
        for err, merr in zip(int_flux, int_flux_m):
            merror.append(err - merr)

        One_GeV_M_error, Four_GeV_M_error, One_TeV_M_error = zip(
            *[((x - s), (y - t), (z - u)) for s, t, u, x, y, z in zip(
                One_GeV_M, Four_GeV_M, One_TeV_M, One_GeV, Four_GeV, One_TeV)])
        One_GeV_P_error, Four_GeV_P_error, One_TeV_P_error = zip(
            *[((s - x), (t - y), (u - z)) for s, t, u, x, y, z in zip(
                One_GeV_M, Four_GeV_M, One_TeV_M, One_GeV, Four_GeV, One_TeV)])
        self.One_GeV_M_error = One_GeV_M_error
        self.Four_GeV_M_error = Four_GeV_M_error
        self.One_TeV_M_error = One_TeV_M_error
        self.One_GeV_P_error = One_GeV_P_error
        self.Four_GeV_P_error = Four_GeV_P_error
        self.One_TeV_P_error = One_TeV_P_error
コード例 #2
0
ファイル: LC_2.py プロジェクト: RoCaerbannog/SummerWork
    def __init__(self,
                 Burst='130427A',
                 redshift=0.34,
                 eblModel='Dominguez',
                 instrument='VERITAS',
                 zenith=20):

        self.redshift = redshift
        self.eblModel = eblModel
        self.instrument = instrument
        self.zenith = zenith

        # this finds the GRB file and reads it
        GRB = 'GRBs/' + Burst + '.csv'
        burst = asciitable.read(GRB, delimiter=',')

        # this makes the arrays to which we will add values from the GRB table
        start_time = []
        stop_time = []
        Photon_index = []
        EF_erg = []
        EFM_erg = []

        # this takes the values found under start time, stop time, etc. and places them in the arrays we made before
        for x_1 in burst['start time']:
            start_time.append(x_1)
        for x_2 in burst['stop time']:
            stop_time.append(x_2)
        for y, y_1 in zip(burst['Energy flux (erg/cm2/s)'],
                          burst['Energy flux error']):
            Flux_erg = unumpy.uarray([y], [y_1])
        for p, p_1 in zip(burst['Photon index'], burst['Photon index error']):
            Photon_index = unumpy.uarray([p], [p_1])
        for a in burst['Energy flux plus']:
            EF_erg.append(a)
        for b in burst['Energy flux minus']:
            EFM_erg.append(b)

    # these make new arrays. One is the average time and the other is the time between the start time and the average
        time, time_err = zip(*[(((y - x) / 2) + x, (y - x) / 2)
                               for x, y in zip(start_time, stop_time)])
        # this changes ergs to GeV
        Flux_GeV = [624.150934 * x for x in Flux_erg]
        self.Flux_GeV = Flux_GeV

        dNdE_new = np.array([])
        int_flux = []
        for i, v in zip(Flux_GeV, Photon_index):
            myVOT = VOT("custom",
                        eMin=0.001,
                        emax=100000,
                        Nbins=100000,
                        redshift=self.redshift,
                        eblModel=self.eblModel,
                        instrument=self.instrument,
                        zenith=self.zenith,
                        spectralModel='PowerLaw',
                        N0=i,
                        index=v,
                        E0=1)

            # makes a boolean array (Trues and Falses) of all the energy bins depending on whether 100 GeV > E > 0.1 GeV
            mymask = (myVOT.VS.EBins > 0.1) + (myVOT.VS.EBins < 100)
            #print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
            #print mask

            # makes a new array of energies 100 GeV > E > 0.1 GeV
            E_new = [0.1] + myVOT.VS.EBins[mymask] + [100]
            # makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
            dNdE_new = [np.interp(0.1, myVOT.VS.EBins, myVOT.VS.dNdE)
                        ] + np.array(myVOT.VS.dNdE)[mymask] + [
                            np.interp(100, myVOT.VS.EBins, myVOT.VS.dNdE)
                        ]

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux.append(np.trapz(dNdE_new, x=E_new))

        #Flux_GeV_error =  [624.150934 * x for x in EF_erg]
        #Flux_error = np.array(Flux_GeV_error) - np.array(Flux_GeV)
        #self.Flux_error = Flux_error
        # this takes care of the flux error
        #dNdE_new_error = np.array([])
        #int_flux_error = []
        #for i, v in zip(Flux_GeV_error, Photon_index,):
        #myVOT_error = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
        #zenith = self.zenith , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)

        # makes a boolean array (Trues and Falses) of all the energy bins depending on whether E > 200 GeV
        #mymask = (myVOT_error.VS.EBins > 0.1) + (myVOT_error.VS.EBins < 100)
        #print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
        #print mask

        # makes a new array of energies 100 GeV > E > 0.1 GeV
        #E_new_error = [0.1] + myVOT_error.VS.EBins[mymask] + [100]
        # makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
        #dNdE_new_error = [np.interp(0.1, myVOT.VS.EBins, myVOT_error.VS.dNdE)] + np.array(myVOT_error.VS.dNdE)[mymask] +[np.interp(100, myVOT.VS.EBins, myVOT_error.VS.dNdE)]

        # Integrates differential flux with respect to energy bins using the trapezoid rule
        #int_flux_error.append(np.trapz(dNdE_new_error, x = E_new))

        #
        #error = np.array(int_flux_error)-np.array(int_flux)
        # assigns instances(attributes) to the take_data class so that it can be called in the notebook
        self.time = time
        self.int_flux = int_flux
        self.error = error
        self.time_err = time_err
        self.E_new = E_new
        self.myVOT = myVOT

        #print int_flux
        #fig2 = pyplot.figure(figsize=(16,8))
        #fig2ax1 = fig2.add_subplot(111)
        #fig2ax1.set_ylabel(r'Integral Flux [cm$^{-2}$ s$^{-1}$ GeV$^{-1}$]')
        #fig2ax1.set_xlabel('Time [s]')
        #fig2ax1.errorbar(time, int_flux, xerr=time_err, fmt='o')
        #fig2ax1.loglog(time, int_flux)
        #legend()
        #pyplot.show()
コード例 #3
0
    def __init__(self,
                 Burst='130427A',
                 redshift=0.34,
                 eblModel='Dominguez',
                 instrument='VERITAS',
                 zenith=20):

        #Although it is a bit unclear to me why, you have to put a self. before things so that the code can refer to that piece of code.
        self.redshift = redshift
        self.eblModel = eblModel
        self.instrument = instrument
        self.zenith = zenith

        # this finds the GRB file and reads it there is another file I created that will take txt files and convert it to a more friendly csv file
        GRB = 'GRBs/' + Burst + '.csv'
        burst = asciitable.read(GRB, delimiter=',')

        # this makes the arrays(tuple) to which we will add values from the GRB table
        # that way we can reference these later and pull out any and all values we are interested in
        start_time = []
        stop_time = []
        PI = []
        PI_err = []
        EF_erg = []
        PF = []
        PF_err = []
        EF_erg_err = []
        Flux_erg = []
        Flux_erg_error = []
        One_GeV = []
        One_GeV_P = []
        One_GeV_PI = []
        One_GeV_M = []
        One_GeV_MI = []
        Four_GeV = []
        Four_GeV_P = []
        Four_GeV_PI = []
        Four_GeV_M = []
        Four_GeV_MI = []
        One_TeV = []
        One_TeV_P = []
        One_TeV_PI = []
        One_TeV_M = []
        One_TeV_MI = []

        # this imports the data from the csv files
        # It looks specifically for certain header names. It's very picky so I suggest using the converter file I created.
        # Now, ideally, we have all the data we could possibly need from the csv files
        for x_1 in burst['start time']:
            start_time.append(x_1)
        for x_2 in burst['stop time']:
            stop_time.append(x_2)
        for y in burst['photon flux']:
            PF.append(y)
        for y_1 in burst['photon flux err']:
            PF_err.append(y_1)
        for p in burst['Photon index']:
            PI.append(p)
        for p_1 in burst['Photon index error']:
            PI_err.append(p_1)
        for E_1 in burst['Energy flux (erg/cm2/s)']:
            Flux_erg.append(E_1)
        for E_e in burst['Energy flux error']:
            Flux_erg_error.append(E_e)

        self.PI = PI
        self.PI_err = PI_err

        #photon index error calculator
        PIP, PIM = zip(*[(pi + pie, pi - pie) for pi, pie in zip(PI, PI_err)])
        self.PIP = PIP
        self.PIM = PIM

        # these make new arrays. One is the center of each time bin and the other is the time between the center and edge of each time bin
        time, time_err = zip(*[(((y - x) / 2) + x, (y - x) / 2)
                               for x, y in zip(start_time, stop_time)])
        self.time = time
        self.time_err = time_err

        # So we have all these time bins and for loops but it would be nice, say if we wanted the differential flux for a single time bin, to call a specific time bin
        # well I was nice enough to do it for you
        time_bin = range(0, len(time), 1)

        # This changes the Flux from the LAT from ergs to GeV
        Flux_GeV = [624.150934 * x for x in Flux_erg]
        self.Flux_GeV = Flux_GeV
        Flux_GeV_error = [624.150934 * x for x in Flux_erg_error]
        self.Flux_GeV_error = Flux_GeV_error
        # The energy range for the LAT goes from 0.1 GeV to 100 GeV
        E2 = 100  # GeV
        E1 = 0.1  # GeV
        Norm = []
        Norm_P = []
        Norm_M = []
        # This neat little formula saved me a bit of time. Rather than do the calculation and write a new csv file, this does the calculations for the Normalization values N0 here.
        for F, F_err, I in zip(PF, PF_err, PI):
            Norm.append(
                (F / (E2 - E1)) * ((E2**(1 + I) - E1**(1 + I)) / (1 + I)))
            Norm_P.append(((F + F_err) / (E2 - E1)) *
                          ((E2**(1 + I) - E1**(1 + I)) / (1 + I)))
            Norm_M.append(((F - F_err) / (E2 - E1)) *
                          ((E2**(1 + I) - E1**(1 + I)) / (1 + I)))
        self.Norm = Norm
        self.Norm_P = Norm_P
        self.Norm_M = Norm_M
        #Lots and Lots of arrays(tuples)
        detTimes = []
        detTimes_p = []
        detTimes_pi = []
        detTimes_m = []
        detTimes_mi = []
        dNdE_new = np.array([])
        int_flux = []
        self.int_flux = int_flux
        int_flux_p = []
        self.int_flux_p = int_flux_p
        int_flux_pi = []
        self.int_flux_pi = int_flux_pi
        int_flux_m = []
        self.int_flux_m = int_flux_m
        int_flux_mi = []
        self.int_flux_mi = int_flux_mi
        crab_flux = []
        crab_flux_p = []
        crab_flux_pi = []
        self.crab_flux_pi = crab_flux_pi
        crab_flux_m = []
        crab_flux_mi = []
        self.crab_flux_mi = crab_flux_mi
        self.crab_flux = crab_flux
        self.crab_flux_p = crab_flux_p
        self.crab_flux_m = crab_flux_m
        HAWCDetTimes = []
        self.HAWCDetTimes = HAWCDetTimes

        # A dictionary so that we can refer to specific time bins later
        myVOT = {}
        self.myVOT = myVOT
        # the nominal calculation. No errors involved
        for tb, i, v in zip(time_bin, Norm, PI):
            myVOT['{}'.format(tb)] = VOT("custom",
                                         eMin=0.001,
                                         emax=100000,
                                         Nbins=100000,
                                         redshift=self.redshift,
                                         eblModel=self.eblModel,
                                         instrument=self.instrument,
                                         zenith=self.zenith,
                                         spectralModel='PowerLaw',
                                         N0=i,
                                         index=v,
                                         E0=1)
            redshift = self.redshift

            # makes a boolean array (Trues and Falses) of all the energy bins True if E > 10**self.VR.EASummary['minSafeE'] GeV
            mymask = (myVOT['{}'.format(tb)].VS.EBins > 10**
                      myVOT['{}'.format(tb)].VR.EASummary['minSafeE'])
            #print np.shape(mymask),type(myVOT['{}'.format(tb)].VS.EBins),type(myVOT['{}'.format(tb)].VS.dNdE)
            #print mask

            # makes a new array of energies above 10**self.VR.EASummary['minSafeE'] GeV
            E_new = [10**myVOT['{}'.format(tb)].VR.EASummary['minSafeE']
                     ] + myVOT['{}'.format(tb)].VS.EBins[mymask]
            # makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
            dNdE_new = [
                np.interp(10**myVOT['{}'.format(tb)].VR.EASummary['minSafeE'],
                          myVOT['{}'.format(tb)].VS.EBins,
                          myVOT['{}'.format(tb)].VS.dNdE_absorbed)
            ] + np.array(myVOT['{}'.format(tb)].VS.dNdE_absorbed)[mymask]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV.append(
                np.interp(1, myVOT['{}'.format(tb)].VS.EBins,
                          myVOT['{}'.format(tb)].VS.dNdE_absorbed))
            Four_GeV.append(
                np.interp(400, myVOT['{}'.format(tb)].VS.EBins,
                          myVOT['{}'.format(tb)].VS.dNdE_absorbed))
            One_TeV.append(
                np.interp(1000, myVOT['{}'.format(tb)].VS.EBins,
                          myVOT['{}'.format(tb)].VS.dNdE_absorbed))
            self.One_GeV = One_GeV
            self.Four_GeV = Four_GeV
            self.One_TeV = One_TeV

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux.append(np.trapz(dNdE_new, x=E_new))

            #checks how long detection takes

            crabFlux = 100 * myVOT['{}'.format(tb)].rate * 60. / myVOT[
                '{}'.format(tb)].VR.crabRate
            crab_flux.append(myVOT['{}'.format(tb)].VR.crabRate)
            detTime = np.interp([crabFlux * 0.01],
                                myVOT['{}'.format(tb)].VR.SensCurve[:, 0],
                                myVOT['{}'.format(tb)].VR.SensCurve[:, 1]) * 60
            detTimes.append(detTime[0])
            self.detTimes = detTimes
            R_pmt = 20 * 10**(-9)  # 20 ns
            N_pmt = 900  # 3 PMTs in 300 tanks
            HAWCDetTimes.append(25 * R_pmt * N_pmt /
                                (myVOT['{}'.format(tb)].rate * 60)**
                                2)  # detection time in hours

        # Only taking into account the difference in positive normalization values
        myVOT_PFP = {}
        self.myVOT_PFP = myVOT_PFP

        for tb, i, v in zip(time_bin, Norm_P, PI):
            myVOT_PFP['{}'.format(tb)] = VOT("custom",
                                             eMin=0.001,
                                             emax=100000,
                                             Nbins=100000,
                                             redshift=self.redshift,
                                             eblModel=self.eblModel,
                                             instrument=self.instrument,
                                             zenith=self.zenith,
                                             spectralModel='PowerLaw',
                                             N0=i,
                                             index=v,
                                             E0=1)

            # makes a boolean array (Trues and Falses) of all the energy bins True if E > 10**self.VR.EASummary['minSafeE'] GeV
            mymask_p = (myVOT_PFP['{}'.format(tb)].VS.EBins > 10**
                        myVOT_PFP['{}'.format(tb)].VR.EASummary['minSafeE'])

            # makes a new array of energies above 10**self.VR.EASummary['minSafeE'] GeV
            E_new_p = [
                10**myVOT_PFP['{}'.format(tb)].VR.EASummary['minSafeE']
            ] + myVOT_PFP['{}'.format(tb)].VS.EBins[mymask_p]
            # makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
            dNdE_new_p = [
                np.interp(
                    10**myVOT_PFP['{}'.format(tb)].VR.EASummary['minSafeE'],
                    myVOT_PFP['{}'.format(tb)].VS.EBins,
                    myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed)
            ] + np.array(myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed)[mymask_p]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV_P.append(
                np.interp(1, myVOT_PFP['{}'.format(tb)].VS.EBins,
                          myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed))
            Four_GeV_P.append(
                np.interp(400, myVOT_PFP['{}'.format(tb)].VS.EBins,
                          myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed))
            One_TeV_P.append(
                np.interp(1000, myVOT_PFP['{}'.format(tb)].VS.EBins,
                          myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed))
            self.One_GeV_P = One_GeV_P
            self.Four_GeV_P = Four_GeV_P
            self.One_TeV_P = One_TeV_P

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux_p.append(np.trapz(dNdE_new_p, x=E_new_p))

            #checks how long detection takes

            crabFlux_p = 100 * myVOT_PFP['{}'.format(
                tb)].rate * 60. / myVOT_PFP['{}'.format(tb)].VR.crabRate
            crab_flux_p.append(myVOT_PFP['{}'.format(tb)].VR.crabRate)
            detTime_P = np.interp(
                [crabFlux_p * 0.01],
                myVOT_PFP['{}'.format(tb)].VR.SensCurve[:, 0],
                myVOT_PFP['{}'.format(tb)].VR.SensCurve[:, 1]) * 60
            detTimes_p.append(detTime_P[0])
            self.detTimes_p = detTimes_p

            myVOT_PFM = {}
            self.myVOT_PFM = myVOT_PFM
            # only taking into account the difference in negative normalization error
        for tb, i, v in zip(time_bin, Norm_M, PI):
            myVOT_PFM['{}'.format(tb)] = VOT("custom",
                                             eMin=0.001,
                                             emax=100000,
                                             Nbins=100000,
                                             redshift=self.redshift,
                                             eblModel=self.eblModel,
                                             instrument=self.instrument,
                                             zenith=self.zenith,
                                             spectralModel='PowerLaw',
                                             N0=i,
                                             index=v,
                                             E0=1)

            # makes a boolean array (Trues and Falses) of all the energy bins depending on whether True if E > 10**self.VR.EASummary['minSafeE'] GeV
            mymask_m = (myVOT_PFM['{}'.format(tb)].VS.EBins > 10**
                        myVOT_PFM['{}'.format(tb)].VR.EASummary['minSafeE'])
            #print np.shape(mymask),type(myVOT['{}'.format(tb)].VS.EBins),type(myVOT['{}'.format(tb)].VS.dNdE)
            #print mask

            # makes a new array of energies above the minimum sensitivity
            E_new_m = [
                10**myVOT_PFM['{}'.format(tb)].VR.EASummary['minSafeE']
            ] + myVOT_PFM['{}'.format(tb)].VS.EBins[mymask_m]
            # makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
            dNdE_new_m = [
                np.interp(
                    10**myVOT_PFM['{}'.format(tb)].VR.EASummary['minSafeE'],
                    myVOT_PFM['{}'.format(tb)].VS.EBins,
                    myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed)
            ] + np.array(myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed)[mymask_m]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV_M.append(
                np.interp(1, myVOT_PFM['{}'.format(tb)].VS.EBins,
                          myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed))
            Four_GeV_M.append(
                np.interp(400, myVOT_PFM['{}'.format(tb)].VS.EBins,
                          myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed))
            One_TeV_M.append(
                np.interp(1000, myVOT_PFM['{}'.format(tb)].VS.EBins,
                          myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed))
            self.One_GeV_M = One_GeV_M
            self.Four_GeV_M = Four_GeV_M
            self.One_TeV_M = One_TeV_M

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux_m.append(np.trapz(dNdE_new_m, x=E_new_m))

            #checks how long detection takes

            crabFlux_m = 100 * myVOT_PFM['{}'.format(
                tb)].rate * 60. / myVOT_PFM['{}'.format(tb)].VR.crabRate
            crab_flux_m.append(myVOT_PFM['{}'.format(tb)].VR.crabRate)
            detTime_m = np.interp(
                [crabFlux_m * 0.01],
                myVOT_PFM['{}'.format(tb)].VR.SensCurve[:, 0],
                myVOT_PFM['{}'.format(tb)].VR.SensCurve[:, 1]) * 60
            detTimes_m.append(detTime_m[0])
            self.detTimes_m = detTimes_m

        perror = []
        self.perror = perror
        for err, perr in zip(int_flux, int_flux_p):
            perror.append(perr - err)
        merror = []
        self.merror = merror
        for err, merr in zip(int_flux, int_flux_m):
            merror.append(err - merr)

        # photon index error
        myVOT_PIP = {}
        self.myVOT_PIP = myVOT_PIP
        int_flux_pi = []
        self.int_flux_pi = int_flux_pi
        #positive photon index error and positive normalization error
        for tb, i, v in zip(time_bin, Norm_P, PIP):
            myVOT_PIP['{}'.format(tb)] = VOT("custom",
                                             eMin=0.001,
                                             emax=100000,
                                             Nbins=100000,
                                             redshift=self.redshift,
                                             eblModel=self.eblModel,
                                             instrument=self.instrument,
                                             zenith=self.zenith,
                                             spectralModel='PowerLaw',
                                             N0=i,
                                             index=v,
                                             E0=1)
            self.index_p = v
            # makes a boolean array (Trues and Falses) of all the energy bins True if E > 10**self.VR.EASummary['minSafeE'] GeV
            mymask_pi = (myVOT_PIP['{}'.format(tb)].VS.EBins > 10**
                         myVOT_PIP['{}'.format(tb)].VR.EASummary['minSafeE'])

            # makes a new array of energies above 10**self.VR.EASummary['minSafeE'] GeV
            E_new_pi = [
                10**myVOT_PIP['{}'.format(tb)].VR.EASummary['minSafeE']
            ] + myVOT_PIP['{}'.format(tb)].VS.EBins[mymask_pi]
            # makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
            dNdE_new_pi = [
                np.interp(
                    10**myVOT_PIP['{}'.format(tb)].VR.EASummary['minSafeE'],
                    myVOT_PIP['{}'.format(tb)].VS.EBins,
                    myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed)
            ] + np.array(
                myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed)[mymask_pi]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV_PI.append(
                np.interp(1, myVOT_PIP['{}'.format(tb)].VS.EBins,
                          myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed))
            Four_GeV_PI.append(
                np.interp(400, myVOT_PIP['{}'.format(tb)].VS.EBins,
                          myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed))
            One_TeV_PI.append(
                np.interp(1000, myVOT_PIP['{}'.format(tb)].VS.EBins,
                          myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed))
            self.One_GeV_PI = One_GeV_PI
            self.Four_GeV_PI = Four_GeV_PI
            self.One_TeV_PI = One_TeV_PI

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux_pi.append(np.trapz(dNdE_new_pi, x=E_new_pi))

            #checks how long detection takes

            crabFlux_pi = 100 * myVOT_PIP['{}'.format(
                tb)].rate * 60. / myVOT_PIP['{}'.format(tb)].VR.crabRate
            crab_flux_pi.append(myVOT_PIP['{}'.format(tb)].VR.crabRate)
            detTime_PI = np.interp(
                [crabFlux_pi * 0.01],
                myVOT_PIP['{}'.format(tb)].VR.SensCurve[:, 0],
                myVOT_PIP['{}'.format(tb)].VR.SensCurve[:, 1]) * 60
            detTimes_pi.append(detTime_PI[0])
            self.detTimes_pi = detTimes_pi

        myVOT_PIM = {}
        self.myVOT_PIM = myVOT_PIM
        int_flux_mi = []
        self.int_flux_mi = int_flux_mi
        # negative photon index error and normalization error
        for tb, i, v in zip(time_bin, Norm_M, PIM):
            myVOT_PIM['{}'.format(tb)] = VOT("custom",
                                             eMin=0.001,
                                             emax=100000,
                                             Nbins=100000,
                                             redshift=self.redshift,
                                             eblModel=self.eblModel,
                                             instrument=self.instrument,
                                             zenith=self.zenith,
                                             spectralModel='PowerLaw',
                                             N0=i,
                                             index=v,
                                             E0=1)
            self.index_m = v
            # makes a boolean array (Trues and Falses) of all the energy bins True if E > 10**self.VR.EASummary['minSafeE'] GeV
            mymask_mi = (myVOT_PIM['{}'.format(tb)].VS.EBins > 10**
                         myVOT_PIM['{}'.format(tb)].VR.EASummary['minSafeE'])
            #print np.shape(mymask),type(myVOT['{}'.format(tb)].VS.EBins),type(myVOT['{}'.format(tb)].VS.dNdE)
            #print mask

            # makes a new array of energies above 10**self.VR.EASummary['minSafeE'] GeV
            E_new_mi = [
                10**myVOT_PIM['{}'.format(tb)].VR.EASummary['minSafeE']
            ] + myVOT_PIM['{}'.format(tb)].VS.EBins[mymask_m]
            # makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
            dNdE_new_mi = [
                np.interp(
                    10**myVOT_PIM['{}'.format(tb)].VR.EASummary['minSafeE'],
                    myVOT_PIM['{}'.format(tb)].VS.EBins,
                    myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed)
            ] + np.array(
                myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed)[mymask_mi]
            # interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV
            One_GeV_MI.append(
                np.interp(1, myVOT_PIM['{}'.format(tb)].VS.EBins,
                          myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed))
            Four_GeV_MI.append(
                np.interp(400, myVOT_PIM['{}'.format(tb)].VS.EBins,
                          myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed))
            One_TeV_MI.append(
                np.interp(1000, myVOT_PIM['{}'.format(tb)].VS.EBins,
                          myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed))
            self.One_GeV_MI = One_GeV_MI
            self.Four_GeV_MI = Four_GeV_MI
            self.One_TeV_MI = One_TeV_MI

            # Integrates differential flux with respect to energy bins using the trapezoid rule
            int_flux_mi.append(np.trapz(dNdE_new_mi, x=E_new_mi))

            #checks how long detection takes

            crabFlux_mi = 100 * myVOT_PIM['{}'.format(
                tb)].rate * 60. / myVOT_PIM['{}'.format(tb)].VR.crabRate
            crab_flux_mi.append(myVOT_PIM['{}'.format(tb)].VR.crabRate)
            detTime_mi = np.interp(
                [crabFlux_mi * 0.01],
                myVOT_PIM['{}'.format(tb)].VR.SensCurve[:, 0],
                myVOT_PIM['{}'.format(tb)].VR.SensCurve[:, 1]) * 60
            detTimes_mi.append(detTime_mi[0])
            self.detTimes_mi = detTimes_mi

        # Lots and lots of error calculations
        One_GeV_M_error, Four_GeV_M_error, One_TeV_M_error = zip(
            *[((x - s), (y - t), (z - u)) for s, t, u, x, y, z in zip(
                One_GeV_M, Four_GeV_M, One_TeV_M, One_GeV, Four_GeV, One_TeV)])
        One_GeV_P_error, Four_GeV_P_error, One_TeV_P_error = zip(
            *[((s - x), (t - y), (u - z)) for s, t, u, x, y, z in zip(
                One_GeV_M, Four_GeV_M, One_TeV_M, One_GeV, Four_GeV, One_TeV)])
        self.One_GeV_M_error = One_GeV_M_error
        self.Four_GeV_M_error = Four_GeV_M_error
        self.One_TeV_M_error = One_TeV_M_error
        self.One_GeV_P_error = One_GeV_P_error
        self.Four_GeV_P_error = Four_GeV_P_error
        self.One_TeV_P_error = One_TeV_P_error
コード例 #4
0
	def __init__(self, Burst = '130427A', redshift = 0.34, eblModel = 'Dominguez', instrument = 'VERITAS', date = '2013/4/25 08:05:12', GC = [173.1370800,27.6990200]):	

		self.redshift = redshift
		self.eblModel = eblModel
		self.instrument = instrument
		self.date = date
		self.GC = GC

	# this finds the GRB file and reads it 
		GRB = 'GRBs/'+ Burst +'.csv'
		burst = asciitable.read(GRB, delimiter = ',')
	
	# this makes the arrays to which we will add values from the GRB table
		start_time = []
		stop_time = []
		Photon_index = []
		EF_erg = []
		EFM_erg = []
		Flux_erg = []
		One_GeV = []
		Four_GeV = []
		One_TeV = []
	# this takes the values found under start time, stop time, etc. and places them in the arrays we made before
		for x_1 in burst['start time']:
			start_time.append(x_1)
		for x_2 in burst['stop time']:
			stop_time.append(x_2)
		for y in burst['Energy flux (erg/cm2/s)']:
			Flux_erg.append(y)
		for y_1 in burst['Energy flux error']:
			EF_erg.append(y_1)
		for p in burst['Photon index']:
			Photon_index.append(p)
		
	# these make new arrays. One is the average time and the other is the time between the start time and the average
		time,time_err = zip(*[(((y-x)/2)+x,(y-x)/2) for x,y in zip(start_time, stop_time)])
		"""
		Here we write in the locations of the various telescopes. This uses some tricks of the dictionary capability of python.
		For now I'm just using the TeV Cat locations. Elevations I got from the CTA paper/HAWC website
		Locations:- 110.952158','31.675058
		Veritas: http://tevcat.uchicago.edu/
		H.E.S.S.: http://tevcat.uchicago.edu/
		HAWC: http://www.ice.phys.psu.edu/~deyoung/Home/HAWC.html
		CTA:    http://dx.doi.org/10.1016/j.bbr.2011.03.031
		http://dx.doi.org/10.1016/j.bbr.2011.03.031
		"""
		
		# sets veritas as a telescope
		veritas = ephem.Observer()
		veritas.lon, veritas.lat = '-110.952158','31.675058'
		veritas.elevation = 1275.
		
		#sets HESS as a telescope
		hess = ephem.Observer()
		hess.lon, hess.lat = '16.5','-23.16'
		hess.elevation = 1800.
		
		# sets CTA as a telescope
		cta = ephem.Observer()
		cta.lon, cta.lat = '-25.', '30.'
		cta.elevation = 2000.
		
		#sets HAWC as a telescope
		hawc = ephem.Observer()
		hawc.lon, hawc.lat = '-97.307', '18.995'
		hawc.elevation = 4100.
		
		# The dictionary 
		instruments = { 'VERITAS': veritas, 'HAWC': hawc, 'HESS': hess, 'CTA': cta}
		# Sets a Fixed Astronomical Body
		grb = ephem.FixedBody(GC[0],GC[1])
		
		# Takes the difference between the time bins in order to create steps 
		tdiff = [time[n]-time[n-1] for n in range(1,len(time))]
		
		myinstrument = instruments[instrument]
		
		dates = []
		zenith = []
		moon = []
		myinstrument.date = date
		
		for t,t_diff in zip(time, tdiff):  
   			grb.compute(veritas)
    		m = ephem.Moon(veritas)
    		#print veritas.date,grb.alt
    		dates = np.append(dates,myinstrument.date)
    		zenith = np.append(zenith, 90 + np.degrees(grb.alt))
    		moon = np.append(moon, np.degrees(m.alt))
    		myinstrument.date += t_diff/(24.*60.)
		
		self.zenith = zenith
		self.dates = dates
	# this changes ergs to GeV
		Flux_GeV =  [624.150934 * x for x in Flux_erg]
		self.Flux_GeV = Flux_GeV
	 	detTimes =[]
 		dNdE_new = np.array([])
	 	int_flux = []
	 	crab_flux =[]
	 	self.crab_flux = crab_flux
		for i, v, t in zip(Flux_GeV, Photon_index, zenith):
			myVOT = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = t , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			
			# makes a boolean array (Trues and Falses) of all the energy bins depending on whether 100 GeV > E > 0.1 GeV
			mymask = (myVOT.VS.EBins > 200) 
			#print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
			#print mask
			
			# makes a new array of energies above 200 GeV
			E_new = [200] + myVOT.VS.EBins[mymask]
			# makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
			dNdE_new = [np.interp(200, myVOT.VS.EBins, myVOT.VS.dNdE)] + np.array(myVOT.VS.dNdE)[mymask] 
			# interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV 
			One_GeV.append(np.interp(1,myVOT.VS.EBins, myVOT.VS.dNdE))
			Four_GeV.append(np.interp(400,myVOT.VS.EBins, myVOT.VS.dNdE))
			One_TeV.append(np.interp(1000,myVOT.VS.EBins, myVOT.VS.dNdE))
			self.One_GeV = One_GeV
			self.Four_GeV = Four_GeV
			self.One_TeV = One_TeV
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			int_flux.append(np.trapz(dNdE_new, x = E_new))
			
			#checks how long detection takes
			
			crabFlux = 100*myVOT.rate*60./myVOT.VR.crabRate
			crab_flux.append(myVOT.VR.crabRate)
			detTime = np.interp([crabFlux*0.01], myVOT.VR.SensCurve[:,0], myVOT.VR.SensCurve[:,1])
			detTimes.append(detTime[0])
			self.detTimes = detTimes
		print detTimes
		
		Flux_GeV_error =  [624.150934 * x for x in EF_erg]
		EFP_GeV_error = [] 
		for x,y in zip(Flux_GeV_error,Flux_GeV):
			EFP_GeV_error.append(x+y) 
		Flux_error = np.array(Flux_GeV_error) - np.array(Flux_GeV)
		self.Flux_error = Flux_error
	 # this takes care of the flux error
 		dNdE_new_error = np.array([])
	 	int_flux_error = []
		for i, v, t in zip(EFP_GeV_error, Photon_index, zenith):
			myVOT_error = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = t , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			
			# makes a boolean array (Trues and Falses) of all the energy bins depending on whether E > 200 GeV
			mymask = (myVOT_error.VS.EBins > 200)  
			#print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
			#print mask
			
			# makes a new array of energies 100 GeV > E > 0.1 GeV
			E_new_error = [200] + myVOT_error.VS.EBins[mymask] 
			# makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
			dNdE_new_error = [np.interp(200, myVOT.VS.EBins, myVOT_error.VS.dNdE)] + np.array(myVOT_error.VS.dNdE)[mymask] 
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			int_flux_error.append(np.trapz(dNdE_new_error, x = E_new))
		
			# 
		error = np.array(int_flux_error)-np.array(int_flux) 
		# assigns instances(attributes) to the take_data class so that it can be called in the notebook
		self.time = time
		self.int_flux = int_flux
		self.int_flux_error = int_flux_error
		self.error = error
		self.time_err = time_err
		self.E_new = E_new
		self.myVOT = myVOT
		
		
	
		#print int_flux	
		#fig2 = pyplot.figure(figsize=(16,8))
		#fig2ax1 = fig2.add_subplot(111)
		#fig2ax1.set_ylabel(r'Integral Flux [cm$^{-2}$ s$^{-1}$ GeV$^{-1}$]')
		#fig2ax1.set_xlabel('Time [s]')
		#fig2ax1.errorbar(time, int_flux, xerr=time_err, fmt='o')
		#fig2ax1.loglog(time, int_flux)
		#legend()
		#pyplot.show()
コード例 #5
0
    def __init__(self,
                 redshift=0.34,
                 eblModel='Dominguez',
                 instrument='VERITAS',
                 zenith=20,
                 index=-1.2,
                 index_err=0.17,
                 N0=1000,
                 start_time=0,
                 stop_time=1000):

        self.redshift = redshift
        self.eblModel = eblModel
        self.instrument = instrument
        self.zenith = zenith
        self.index = index
        self.index_err = index_err
        self.N0 = N0
        self.start_time = start_time
        self.stop_time = stop_time

        # this finds the GRB file and reads it
        #GRB = 'GRBs/'+ Burst +'.csv'
        #burst = asciitable.read(GRB, delimiter = ',')

        # this makes the arrays to which we will add values from the GRB table
        #start_time = []
        #stop_time = []
        #Photon_index = []
        #EF_erg = []
        #EFM_erg = []
        #Flux_erg = []
        #One_GeV = []
        #Four_GeV = []
        #One_TeV = []
        # this takes the values found under start time, stop time, etc. and places them in the arrays we made before

        # these make new arrays. One is the average time and the other is the time between the start time and the average
        #time,time_err = zip(*[(((y-x)/2)+x,(y-x)/2) for x,y in zip(start_time, stop_time)])
        # this changes ergs to GeV
        #Flux_GeV =  [624.150934 * x for x in Flux_erg]
        #self.Flux_GeV = Flux_GeV
        #detTimes =[]
        #dNdE_new = np.array([])
        #int_flux = []
        myVOT = VOT("custom",
                    eMin=0.001,
                    emax=100000,
                    Nbins=100000,
                    redshift=self.redshift,
                    eblModel=self.eblModel,
                    instrument=self.instrument,
                    zenith=self.zenith,
                    spectralModel='PowerLaw',
                    N0=self.N0,
                    index=self.index,
                    E0=1)
        myVOT_P = VOT("custom",
                      eMin=0.001,
                      emax=100000,
                      Nbins=100000,
                      redshift=self.redshift,
                      eblModel=self.eblModel,
                      instrument=self.instrument,
                      zenith=self.zenith,
                      spectralModel='PowerLaw',
                      N0=self.N0,
                      index=self.index + self.index_err,
                      E0=1)
        myVOT_M = VOT("custom",
                      eMin=0.001,
                      emax=100000,
                      Nbins=100000,
                      redshift=self.redshift,
                      eblModel=self.eblModel,
                      instrument=self.instrument,
                      zenith=self.zenith,
                      spectralModel='PowerLaw',
                      N0=self.N0,
                      index=self.index - self.index_err,
                      E0=1)

        self.myVOT = myVOT
        self.myVOT_P = myVOT_P
        self.myVOT_M = myVOT_M

        mymask = (myVOT.VS.EBins > 200)
        mymask_p = (myVOT_P.VS.EBins > 200)
        mymask_m = (myVOT_M.VS.EBins > 200)

        E_new = [200] + myVOT.VS.EBins[mymask]
        E_new_p = [200] + myVOT_P.VS.EBins[mymask_p]
        E_new_m = [200] + myVOT_M.VS.EBins[mymask_m]
        dNdE_new = [np.interp(200, myVOT.VS.EBins, myVOT.VS.dNdE)] + np.array(
            myVOT.VS.dNdE)[mymask]
        dNdE_new_p = [np.interp(200, myVOT_P.VS.EBins, myVOT_P.VS.dNdE)
                      ] + np.array(myVOT_P.VS.dNdE)[mymask_p]
        dNdE_new_m = [np.interp(200, myVOT_M.VS.EBins, myVOT_M.VS.dNdE)
                      ] + np.array(myVOT_M.VS.dNdE)[mymask_m]

        # percent error and integrated flux
        int_flux = np.trapz(dNdE_new, x=E_new)
        int_flux_p = np.trapz(dNdE_new_p, x=E_new_p)
        int_flux_m = np.trapz(dNdE_new_m, x=E_new_m)
        pp_error = (np.absolute(int_flux_p - int_flux) / int_flux) * 100
        pm_error = (np.absolute(int_flux_m - int_flux) / int_flux) * 100
        self.int_flux = int_flux
        self.int_flux_p = int_flux_p
        self.int_flux_m = int_flux_m
        self.pp_error = pp_error
        self.pm_error = pm_error

        time_bin = stop_time - start_time

        #checks how long detection takes
        crabFlux = 100 * myVOT.rate * 60. / myVOT.VR.crabRate
        self.crabFlux = crabFlux
        crabFlux_p = 100 * myVOT_P.rate * 60. / myVOT_P.VR.crabRate
        crabFlux_m = 100 * myVOT_M.rate * 60. / myVOT_M.VR.crabRate
        detTime = np.interp([crabFlux * 0.01], myVOT.VR.SensCurve[:, 0],
                            myVOT.VR.SensCurve[:, 1]) * 60
        detTime_p = np.interp([crabFlux_p * 0.01], myVOT_P.VR.SensCurve[:, 0],
                              myVOT_P.VR.SensCurve[:, 1]) * 60
        detTime_m = np.interp([crabFlux_m * 0.01], myVOT_M.VR.SensCurve[:, 0],
                              myVOT_M.VR.SensCurve[:, 1]) * 60
        self.detTime = detTime
        self.detTime_p = detTime_p
        self.detTime_m = detTime_m
        # gives an output of observed or not observed depending on whether the detection time is less than or greater than the time bin (exposure length)
        if time_bin >= detTime[0]:
            detection = 'Observed'
        else:
            detection = 'Not Observed'
        if time_bin >= detTime_p[0]:
            detection_p = 'Observed'
        else:
            detection_p = 'Not Observed'
        if time_bin >= detTime_m[0]:
            detection_m = 'Observed'
        else:
            detection_m = 'Not Observed'
        self.detection = detection
        self.detection_p = detection_p
        self.detection_m = detection_m
コード例 #6
0
	def __init__(self, Burst = '130427A', redshift = 0.34, eblModel = 'Dominguez', instrument = 'VERITAS', zenith = 20):	

		self.redshift = redshift
		self.eblModel = eblModel
		self.instrument = instrument
		self.zenith = zenith
		

	# this finds the GRB file and reads it 
		GRB = 'GRBs/'+ Burst +'.csv'
		burst = asciitable.read(GRB, delimiter = ',')
	
	# this makes the arrays to which we will add values from the GRB table
		start_time = []
		stop_time = []
		Photon_index = []
		EF_erg = []
		EFM_erg = []
		Flux_erg = []
		One_GeV = []
		Four_GeV = []
		One_TeV = []
	# this takes the values found under start time, stop time, etc. and places them in the arrays we made before
		for x_1 in burst['start time']:
			start_time.append(x_1)
		for x_2 in burst['stop time']:
			stop_time.append(x_2)
		for y in burst['Energy flux (erg/cm2/s)']:
			Flux_erg.append(y)
		for y_1 in burst['Energy flux error']:
			EF_erg.append(y_1)
		for p in burst['Photon index']:
			Photon_index.append(p)
		
	# these make new arrays. One is the average time and the other is the time between the start time and the average
		time,time_err = zip(*[(((y-x)/2)+x,(y-x)/2) for x,y in zip(start_time, stop_time)])
	# this changes ergs to GeV
		Flux_GeV =  [624.150934 * x for x in Flux_erg]
		self.Flux_GeV = Flux_GeV
	 	detTimes =[]
 		dNdE_new = np.array([])
	 	int_flux = []
	 	crab_flux =[]
	 	self.crab_flux = crab_flux
		for i, v in zip(Flux_GeV, Photon_index):
			myVOT = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = self.zenith , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			
			# makes a boolean array (Trues and Falses) of all the energy bins depending on whether 100 GeV > E > 0.1 GeV
			mymask = (myVOT.VS.EBins > 200) 
			#print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
			#print mask
			
			# makes a new array of energies above 200 GeV
			E_new = [200] + myVOT.VS.EBins[mymask]
			# makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
			dNdE_new = [np.interp(200, myVOT.VS.EBins, myVOT.VS.dNdE)] + np.array(myVOT.VS.dNdE)[mymask] 
			# interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV 
			One_GeV.append(np.interp(1,myVOT.VS.EBins, myVOT.VS.dNdE))
			Four_GeV.append(np.interp(400,myVOT.VS.EBins, myVOT.VS.dNdE))
			One_TeV.append(np.interp(1000,myVOT.VS.EBins, myVOT.VS.dNdE))
			self.One_GeV = One_GeV
			self.Four_GeV = Four_GeV
			self.One_TeV = One_TeV
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			int_flux.append(np.trapz(dNdE_new, x = E_new))
			
			#checks how long detection takes
			
			crabFlux = 100*myVOT.rate*60./myVOT.VR.crabRate
			crab_flux.append(myVOT.VR.crabRate)
			detTime = np.interp([crabFlux*0.01], myVOT.VR.SensCurve[:,0], myVOT.VR.SensCurve[:,1])
			detTimes.append(detTime[0])
			self.detTimes = detTimes
		print detTimes
	
		
		Flux_GeV_error =  [624.150934 * x for x in EF_erg]
		EFP_GeV_error = [] 
		for x,y in zip(Flux_GeV_error,Flux_GeV):
			EFP_GeV_error.append(x+y) 
		Flux_error = np.array(Flux_GeV_error) - np.array(Flux_GeV)
		self.Flux_error = Flux_error
	 # this takes care of the flux error
 		dNdE_new_error = np.array([])
	 	int_flux_error = []
		for i, v in zip(EFP_GeV_error, Photon_index,):
			myVOT_error = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = self.zenith , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			
			# makes a boolean array (Trues and Falses) of all the energy bins depending on whether E > 200 GeV
			mymask = (myVOT_error.VS.EBins > 200)  
			#print np.shape(mymask),type(myVOT.VS.EBins),type(myVOT.VS.dNdE)
			#print mask
			
			# makes a new array of energies 100 GeV > E > 0.1 GeV
			E_new_error = [200] + myVOT_error.VS.EBins[mymask] 
			# makes a new differential flux with an interpolated value at 200 GeV and all values above (not interpolated)
			dNdE_new_error = [np.interp(200, myVOT.VS.EBins, myVOT_error.VS.dNdE)] + np.array(myVOT_error.VS.dNdE)[mymask] 
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			int_flux_error.append(np.trapz(dNdE_new_error, x = E_new))
		
			# 
		error = np.array(int_flux_error)-np.array(int_flux) 
		# assigns instances(attributes) to the take_data class so that it can be called in the notebook
		self.time = time
		self.int_flux = int_flux
		self.int_flux_error = int_flux_error
		self.error = error
		self.time_err = time_err
		self.E_new = E_new
		self.myVOT = myVOT
		
		
	
		#print int_flux	
		#fig2 = pyplot.figure(figsize=(16,8))
		#fig2ax1 = fig2.add_subplot(111)
		#fig2ax1.set_ylabel(r'Integral Flux [cm$^{-2}$ s$^{-1}$ GeV$^{-1}$]')
		#fig2ax1.set_xlabel('Time [s]')
		#fig2ax1.errorbar(time, int_flux, xerr=time_err, fmt='o')
		#fig2ax1.loglog(time, int_flux)
		#legend()
		#pyplot.show()
コード例 #7
0
	def __init__(self, Burst = '130427A', date = '2013/4/25 08:05:12', GC = [173.1370800,27.6990200], redshift = 0.34, eblModel = 'Dominguez', instrument = 'VERITAS2'):	
		
		#Although it is a bit unclear to me why, you have to put a self. before things so that the code can refer to that piece of code.
		self.redshift = redshift
		self.eblModel = eblModel
		self.instrument = instrument
		self.date = date
		self.GC = GC
		

	# this finds the GRB file and reads it there is another file I created that will take txt files and convert it to a more friendly csv file 
		GRB = 'GRBs/'+ Burst +'.csv'
		burst = asciitable.read(GRB, delimiter = ',')
	
	# this makes the arrays(tuple) to which we will add values from the GRB table
	
		
	
	
	# this imports the data from the csv files 
	# It looks specifically for certain header names. It's very picky so I suggest using the converter file I created.
	# Now, ideally, we have all the data we could possibly need from the csv files
		self.start_time = []
		for x_1 in burst['start time']:
			self.start_time.append(x_1)
		self.stop_time = []
		for x_2 in burst['stop time']:
			self.stop_time.append(x_2)
		self.PF = []
		for y in burst['photon flux']:
			self.PF.append(y)
		self.PF_err = []
		for y_1 in burst['photon flux err']:
			self.PF_err.append(y_1)
		self.PI = []
		for p in burst['Photon index']:
			self.PI.append(p)
		self.PI_err = []
		for p_1 in burst['Photon index error']:
			self.PI_err.append(p_1)
		self.Flux_erg = []
		for E_1 in burst['Energy flux (erg/cm2/s)']:
			self.Flux_erg.append(E_1)
		self.Flux_erg_error = []
		for E_e in burst['Energy flux error']:
			self.Flux_erg_error.append(E_e)
		
		
		
	 
	#photon index error calculator
		PIP, PIM = zip(*[(pi+pie, pi-pie) for pi, pie in zip(self.PI, self.PI_err)])
		self.PIP = PIP; self.PIM = PIM
		
	
	# these make new arrays. One is the center of each time bin and the other is the time between the center and edge of each time bin
		time,time_err = zip(*[(((y-x)/2)+x,(y-x)/2) for x,y in zip(self.start_time, self.stop_time)])
		self.time = time; self.time_err = time_err
	
	# So we have all these time bins and for loops but it would be nice, say if we wanted the differential flux for a single time bin, to call a specific time bin
	# well I was nice enough to do it for you
		time_bin = range(0, len(time), 1)
		self.time_bin = time_bin

	# This changes the Flux from the LAT from ergs to GeV 
		Flux_GeV =  [624.150934 * x for x in self.Flux_erg]; self.Flux_GeV = Flux_GeV
		
		Flux_GeV_error =  [624.150934 * x for x in self.Flux_erg_error]; self.Flux_GeV_error = Flux_GeV_error
	# The effective energy range for the LAT data spans from 0.1 GeV to 100 GeV 
		E2 =  100 # GeV
		E1 = 0.1 # GeV

	# This neat little formula saved me a bit of time. Rather than do the calculation and write a new csv file, this does the calculations for the Normalization values N0 here.
		self.Norm = []; self.Norm_P = []; self.Norm_M = []
		for F, F_err, I in zip(self.PF, self.PF_err, self.PI):
			self.Norm.append(((F/(E2-E1))*((E2**(1+I)-E1**(1+I))/(1+I)))); 
			self.Norm_P.append((((F+F_err)/(E2-E1))*((E2**(1+I)-E1**(1+I))/(1+I)))); 
			self.Norm_M.append((((F-F_err)/(E2-E1))*((E2**(1+I)-E1**(1+I))/(1+I)))); 
			
	# This section figures out the zenith angle based on the time of day that the burst went off as well as the positions of the burst and observatory.
		tel = VHEtelescope(instrument = self.instrument, time = time_bin, GC = self.GC, date = self.date)
		self.tel = tel
	# A dictionary so that we can refer to specific time bins later
	 	myVOT = {}; self.myVOT = myVOT
		self.One_GeV = []
		self.Four_GeV = []
		self.One_TeV = []
		self.int_flux = []
		self.detTimes = []
		self.crab_flux = []
		# the nominal calculation. No errors involved
		for tb, i, v, z in zip(time_bin, self.Norm, self.PI, tel.zenith):
			myVOT['{}'.format(tb)] = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = z , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			redshift = self.redshift
			
			
			# makes a boolean array (Trues and Falses) of all the energy bins True if E >  minimum safe Energy
			mymask = (myVOT['{}'.format(tb)].VS.EBins > 10**myVOT['{}'.format(tb)].VR.EASummary['minSafeE']) 
			#print np.shape(mymask),type(myVOT['{}'.format(tb)].VS.EBins),type(myVOT['{}'.format(tb)].VS.dNdE)
			#print mask
			
			# makes a new array of energies above 10**self.VR.EASummary['minSafeE'] GeV
			E_new = [10**myVOT['{}'.format(tb)].VR.EASummary['minSafeE']] + myVOT['{}'.format(tb)].VS.EBins[mymask]
			# makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
			dNdE_new = [np.interp(10**myVOT['{}'.format(tb)].VR.EASummary['minSafeE'], myVOT['{}'.format(tb)].VS.EBins, myVOT['{}'.format(tb)].VS.dNdE_absorbed)] + np.array(myVOT['{}'.format(tb)].VS.dNdE_absorbed)[mymask] 
			# interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV 
			self.One_GeV.append(np.interp(1,myVOT['{}'.format(tb)].VS.EBins, myVOT['{}'.format(tb)].VS.dNdE_absorbed))
			self.Four_GeV.append(np.interp(400,myVOT['{}'.format(tb)].VS.EBins, myVOT['{}'.format(tb)].VS.dNdE_absorbed))
			self.One_TeV.append(np.interp(1000,myVOT['{}'.format(tb)].VS.EBins, myVOT['{}'.format(tb)].VS.dNdE_absorbed))
			
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			self.int_flux.append(np.trapz(dNdE_new, x = E_new)) 
			
			#checks how long detection takes
			
			crabFlux = 100*myVOT['{}'.format(tb)].rate*60./myVOT['{}'.format(tb)].VR.crabRate
			self.crab_flux.append(myVOT['{}'.format(tb)].VR.crabRate)
			detTime = np.interp([crabFlux*0.01], myVOT['{}'.format(tb)].VR.SensCurve[:,0], myVOT['{}'.format(tb)].VR.SensCurve[:,1])*60
			self.detTimes.append((detTime[0]))
		# Only taking into account the difference in positive normalization values
		myVOT_PFP = {}; self.myVOT_PFP = myVOT_PFP
		
		'''
		Calculates the upper limit of the extrapolation based on the larger normalization value. 
		This is used to create the upper portion of the flux error bars. (i.e. N0 + error)
		'''
		self.int_flux_p = []
		self.detTimes_p = []
		self.One_GeV_P = []
		self.Four_GeV_P = []
		self.One_TeV_P = []
		self.crab_flux_p = []
		
		
		for tb, i, v, z in zip(time_bin, self.Norm_P, self.PI, tel.zenith):
			myVOT_PFP['{}'.format(tb)] = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = z , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			
			# makes a boolean array (Trues and Falses) of all the energies above the minimum safe energy range
			mymask_p = (myVOT_PFP['{}'.format(tb)].VS.EBins > 10**myVOT_PFP['{}'.format(tb)].VR.EASummary['minSafeE'])
		
			
			# Limits the energies to only those within the safe energy range
			E_new_p = [10**myVOT_PFP['{}'.format(tb)].VR.EASummary['minSafeE']] + myVOT_PFP['{}'.format(tb)].VS.EBins[mymask_p]
			
			# Limits the differential flux values (i.e. y axis )
			dNdE_new_p = [np.interp(10**myVOT_PFP['{}'.format(tb)].VR.EASummary['minSafeE'], myVOT_PFP['{}'.format(tb)].VS.EBins, myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed)] + np.array(myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed)[mymask_p]
			
			# Uses the interpolation function to determine the differential flux for energies 1 GeV, 400 GeV and 1 TeV 
			self.One_GeV_P.append(np.interp(1,myVOT_PFP['{}'.format(tb)].VS.EBins, myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed))
			self.Four_GeV_P.append(np.interp(400,myVOT_PFP['{}'.format(tb)].VS.EBins, myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed))
			self.One_TeV_P.append(np.interp(1000,myVOT_PFP['{}'.format(tb)].VS.EBins, myVOT_PFP['{}'.format(tb)].VS.dNdE_absorbed))
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			self.int_flux_p.append(np.trapz(dNdE_new_p, x = E_new_p))
			
			#checks how long detection takes
			
			crabFlux_p = 100*myVOT_PFP['{}'.format(tb)].rate*60./myVOT_PFP['{}'.format(tb)].VR.crabRate
			self.crab_flux_p.append(myVOT_PFP['{}'.format(tb)].VR.crabRate)
			detTime_P = np.interp([crabFlux_p*0.01], myVOT_PFP['{}'.format(tb)].VR.SensCurve[:,0], myVOT_PFP['{}'.format(tb)].VR.SensCurve[:,1])*60
			self.detTimes_p.append(detTime_P[0])
			
			myVOT_PFM = {}; self.myVOT_PFM = myVOT_PFM
			self.int_flux_m = []
			self.detTimes_m = []
			self.One_GeV_M = []
			self.Four_GeV_M = []
			self.One_TeV_M = []
			self. crab_flux_m = []
			# only taking into account the difference in negative normalization error
		for tb, i, v, z in zip(time_bin, self.Norm_M, self.PI, tel.zenith):
			myVOT_PFM['{}'.format(tb)] = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = z , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			
			# makes a boolean array (Trues and Falses) of all the energy bins depending on whether True if E > 10**self.VR.EASummary['minSafeE'] GeV
			mymask_m =  (myVOT_PFM['{}'.format(tb)].VS.EBins > 10**myVOT_PFM['{}'.format(tb)].VR.EASummary['minSafeE'])
			#print np.shape(mymask),type(myVOT['{}'.format(tb)].VS.EBins),type(myVOT['{}'.format(tb)].VS.dNdE)
			#print mask
			
			# makes a new array of energies above the minimum sensitivity
			E_new_m = [10**myVOT_PFM['{}'.format(tb)].VR.EASummary['minSafeE']] + myVOT_PFM['{}'.format(tb)].VS.EBins[mymask_m]
			# makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
			dNdE_new_m = [np.interp(10**myVOT_PFM['{}'.format(tb)].VR.EASummary['minSafeE'], myVOT_PFM['{}'.format(tb)].VS.EBins, myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed)] + np.array(myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed)[mymask_m]		
			# interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV 
			self.One_GeV_M.append(np.interp(1,myVOT_PFM['{}'.format(tb)].VS.EBins, myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed))
			self.Four_GeV_M.append(np.interp(400,myVOT_PFM['{}'.format(tb)].VS.EBins, myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed))
			self.One_TeV_M.append(np.interp(1000,myVOT_PFM['{}'.format(tb)].VS.EBins, myVOT_PFM['{}'.format(tb)].VS.dNdE_absorbed))
			
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			self.int_flux_m.append(np.trapz(dNdE_new_m, x = E_new_m))
			
			#checks how long detection takes
			
			crabFlux_m = 100*myVOT_PFM['{}'.format(tb)].rate*60./myVOT_PFM['{}'.format(tb)].VR.crabRate
			self.crab_flux_m.append(myVOT_PFM['{}'.format(tb)].VR.crabRate)
			detTime_m = np.interp([crabFlux_m*0.01], myVOT_PFM['{}'.format(tb)].VR.SensCurve[:,0], myVOT_PFM['{}'.format(tb)].VR.SensCurve[:,1])*60
			self.detTimes_m.append(detTime_m[0])
		
		self.perror = []
		for err, perr in zip(self.int_flux, self.int_flux_p):
			self.perror.append(perr - err)
		
		self.merror = []
		for err, merr in zip(self.int_flux, self.int_flux_m):
			self.merror.append(err-merr)
		
		
		'''
		Performs all calculations taking into account all possible sources of statistical error 
		(i.e. Normalization error and Photon Index error).
		'''
		myVOT_PIP = {}; self.myVOT_PIP = myVOT_PIP
		self.int_flux_pi = []
		self.detTimes_pi = []
		self.One_GeV_PI = []
		self.Four_GeV_PI = []
		self.One_TeV_PI = []
		self.crab_flux_pi = []
		#positive photon index error and positive normalization error
		for tb, i, v, z in zip(time_bin, self.Norm_P, self.PIP, tel.zenith):
			myVOT_PIP['{}'.format(tb)] = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = z , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			self.index_p = v
			# makes a boolean array (Trues and Falses) of all the energy bins True if E > 10**self.VR.EASummary['minSafeE'] GeV
			mymask_pi = (myVOT_PIP['{}'.format(tb)].VS.EBins > 10**myVOT_PIP['{}'.format(tb)].VR.EASummary['minSafeE'])
		
			
			# makes a new array of energies above 10**self.VR.EASummary['minSafeE'] GeV
			E_new_pi = [10**myVOT_PIP['{}'.format(tb)].VR.EASummary['minSafeE']] + myVOT_PIP['{}'.format(tb)].VS.EBins[mymask_pi]
			# makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
			dNdE_new_pi = [np.interp(10**myVOT_PIP['{}'.format(tb)].VR.EASummary['minSafeE'], myVOT_PIP['{}'.format(tb)].VS.EBins, myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed)] + np.array(myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed)[mymask_pi]
			# interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV 
			self.One_GeV_PI.append(np.interp(1,myVOT_PIP['{}'.format(tb)].VS.EBins, myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed))
			self.Four_GeV_PI.append(np.interp(400,myVOT_PIP['{}'.format(tb)].VS.EBins, myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed))
			self.One_TeV_PI.append(np.interp(1000,myVOT_PIP['{}'.format(tb)].VS.EBins, myVOT_PIP['{}'.format(tb)].VS.dNdE_absorbed))
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			self.int_flux_pi.append(np.trapz(dNdE_new_pi, x = E_new_pi))
			
			
			#checks how long detection takes
			crabFlux_pi = 100*myVOT_PIP['{}'.format(tb)].rate*60./myVOT_PIP['{}'.format(tb)].VR.crabRate
			self.crab_flux_pi.append(myVOT_PIP['{}'.format(tb)].VR.crabRate)
			detTime_PI = np.interp([crabFlux_pi*0.01], myVOT_PIP['{}'.format(tb)].VR.SensCurve[:,0], myVOT_PIP['{}'.format(tb)].VR.SensCurve[:,1])*60
			self.detTimes_pi.append(detTime_PI[0])
			
			
		myVOT_PIM = {}; self.myVOT_PIM = myVOT_PIM
		self.int_flux_mi = []
		self.detTimes_mi = []
		self.One_GeV_MI = []
		self.Four_GeV_MI = []
		self.One_TeV_MI = []
		self.crab_flux_mi = []
		# negative photon index error and normalization error
		for tb, i, v, z in zip(time_bin, self.Norm_M, self.PIM, tel.zenith):
			myVOT_PIM['{}'.format(tb)] = VOT("custom", eMin = 0.001, emax = 100000, Nbins= 100000, redshift = self.redshift, eblModel = self.eblModel, instrument = self.instrument,
				    zenith = z , spectralModel = 'PowerLaw', N0 = i, index = v, E0 = 1)
			self.index_m = v
			# makes a boolean array (Trues and Falses) of all the energy bins True if E > 10**self.VR.EASummary['minSafeE'] GeV
			mymask_mi =  (myVOT_PIM['{}'.format(tb)].VS.EBins > 10**myVOT_PIM['{}'.format(tb)].VR.EASummary['minSafeE'])
			#print np.shape(mymask),type(myVOT['{}'.format(tb)].VS.EBins),type(myVOT['{}'.format(tb)].VS.dNdE)
			#print mask
			
			# makes a new array of energies above 10**self.VR.EASummary['minSafeE'] GeV
			E_new_mi = [10**myVOT_PIM['{}'.format(tb)].VR.EASummary['minSafeE']] + myVOT_PIM['{}'.format(tb)].VS.EBins[mymask_m]
			# makes a new differential flux with an interpolated value at 10**self.VR.EASummary['minSafeE'] GeV and all values above (not interpolated)
			dNdE_new_mi = [np.interp(10**myVOT_PIM['{}'.format(tb)].VR.EASummary['minSafeE'], myVOT_PIM['{}'.format(tb)].VS.EBins, myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed)] + np.array(myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed)[mymask_mi]		
			# interpolates the differential flux at 1 GeV, 400 GeV and 1 TeV 
			self.One_GeV_MI.append(np.interp(1,myVOT_PIM['{}'.format(tb)].VS.EBins, myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed))
			self.Four_GeV_MI.append(np.interp(400,myVOT_PIM['{}'.format(tb)].VS.EBins, myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed)) 
			self.One_TeV_MI.append(np.interp(1000,myVOT_PIM['{}'.format(tb)].VS.EBins, myVOT_PIM['{}'.format(tb)].VS.dNdE_absorbed)) 
			
			# Integrates differential flux with respect to energy bins using the trapezoid rule
			self.int_flux_mi.append(np.trapz(dNdE_new_mi, x = E_new_mi))
			
			#checks how long detection takes
			
			crabFlux_mi = 100*myVOT_PIM['{}'.format(tb)].rate*60./myVOT_PIM['{}'.format(tb)].VR.crabRate
			self.crab_flux_mi.append(myVOT_PIM['{}'.format(tb)].VR.crabRate)
			detTime_MI = np.interp([crabFlux_mi*0.01], myVOT_PIM['{}'.format(tb)].VR.SensCurve[:,0], myVOT_PIM['{}'.format(tb)].VR.SensCurve[:,1])*60
			self.detTimes_mi.append(detTime_MI[0])
	
		
		# Lots and lots of error calculations
		One_GeV_M_error,Four_GeV_M_error, One_TeV_M_error = zip(*[((x-s),(y-t),(z-u)) for s,t,u,x,y,z in zip(self.One_GeV_M, self.Four_GeV_M, self.One_TeV_M, self.One_GeV, self.Four_GeV, self.One_TeV)])
		
		self.One_GeV_M_error = One_GeV_M_error; self.Four_GeV_M_error = Four_GeV_M_error; self.One_TeV_M_error = One_TeV_M_error
		
		One_GeV_P_error,Four_GeV_P_error, One_TeV_P_error = zip(*[((s-x),(t-y),(u-z)) for s,t,u,x,y,z in zip(self.One_GeV_M, self.Four_GeV_M, self.One_TeV_M, self.One_GeV, self.Four_GeV, self.One_TeV)])
		
		self.One_GeV_P_error = One_GeV_P_error; self.Four_GeV_P_error = Four_GeV_P_error; self.One_TeV_P_error = One_TeV_P_error