Skip to content

Commit

Permalink
Merge pull request #9930 from gem/missing-stations
Browse files Browse the repository at this point in the history
ARISTOTLE: fix a case in which stations can not be downloaded from the USGS website
  • Loading branch information
ptormene authored Sep 5, 2024
2 parents d37afd8 + f17aef5 commit 4f7e1b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion openquake/engine/aristotle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import getpass
import logging
import numpy
from urllib.error import HTTPError
from openquake.baselib import config, hdf5, sap
from openquake.hazardlib import geo, nrml, sourceconverter
from openquake.hazardlib.shakemap.parsers import (
Expand Down Expand Up @@ -118,7 +119,11 @@ def get_aristotle_allparams(rupture_dict, time_event,
rupdic = get_rupture_dict(rupture_dict, ignore_shakemap)
if station_data_file is None:
# NOTE: giving precedence to the station_data_file uploaded via form
station_data_file = download_station_data_file(rupture_dict['usgs_id'])
try:
station_data_file = download_station_data_file(
rupture_dict['usgs_id'])
except HTTPError as exc:
logging.info(f'Station data is not available: {exc}')
rupture_file = rupdic.pop('rupture_file')
if rupture_file:
inputs['rupture_model'] = rupture_file
Expand Down
2 changes: 1 addition & 1 deletion openquake/hazardlib/shakemap/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def download_station_data_file(usgs_id):
try:
stations = read_usgs_stations_json(stations_json_str)
except LookupError as exc:
logging.warning(str(exc))
logging.info(str(exc))
else:
df = usgs_to_ecd_format(stations, exclude_imts=('SA(3.0)',))
if len(df) < 1:
Expand Down
10 changes: 8 additions & 2 deletions openquake/server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import psutil
from datetime import datetime, timezone
from urllib.parse import unquote_plus
from urllib.error import HTTPError
from xml.parsers.expat import ExpatError
from django.http import (
HttpResponse, HttpResponseNotFound, HttpResponseBadRequest,
Expand Down Expand Up @@ -857,8 +858,13 @@ def aristotle_validate(request):
params['station_data_file'] = request.POST.get(
'station_data_file_from_usgs')
else:
station_data_file = download_station_data_file(dic['usgs_id'])
params['station_data_file'] = station_data_file
try:
station_data_file = download_station_data_file(dic['usgs_id'])
except HTTPError as exc:
logging.info(f'Station data is not available: {exc}')
params['station_data_file'] = None
else:
params['station_data_file'] = station_data_file
return rupdic, *params.values()


Expand Down

0 comments on commit 4f7e1b0

Please sign in to comment.