Class DefaultAssociator

java.lang.Object
gov.usgs.earthquake.indexer.DefaultAssociator
All Implemented Interfaces:
Associator

public class DefaultAssociator extends Object implements Associator
Utilities for associating events. Based on the QDM EQEventsUtils class.
  • Field Details

    • TIME_DIFF_MILLISECONDS

      public static final long TIME_DIFF_MILLISECONDS
      Distance between related events in time, in milliseconds.
      See Also:
    • LOCATION_DIFF_KILOMETER

      public static final BigDecimal LOCATION_DIFF_KILOMETER
      Distance between related events in space, in kilometers.
    • KILOMETERS_PER_DEGREE

      public static final BigDecimal KILOMETERS_PER_DEGREE
      Number of kilometers in a degree at the equator.
    • LOCATION_DIFF_DEGREES

      public static final BigDecimal LOCATION_DIFF_DEGREES
      Distance between related events latitude, in degrees. This is based on the max number of kilometers per degree, and provides the maximum latitude separation (assuming events share a longitude). Used as a pre-filter before more expensive checks.
  • Constructor Details

    • DefaultAssociator

      public DefaultAssociator()
  • Method Details

    • getSearchRequest

      public SearchRequest getSearchRequest(ProductSummary summary)
      Build an index search that searches for associated products. Products are considered associated if the eventid matches or their location is within a certain distance.
      Specified by:
      getSearchRequest in interface Associator
      Parameters:
      summary - the product summary being associated.
      Returns:
      a SearchRequest that can be used to search the ProductIndex.
    • chooseEvent

      public Event chooseEvent(List<Event> events, ProductSummary summary)
      Choose and return the most closely associated event.
      Specified by:
      chooseEvent in interface Associator
      Parameters:
      events - a list of candidate events.
      summary - the summary being associated.
      Returns:
      the best match event from the list of events.
    • chooseMostSimilar

      protected Event chooseMostSimilar(ProductSummary summary, List<Event> events)
      For the given list of events, find the one that is "closest" to the given product. Similarity is calculated by first subtracting the event parameter from the product parameter, normalizing between 1 and -1, then calculating the Euclidean distance in the 3D space composed of the normalized lat, lon, and time vectors.
      Parameters:
      summary - ProductSummary to compare events with
      events - List of events
      Returns:
      Event with lowest distance
    • eventsAssociated

      public boolean eventsAssociated(Event event1, Event event2)
      Check if two events are associated to each other. Reasons events may be considered disassociated:
      1. Share a common EVENTSOURCE with different EVENTSOURCECODE.
      2. Either has a disassociate product for the other.
      3. Preferred location in space and time is NOT nearby, and no other reason to associate.
      Reasons events may be considered associated:
      1. Share a common EVENTID
      2. Either has an associate product for the other.
      3. Their preferred location in space and time is nearby.
      Specified by:
      eventsAssociated in interface Associator
      Parameters:
      event1 - candidate event to test.
      event2 - candidate event to test.
      Returns:
      true if associated, false otherwise.
    • getEventIdQuery

      public ProductIndexQuery getEventIdQuery(String eventSource, String eventCode)
      Build a ProductIndexQuery that searches based on event id.
      Specified by:
      getEventIdQuery in interface Associator
      Parameters:
      eventSource - the eventSource to search
      eventCode - the eventCode to search
      Returns:
      null if eventSource or eventCode are null, otherwise a ProductIndexQuery. A returned ProductIndexQuery will have EventSearchType SEARCH_EVENT_PREFERRED and ResultType RESULT_TYPE_ALL.
    • getLocationQuery

      public ProductIndexQuery getLocationQuery(Date time, BigDecimal latitude, BigDecimal longitude)
      Build a ProductIndexQuery that searches based on location.
      Specified by:
      getLocationQuery in interface Associator
      Parameters:
      time - the time to search around.
      latitude - the latitude to search around.
      longitude - the longitude to search around.
      Returns:
      null if time, latitude, or longitude are null, otherwise a ProductIndexQuery. A returned ProductIndexQuery will have EventSearchType SEARCH_EVENT_PREFERRED and ResultType RESULT_TYPE_ALL.
    • queryContainsLocation

      protected boolean queryContainsLocation(ProductIndexQuery query, Date time, BigDecimal latitude, BigDecimal longitude)
      Check if a location would be matched by a ProductIndexQuery.
      Parameters:
      query - location query
      time - time to check
      latitude - latitude to check
      longitude - longitude to check
      Returns:
      false if query, time, latitude, or longitude are null, or if min/max time, latitude, longitude are set and do not match time, latitude, or longitude. otherwise, true.