Exemplo n.º 1
0
 def clock_corrections(self, t):
     corr = np.zeros(t.shape) * u.s
     if self.include_gps:
         log.info("Applying GPS to UTC clock correction (~few nanoseconds)")
         if self._gps_clock is None:
             log.info("Observatory {0}, loading GPS clock file {1}".format(
                 self.name, self.gps_fullpath))
             self._gps_clock = ClockFile.read(self.gps_fullpath,
                                              format="tempo2")
         corr += self._gps_clock.evaluate(t)
     if self.include_bipm:
         log.info("Applying TT(TAI) to TT(BIPM) clock correction (~27 us)")
         tt2tai = 32.184 * 1e6 * u.us
         if self._bipm_clock is None:
             try:
                 log.info(
                     "Observatory {0}, loading BIPM clock file {1}".format(
                         self.name, self.bipm_fullpath))
                 self._bipm_clock = ClockFile.read(self.bipm_fullpath,
                                                   format="tempo2")
             except:
                 raise ValueError("Can not find TT BIPM file '%s'. " %
                                  self.bipm_version)
         corr += self._bipm_clock.evaluate(t) - tt2tai
     return corr
Exemplo n.º 2
0
    def clock_corrections(self, t):
        """Compute the total clock corrections,

        Parameters
        ----------
        t : astropy.time.Time
            The time when the clock correcions are applied.
        """
        # Read clock file if necessary
        # TODO provide some method for re-reading the clock file?
        if self._clock is None:
            clock_files = (self.clock_fullpath if self._multiple_clock_files
                           else [self.clock_fullpath])
            self._clock = []
            for clock_file in clock_files:
                log.info("Observatory {0}, loading clock file \n\t{1}".format(
                    self.name, clock_file))
                self._clock.append(
                    ClockFile.read(clock_file,
                                   format=self.clock_fmt,
                                   obscode=self.tempo_code))
        log.info("Applying observatory clock corrections.")
        corr = self._clock[0].evaluate(t)
        for clock in self._clock[1:]:
            corr += clock.evaluate(t)

        if self.include_gps:
            log.info("Applying GPS to UTC clock correction (~few nanoseconds)")
            if self._gps_clock is None:
                log.info(
                    "Observatory {0}, loading GPS clock file \n\t{1}".format(
                        self.name, self.gps_fullpath))
                self._gps_clock = ClockFile.read(self.gps_fullpath,
                                                 format="tempo2")
            corr += self._gps_clock.evaluate(t)

        if self.include_bipm:
            log.info(
                f"Applying TT(TAI) to TT({self.bipm_version}) clock correction (~27 us)"
            )
            tt2tai = 32.184 * 1e6 * u.us
            if self._bipm_clock is None:
                try:
                    log.info(
                        "Observatory {0}, loading BIPM clock file \n\t{1}".
                        format(self.name, self.bipm_fullpath))
                    self._bipm_clock = ClockFile.read(self.bipm_fullpath,
                                                      format="tempo2")
                except Exception as e:
                    raise ValueError(
                        f"Can not find TT BIPM file for version '{self.bipm_version}'."
                    ) from e
            corr += self._bipm_clock.evaluate(t) - tt2tai
        return corr
Exemplo n.º 3
0
    def test_wsrt(self):
        # Issue here is the wsrt clock file has text columns, which used to cause np.loadtxt to crash
        cf = ClockFile.read(
            path.join(datadir, "wsrt2gps.clk"), format="tempo2", obscode="i"
        )

        t = Time(57109.5, scale="utc", format="mjd")
        e = cf.evaluate(t)
        assert numpy.isclose(e.to(u.us).value, 7.907)
Exemplo n.º 4
0
    def test_Parkes(self):
        obs = Observatory.get('Parkes')
        cf = ClockFile.read(obs.clock_fullpath, format=obs.clock_fmt,
                obscode=obs.tempo_code)
        mjd = cf.time.mjd
        corr = cf.clock.to(u.us).value

        assert numpy.isclose(mjd.min(), 44000.0)

        idx = numpy.where(numpy.isclose(mjd,49990.0))[0][0]
        assert numpy.isclose(corr[idx],-2.506)

        idx = numpy.where(numpy.isclose(mjd,55418.27))[0][0]
        assert numpy.isclose(corr[idx],-0.586)
Exemplo n.º 5
0
    def test_Parkes(self):
        obs = Observatory.get('Parkes')
        cf = ClockFile.read(obs.clock_fullpath, format=obs.clock_fmt,
                obscode=obs.tempo_code)
        mjd = cf.time.mjd
        corr = cf.clock.to(u.us).value
        
        assert numpy.isclose(mjd.min(), 44000.0)

        idx = numpy.where(numpy.isclose(mjd,49990.0))[0][0]
        assert numpy.isclose(corr[idx],-2.506)

        idx = numpy.where(numpy.isclose(mjd,55418.27))[0][0]
        assert numpy.isclose(corr[idx],-0.586)
Exemplo n.º 6
0
    def test_parkes(self):
        obs = Observatory.get("Parkes")
        if os.getenv("TEMPO2") is None:
            pytest.skip(
                "TEMPO2 evnironment variable is not set, can't run this test")
        cf = ClockFile.read(obs.clock_fullpath,
                            format=obs.clock_fmt,
                            obscode=obs.tempo_code)

        t = Time(51211.73, format="pulsar_mjd", scale="utc")
        assert numpy.isclose(cf.evaluate(t), 1.75358956 * u.us)

        t = Time(55418.11285, format="pulsar_mjd", scale="utc")
        assert numpy.isclose(cf.evaluate(t), -0.593622 * u.us)
Exemplo n.º 7
0
    def test_wsrt(self):
        # Issue here is the wsrt clock file has text columns, which used to cause np.loadtxt to crash
        cf = ClockFile.read(
            path.join(datadir, "wsrt2gps.clk"), format="tempo2", obscode="i"
        )

        t = Time(57109.5, scale="utc", format="mjd")
        e = cf.evaluate(t)
        assert numpy.isclose(e.to(u.us).value, 7.907)

        # Test that an error is raised when time is outside of clock file range.
        # Normally it just prints a warning, but I'm not sure how to test for that, so I set limits="error"
        with pytest.raises(RuntimeError):
            t = cf.time[-1] + 1.0 * u.d
            cf.evaluate(t, limits="error")
Exemplo n.º 8
0
    def test_parkes(self):
        obs = Observatory.get("Parkes")
        if os.getenv("TEMPO2") is None:
            pytest.skip("TEMPO2 environment variable is not set, can't run this test")
        cf = ClockFile.read(
            obs.clock_fullpath, format=obs.clock_fmt, obscode=obs.tempo_code
        )

        t = Time(51211.73, format="pulsar_mjd", scale="utc")
        assert numpy.isclose(cf.evaluate(t).to(u.us).value, 1.75358956)

        t = Time(55418.11285, format="pulsar_mjd", scale="utc")
        assert numpy.isclose(cf.evaluate(t).to(u.us).value, -0.593622)

        # Test that an error is raised when time is outside of clock file range.
        # Normally it just prints a warning, but I'm not sure how to test for that, so I set limits="error"
        with pytest.raises(RuntimeError):
            t = cf.time[-1] + 1.0 * u.d
            cf.evaluate(t, limits="error")