예제 #1
0
 def drawPointsToToroid(self):
     """
     Convert self.draw_points to a tuple of (lat, lon, radius)
     """
     (lat1, lon1) = self.draw_points[0]
     (lat2, lon2) = self.draw_points[1]
     radius = get_distance(lat1, lon1, lat2, lon2)
     return (lat1, lon1, radius)
예제 #2
0
 def filter_one_station(self, station):
     """
     Filter one station from the results
     """
     for lat, lon in self.event_locations:
         dist = get_distance(lat, lon, station.latitude, station.longitude)
         if self.distance_range['mindistance'] <= dist <= self.distance_range['maxdistance']:
             return True
     return False
예제 #3
0
    def iter_selected_events_stations(self):
        """
        Iterate through the selected event/station combinations.

        The main use case this method is meant to handle is where the user
        loaded stations based on selected events.

        For example, if the user selected multiple events and searched for stations
        within 20 degrees of any event, there may be stations that are within 20 degrees
        of one event but farther away from others -- we want to ensure that we only include
        the event/station combinations that are within 20 degrees of each other.
        """
        events = list(self.iter_selected_events())

        # Look for any event-based distance filter
        distance_range = self.station_options.get_event_distances()

        if distance_range:
            # Event locations by id
            event_locations = dict(self.iter_selected_event_locations())
        else:
            event_locations = {}

        # Iterate through the stations
        for (network, station, channel) in self.iter_selected_stations():
            for event in events:
                if distance_range:
                    event_location = event_locations.get(event.resource_id.id)
                    if event_location:
                        distance = get_distance(event_location[0],
                                                event_location[1],
                                                station.latitude,
                                                station.longitude)
                        LOGGER.debug("Distance from (%s, %s) to (%s, %s): %s",
                                     event_location[0], event_location[1],
                                     station.latitude, station.longitude,
                                     distance)
                        if distance < distance_range[
                                'mindistance'] or distance > distance_range[
                                    'maxdistance']:
                            continue
                # If we reach here, include this event/station pair
                yield (event, network, station, channel)
예제 #4
0
    def iter_selected_events_stations(self):
        """
        Iterate through the selected event/station combinations.

        The main use case this method is meant to handle is where the user
        loaded stations based on selected events.

        For example, if the user selected multiple events and searched for stations
        within 20 degrees of any event, there may be stations that are within 20 degrees
        of one event but farther away from others -- we want to ensure that we only include
        the event/station combinations that are within 20 degrees of each other.
        """
        events = list(self.iter_selected_events())

        # Look for any event-based distance filter
        distance_range = self.station_options.get_event_distances()

        if distance_range:
            # Event locations by id
            event_locations = dict(self.iter_selected_event_locations())
        else:
            event_locations = {}

        # Iterate through the stations
        for (network, station, channel) in self.iter_selected_stations():
            for event in events:
                if distance_range:
                    event_location = event_locations.get(event.resource_id.id)
                    if event_location:
                        distance = get_distance(
                            event_location[0], event_location[1],
                            station.latitude, station.longitude)
                        LOGGER.debug(
                            "Distance from (%s, %s) to (%s, %s): %s",
                            event_location[0], event_location[1],
                            station.latitude, station.longitude,
                            distance
                        )
                        if distance < distance_range['mindistance'] or distance > distance_range['maxdistance']:
                            continue
                # If we reach here, include this event/station pair
                yield (event, network, station, channel)
예제 #5
0
    def __init__(self, event, network, station, channel, *args, **kwargs):
        super(WaveformEntry, self).__init__(*args, **kwargs)

        self.event_ref = weakref.ref(event)
        self.network_ref = weakref.ref(network)
        self.station_ref = weakref.ref(station)
        self.channel_ref = weakref.ref(channel)

        self.sncl = get_sncl(network, station, channel)

        self.event_description = get_event_description(event)
        origin = get_preferred_origin(event)
        self.event_time = origin.time
        self.event_time_str = format_time_str(origin.time)
        self.event_depth = origin.depth / 1000
        mag = get_preferred_magnitude(event)
        self.event_mag = "%s%s" % (mag.mag, mag.magnitude_type)
        self.event_mag_value = mag.mag
        self.waveform_id = '%s_%s' % (self.sncl, get_event_id(event))

        self.distance = get_distance(origin.latitude, origin.longitude,
                                     station.latitude, station.longitude)
예제 #6
0
    def __init__(self, event, network, station, channel, *args, **kwargs):
        super(WaveformEntry, self).__init__(*args, **kwargs)

        self.event_ref = weakref.ref(event)
        self.network_ref = weakref.ref(network)
        self.station_ref = weakref.ref(station)
        self.channel_ref = weakref.ref(channel)

        self.sncl = get_sncl(network, station, channel)

        self.event_description = get_event_description(event)
        origin = get_preferred_origin(event)
        self.event_time = origin.time
        self.event_time_str = format_time_str(origin.time)
        self.event_depth = origin.depth / 1000
        mag = get_preferred_magnitude(event)
        self.event_mag = "%s%s" % (mag.mag, mag.magnitude_type)
        self.event_mag_value = mag.mag
        self.waveform_id = '%s_%s' % (self.sncl, get_event_id(event))

        self.distance = get_distance(
            origin.latitude, origin.longitude,
            station.latitude, station.longitude)
예제 #7
0
 def test_distance_3(self):
     dist = get_distance(0, 170, 0, -170)
     self.assertAlmostEqual(dist, 20, delta=1)
예제 #8
0
 def test_distance_2(self):
     dist = get_distance(0, 0, 0, 10)
     self.assertAlmostEqual(dist, 10, delta=1)
예제 #9
0
파일: tests.py 프로젝트: wbm06/pyweed
 def test_distance_3(self):
     dist = get_distance(0, 170, 0, -170)
     self.assertAlmostEqual(dist, 20, delta=1)
예제 #10
0
파일: tests.py 프로젝트: wbm06/pyweed
 def test_distance_2(self):
     dist = get_distance(0, 0, 0, 10)
     self.assertAlmostEqual(dist, 10, delta=1)