trichter / rf

Receiver function calculation in seismology
MIT License
106 stars 62 forks source link

iter_event_data should handle missing data fields in event objects #7

Closed medlin01GA closed 5 years ago

medlin01GA commented 5 years ago

The iterator iter_event_data does not gracefully handle when the Origin of an Event is missing an expected field. Namely, if any of {latitude, longitude, depth, magnitude, or time} are missing, then the call to stats.update(obj2stats(event=event, station=station)) in function rf_stats can raise an unhandled exception. This is difficult for the user to handle in a recoverable way, since the iterator will be left before the user code has a chance to handle it. It should probably be handled (with a warning message) in rf_stats, and then return an empty object. This would allow the iterator iter_event_data to continue yielding events.

To reproduce the issue, use a valid Event with valid Origin, and del the depth field of the Origin. Then pass such data to iter_event_data to iterate over.

A real example of a typical, valid Origin:

Origin resource_id: ResourceIdentifier(id="smi:ISC/origid=609833474") time: UTCDateTime(2017, 9, 11, 17, 35, 9, 620000) [uncertainty=2.24] longitude: 142.3373 latitude: 23.9529 depth: 35000.0 quality: OriginQuality(used_phase_count=166, standard_error=1.1, azimuthal_gap=19.0, minimum_distance=3.132) origin_uncertainty: OriginUncertainty(min_horizontal_uncertainty=9.9, max_horizontal_uncertainty=12.2, azimuth_max_horizontal_uncertainty=258.0, preferred_description='uncertainty ellipse') creation_info: CreationInfo(author='NEIC')

A real example of a bad Origin, missing the depth field, taken from Event id "smi:ISC/evid=611767244":

Origin resource_id: ResourceIdentifier(id="smi:ISC/origid=609672372") time: UTCDateTime(2018, 3, 7, 14, 46, 12, 200000) longitude: 57.65 latitude: 28.03 quality: OriginQuality(azimuthal_gap=27.0) creation_info: CreationInfo(author='CSEM')

As a workaround, users could remove bad events from a Catalog before passing it to iter_event_data.

trichter commented 5 years ago

Thanks for reporting this issue and suggesting solutions! I will have a look.

trichter commented 5 years ago

I solved it similar as you suggested by catching the error in iter_event_data and issuing a warning instead. Does it work for you?

medlin01GA commented 5 years ago

Looks good to me, thanks Tom.