Skip to content

Commit 18278d0

Browse files
author
Mike Hearne
authored
Merge pull request #249 from mhearne-usgs/dyfifix
Cleaning up code to handle older column names in DYFI cdi_geo.txt files
2 parents e194382 + b14b4fe commit 18278d0

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

libcomcat/dataframes.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,13 @@
4646
'Latitude': 'lat',
4747
'Longitude': 'lon',
4848
'No. of responses': 'nresp',
49-
'Hypocentral distance': 'distance'
50-
}
51-
52-
OLD_DYFI_COLUMNS_REPLACE = {
49+
'Hypocentral distance': 'distance',
50+
'Epicentral distance': 'distance',
5351
'ZIP/Location': 'station',
54-
'CDI': 'intensity',
55-
'Latitude': 'lat',
56-
'Longitude': 'lon',
57-
'No. of responses': 'nresp',
58-
'Hypocentral distance': 'distance'
52+
5953
}
6054

55+
6156
PRODUCT_COLUMNS = ['Update Time', 'Product', 'Authoritative Event ID', 'Code',
6257
'Associated',
6358
'Product Source', 'Product Version',
@@ -840,9 +835,15 @@ def get_dyfi_data_frame(detail, dyfi_file=None,
840835
data, _ = dyfi.getContentBytes(file)
841836
if file.endswith('geojson'):
842837
dataframe = _parse_geojson(data)
838+
if dataframe is None or not len(dataframe):
839+
continue
843840
else:
844841
dataframe = _parse_text(data)
842+
if dataframe is None or not len(dataframe):
843+
continue
845844
break
845+
if not len(dataframe):
846+
return dataframe
846847
columns = ['station', 'lat', 'lon', 'distance', 'intensity', 'nresp']
847848
dataframe = dataframe[columns]
848849
return dataframe
@@ -857,10 +858,7 @@ def _parse_text(bytes_geo):
857858
columns = [col.strip(']') for col in columns]
858859
fileio = StringIO(text_geo)
859860
df = pd.read_csv(fileio, skiprows=1, names=columns)
860-
if 'ZIP/Location' in columns:
861-
df = df.rename(index=str, columns=OLD_DYFI_COLUMNS_REPLACE)
862-
else:
863-
df = df.rename(index=str, columns=DYFI_COLUMNS_REPLACE)
861+
df = df.rename(index=str, columns=DYFI_COLUMNS_REPLACE)
864862
df = df.drop(['Suspect?', 'City', 'State'], axis=1)
865863
# df = df[df['nresp'] >= MIN_RESPONSES]
866864
return df

0 commit comments

Comments
 (0)