Package gov.usgs.earthquake.indexer
Class DefaultAssociator
- java.lang.Object
-
- gov.usgs.earthquake.indexer.DefaultAssociator
-
- All Implemented Interfaces:
Associator
public class DefaultAssociator extends java.lang.Object implements Associator
Utilities for associating events. Based on the QDM EQEventsUtils class.
-
-
Field Summary
Fields Modifier and Type Field Description static java.math.BigDecimal
KILOMETERS_PER_DEGREE
Number of kilometers in a degree at the equator.static java.math.BigDecimal
LOCATION_DIFF_DEGREES
Distance between related events latitude, in degrees.static java.math.BigDecimal
LOCATION_DIFF_KILOMETER
Distance between related events in space, in kilometers.static long
TIME_DIFF_MILLISECONDS
Distance between related events in time, in milliseconds.
-
Constructor Summary
Constructors Constructor Description DefaultAssociator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Event
chooseEvent(java.util.List<Event> events, ProductSummary summary)
Choose and return the most closely associated event.protected Event
chooseMostSimilar(ProductSummary summary, java.util.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.ProductIndexQuery
getEventIdQuery(java.lang.String eventSource, java.lang.String eventCode)
Build a ProductIndexQuery that searches based on event id.ProductIndexQuery
getLocationQuery(java.util.Date time, java.math.BigDecimal latitude, java.math.BigDecimal longitude)
Build a ProductIndexQuery that searches based on location.SearchRequest
getSearchRequest(ProductSummary summary)
Build an index search that searches for associated products.protected boolean
queryContainsLocation(ProductIndexQuery query, java.util.Date time, java.math.BigDecimal latitude, java.math.BigDecimal longitude)
Check if a location would be matched by a ProductIndexQuery.
-
-
-
Field Detail
-
TIME_DIFF_MILLISECONDS
public static final long TIME_DIFF_MILLISECONDS
Distance between related events in time, in milliseconds.- See Also:
- Constant Field Values
-
LOCATION_DIFF_KILOMETER
public static final java.math.BigDecimal LOCATION_DIFF_KILOMETER
Distance between related events in space, in kilometers.
-
KILOMETERS_PER_DEGREE
public static final java.math.BigDecimal KILOMETERS_PER_DEGREE
Number of kilometers in a degree at the equator.
-
LOCATION_DIFF_DEGREES
public static final java.math.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.
-
-
Method Detail
-
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 interfaceAssociator
- Parameters:
summary
- the product summary being associated.- Returns:
- a SearchRequest that can be used to search the ProductIndex.
-
chooseEvent
public Event chooseEvent(java.util.List<Event> events, ProductSummary summary)
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
protected Event chooseMostSimilar(ProductSummary summary, java.util.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 withevents
- 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:- 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
public ProductIndexQuery getEventIdQuery(java.lang.String eventSource, java.lang.String eventCode)
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
public ProductIndexQuery getLocationQuery(java.util.Date time, java.math.BigDecimal latitude, java.math.BigDecimal longitude)
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, java.util.Date time, java.math.BigDecimal latitude, java.math.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.
-
-