def _ReadAndFilterData(filename, start_date, end_date, pos, distance):
"""Creates a filter function for the CSV reader, and reads csv data.
Args:
filename: The path of the file to read.
start_date: Start date we should begin filtering the data.
end_date: End date we should begin filtering the data.
pos: Location we should be filtering the data for.
distance: Distance in KM for which we include aftershocks.
Returns:
List of dictionaries of ISC data.
"""
def _Filter(x):
"""Filter that we apply to all isc data."""
try:
# Remove the normal problems with the data.
if not _IsRowValid(x): return False
# Make sure the data point is in the date range specified.
if not start_date <= x['date_time'] <= end_date: return False
# Make sure the data point is within the distance specified.
if vincenty((x['lat'], x['lon']), pos) > distance: return False
except ValueError:
# Vincenty doesn't always converge. If it fails to, then default to a
# Great Circle distance.
if great_circle((x['lat'], x['lon']), pos) > distance: return False
return True
return _ReadCsvFile(filename, data_validator=_Filter)
评论列表
文章目录