Esempio n. 1
0
def update_station_timing_offsets(network_summary):
    """Determine which station timing offsets need updating and update"""

    logger.debug("Determining update of station offsets "
                 "for %s" % network_summary)
    summary_date = network_summary.date

    stations = esd.get_station_numbers_from_esd_coincidences(network_summary)
    network_off = esd.DetermineStationTimingOffsetsESD(stations)

    for ref_sn, sn in network_off.get_station_pairs_within_max_distance():
        off = esd.DetermineStationTimingOffsetsESD([ref_sn, sn])
        cuts = off._get_cuts(sn, ref_sn)
        left, right = off.determine_first_and_last_date(summary_date,
                                                        sn, ref_sn)
        # To only update offset for specific date use:
        # for date in [summary_date]:
        for date, _ in datetime_range(left, right):
            ref_summary = get_summary_or_none(date, ref_sn)
            if ref_summary is None:
                continue
            summary = get_summary_or_none(date, sn)
            if summary is None:
                continue
            if date in cuts:
                logger.debug("Setting offset for config cut to nan for %s"
                             " ref %s at %s" % (summary, ref_summary, date))
                offset, error = np.nan, np.nan
            else:
                logger.debug("Determining station offset for %s"
                             " ref %s at %s" % (summary, ref_summary, date))
                offset, error = off.determine_station_timing_offset(date, sn,
                                                                    ref_sn)
            save_station_offset(ref_summary, summary, offset, error)
Esempio n. 2
0
def update_station_timing_offsets(network_summary):
    """Determine which station timing offsets need updating and update"""

    logger.debug("Determining update of station offsets "
                 "for %s" % network_summary)
    summary_date = network_summary.date

    stations = esd.get_station_numbers_from_esd_coincidences(network_summary)
    network_off = esd.DetermineStationTimingOffsetsESD(stations)

    for ref_sn, sn in network_off.get_station_pairs_within_max_distance():
        off = esd.DetermineStationTimingOffsetsESD([ref_sn, sn])
        cuts = off._get_cuts(sn, ref_sn)
        left, right = off.determine_first_and_last_date(summary_date,
                                                        sn, ref_sn)
        # To only update offset for specific date use:
        # for date in [summary_date]:
        for date, _ in datetime_range(left, right):
            ref_summary = get_summary_or_none(date, ref_sn)
            if ref_summary is None:
                continue
            summary = get_summary_or_none(date, sn)
            if summary is None:
                continue
            if date in cuts:
                logger.debug("Setting offset for config cut to nan for %s"
                             " ref %s at %s" % (summary, ref_summary, date))
                offset, error = np.nan, np.nan
            else:
                logger.debug("Determining station offset for %s"
                             " ref %s at %s" % (summary, ref_summary, date))
                offset, error = off.determine_station_timing_offset(date, sn,
                                                                    ref_sn)
            save_station_offset(ref_summary, summary, offset, error)
Esempio n. 3
0
    def read_dt(self, station, ref_station, start, end):
        """Overwrite how time deltas are read"""

        dt = []
        for date, _ in datetime_range(start, end):
            data = get_timedeltas(date, ref_station, station)
            if data is not None:
                dt.extend(data)
        return dt
Esempio n. 4
0
    def read_dt(self, station, ref_station, start, end):
        """Overwrite how time deltas are read"""

        dt = []
        for date, _ in datetime_range(start, end):
            data = get_timedeltas(date, ref_station, station)
            if data is not None:
                dt.extend(data)
        return dt
Esempio n. 5
0
    def test_split_range(self):
        # 101 days
        start = date(2016, 1, 1)
        end_5days = date(2016, 1, 6)
        end_100days = date(2016, 4, 11)

        # no step, dates:
        result = list(calibration.datetime_range(start, end_5days))
        self.assertEqual(len(result), 5)
        begin, _ = result[0]
        _, end = result[-1]
        self.assertEqual(begin, start)
        self.assertEqual(end, end_5days)

        # single interval
        result = list(calibration.datetime_range(start, end_5days, 5))
        self.assertEqual(len(result), 1)
        begin, end = result[0]
        self.assertEqual(begin, start)
        self.assertEqual(end, end_5days)

        # split an even interval in two parts
        result = list(calibration.datetime_range(start, end_5days, 2))
        self.assertEqual(len(result), 2)
        begin, _ = result[0]
        _, end = result[-1]
        self.assertEqual(begin, start)
        self.assertEqual(end, end_5days)

        # split large interval, remainder = 0
        result = list(calibration.datetime_range(start, end_100days, 10))
        self.assertEqual(len(result), 10)
        begin, _ = result[0]
        _, end = result[-1]
        self.assertEqual(begin, start)
        self.assertEqual(end, end_100days)

        # split large interval, divide remainder
        result = list(calibration.datetime_range(start, end_100days, 7))
        self.assertEqual(len(result), 14)
        begin, _ = result[0]
        _, end = result[-1]
        self.assertEqual(begin, start)
        self.assertEqual(end, end_100days)

        # number of steps == 0
        result = list(calibration.datetime_range(start, start, 1))
        self.assertEqual(len(result), 1)
        self.assertEqual(result, [(start, start)])