Пример #1
0
def test_unix_conversion(input_date, expected):

    assert AstroUtils.time_agile_seconds_to_iso(input_date) == expected["iso"]
    assert AstroUtils.time_agile_seconds_to_jd(input_date) == pytest.approx(
        expected["jd"], 0.00001)
    assert AstroUtils.time_agile_seconds_to_mjd(input_date) == pytest.approx(
        expected["mjd"], 0.00001)
    assert AstroUtils.time_agile_seconds_to_unix(
        input_date) == expected["unix"]
    assert AstroUtils.time_agile_seconds_to_fits(
        input_date) == expected["fits"]
Пример #2
0
    def plot(self, ax, agile_data, fermi_data, arg_lines, plotrate):
        """It plots aperture photometry data
        """

        #---AGILE----

        tm = (AstroUtils.time_agile_seconds_to_mjd(agile_data["tstart"]) + AstroUtils.time_agile_seconds_to_mjd(agile_data["tstop"])) / 2
        #agile_data.loc[agile_data['cts'] == 0, 'rateError'] = 0
        #yerr = agile_data["rateError"]*1e8
        if plotrate:
            yerr = agile_data["rateError"]*1e8
            #print(agile_data["tstart"], agile_data["tstop"], agile_data["cts"], agile_data["exp"], agile_data["rate"]*1e8, agile_data["rateError"]*1e8)
            tw = tm -  AstroUtils.time_agile_seconds_to_mjd(agile_data["tstart"])
            ax.errorbar(tm, agile_data["rate"]*1e8, color="b", label="AGILE", fmt='.', yerr=yerr, xerr=tw, linewidth=0.8)

            self.logger.info(self, f"AGILE mean {agile_data['rate'].mean()*1e8}")
            self.logger.info(f"AGILE median {agile_data['rate'].median()*1e8}")
            self.logger.info(self, f"AGILE std {agile_data['rate'].std()*1e8}")

            agilemean = agile_data["rate"].median()*1e8
            agilestd = agile_data["rate"].std()*1e8
        else:
            yerr = agile_data["rateError"]*agile_data["exp"]
            #print(agile_data["tstart"], agile_data["tstop"], agile_data["cts"], agile_data["exp"], agile_data["rate"]*1e8, agile_data["rateError"]*1e8)
            tw = tm -  AstroUtils.time_agile_seconds_to_mjd(agile_data["tstart"])
            ax.errorbar(tm, agile_data["cts"], color="b", label="AGILE", fmt='.', yerr=yerr, xerr=tw, linewidth=0.8)

            self.logger.info(self, f"AGILE mean, {agile_data['cts'].mean()}")
            self.logger.info(self, f"AGILE median {agile_data['cts'].median()}")
            self.logger.info(self, f"AGILE std {agile_data['cts'].std()}")

            agilemean = agile_data["cts"].median()
            agilestd = agile_data["cts"].std()

        ax.axhline(agilemean, linestyle='solid', color='b', linewidth=0.5)
        ax.axhline(agilemean + 1 * agilestd, linestyle='dotted', color='b', linewidth=0.5)
        ax.axhline(agilemean + 2 * agilestd, linestyle='dashed', color='b', linewidth=0.5)
        ax.axhline(agilemean + 3 * agilestd, linestyle='dashdot', color='b', linewidth=1)

        #---Fermi----

        tmFermi = (AstroUtils.time_agile_seconds_to_mjd(fermi_data["tstart"]) + AstroUtils.time_tt_to_mjd(fermi_data["tstop"])) / 2
        #fermi_data.loc[fermi_data['cts'] == 0, 'rateError'] = 0
        if plotrate:
            fermi_data.loc[fermi_data['rateError'] > 1000e-08, 'rateError'] = 0
            #fermi_data.loc[fermi_data['rateError'] > 1000e-08, 'rate'] = 0
            fermi_data.loc[fermi_data['rate'] > 10000e-08, 'rate'] = 0
            yerrFermi = fermi_data["rateError"]*1e8
            #print(fermi_data["tstart"], fermi_data["tstop"], fermi_data["rateError"], fermi_data["rate"])
            twFermi = tmFermi -  AstroUtils.time_agile_seconds_to_mjd(fermi_data["tstart"])
            #ax.errorbar(fermi_data["Time_MJD"], fermi_data["count_rate_(cts/s)"]*1e8, color="r", label="FERMI", fmt="none", xerr=[fermi_data["Time_MJD"] - tstart,tstop - fermi_data["Time_MJD"]], yerr=fermi_yerr)
            ax.errorbar(tmFermi, fermi_data["rate"]*1e8, color="r", label="FERMI", fmt="none", yerr=yerrFermi, xerr=twFermi, linewidth=0.8)

            self.logger.info(self, f"Fermi mean {fermi_data['rate'].mean()*1e8}")
            self.logger.info(self, f"Fermi median {fermi_data['rate'].median()*1e8}")
            self.logger.info(self, f"Fermi std {fermi_data['rate'].std()*1e8}")

            fermimean = fermi_data["rate"].median()*1e8
            fermistd = fermi_data["rate"].std()*1e8
        else:
            #fermi_data.loc[fermi_data['rateError'] > 1000e-08, 'rateError'] = 0
            #fermi_data.loc[fermi_data['rateError'] > 1000e-08, 'rate'] = 0
            yerrFermi = fermi_data["rateError"]*fermi_data["exp"]
            #print(fermi_data["tstart"], fermi_data["tstop"], fermi_data["rateError"], fermi_data["rate"])
            twFermi = tmFermi -  AstroUtils.time_agile_seconds_to_mjd(fermi_data["tstart"])
            #ax.errorbar(fermi_data["Time_MJD"], fermi_data["count_rate_(cts/s)"]*1e8, color="r", label="FERMI", fmt="none", xerr=[fermi_data["Time_MJD"] - tstart,tstop - fermi_data["Time_MJD"]], yerr=fermi_yerr)
            ax.errorbar(tmFermi, fermi_data["cts"], color="r", label="FERMI", fmt="none", yerr=yerrFermi, xerr=twFermi, linewidth=0.8)

            self.logger.info(self, f"Fermi mean {fermi_data['cts'].mean()}")
            self.logger.info(self, f"Fermi median {fermi_data['cts'].median()}")
            self.logger.info(self, f"Fermi std' {fermi_data['cts'].std()}")

            fermimean = fermi_data["cts"].mean()
            fermistd = fermi_data["cts"].std()

        ax.axhline(fermimean, linestyle='solid', color='r', linewidth=0.5)
        ax.axhline(fermimean + 1 * fermistd, linestyle='dotted', color='r', linewidth=0.5)
        ax.axhline(fermimean + 2 * fermistd, linestyle='dashed', color='r', linewidth=0.5)
        ax.axhline(fermimean + 3 * fermistd, linestyle='dashdot', color='r', linewidth=1)

        time_diff = fermi_data["tstop"] - fermi_data["tstart"]
        self.logger.info(self, f"Total time in GTI(bottom plot) {time_diff.sum()}")
            



        ax.ticklabel_format(axis="x", useOffset=False)
        if plotrate:
            ax.set_ylabel('Photon counts')
        else:
            ax.set_ylabel('Rate') 
        ax.set_xlabel("MJD")
        ax.legend(loc='upper right', shadow=True, fontsize='xx-small')
Пример #3
0
 def test_astro_utils_time_agile_seconds_to_mjd(self):
     sec_tolerance = 0.0000001
     mjd = AstroUtils.time_agile_seconds_to_mjd(507391426.9447)
     assert abs(58877.58595999 - mjd) <= sec_tolerance