Package gov.usgs.earthquake.indexer
Class DefaultAssociator
java.lang.Object
gov.usgs.earthquake.indexer.DefaultAssociator
- All Implemented Interfaces:
Associator
Utilities for associating events.
Based on the QDM EQEventsUtils class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BigDecimal
Number of kilometers in a degree at the equator.static final BigDecimal
Distance between related events latitude, in degrees.static final BigDecimal
Distance between related events in space, in kilometers.static final long
Distance between related events in time, in milliseconds. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchooseEvent
(List<Event> events, ProductSummary summary) Choose and return the most closely associated event.protected Event
chooseMostSimilar
(ProductSummary summary, List<Event> events) For the given list of events, find the one that is "closest" to the given product.boolean
eventsAssociated
(Event event1, Event event2) Check if two events are associated to each other.getEventIdQuery
(String eventSource, String eventCode) Build a ProductIndexQuery that searches based on event id.getLocationQuery
(Date time, BigDecimal latitude, BigDecimal longitude) Build a ProductIndexQuery that searches based on location.getSearchRequest
(ProductSummary summary) Build an index search that searches for associated products.protected boolean
queryContainsLocation
(ProductIndexQuery query, Date time, BigDecimal latitude, BigDecimal longitude) Check if a location would be matched by a ProductIndexQuery.
-
Field Details
-
TIME_DIFF_MILLISECONDS
public static final long TIME_DIFF_MILLISECONDSDistance between related events in time, in milliseconds.- See Also:
-
LOCATION_DIFF_KILOMETER
Distance between related events in space, in kilometers. -
KILOMETERS_PER_DEGREE
Number of kilometers in a degree at the equator. -
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
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 interfaceAssociator
- Parameters:
summary
- the product summary being associated.- Returns:
- a SearchRequest that can be used to search the ProductIndex.
-
chooseEvent
Choose and return the most closely associated event.- Specified by:
chooseEvent
in interfaceAssociator
- Parameters:
events
- a list of candidate events.summary
- the summary being associated.- Returns:
- the best match event from the list of events.
-
chooseMostSimilar
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 withevents
- List of events- Returns:
- Event with lowest distance
-
eventsAssociated
Check if two events are associated to each other. Reasons events may be considered disassociated:- Share a common EVENTSOURCE with different EVENTSOURCECODE.
- Either has a disassociate product for the other.
- Preferred location in space and time is NOT nearby, and no other reason to associate.
- Share a common EVENTID
- Either has an associate product for the other.
- Their preferred location in space and time is nearby.
- Specified by:
eventsAssociated
in interfaceAssociator
- Parameters:
event1
- candidate event to test.event2
- candidate event to test.- Returns:
- true if associated, false otherwise.
-
getEventIdQuery
Build a ProductIndexQuery that searches based on event id.- Specified by:
getEventIdQuery
in interfaceAssociator
- Parameters:
eventSource
- the eventSource to searcheventCode
- 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
Build a ProductIndexQuery that searches based on location.- Specified by:
getLocationQuery
in interfaceAssociator
- 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 querytime
- time to checklatitude
- latitude to checklongitude
- 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.
-