Skip to content

Commit

Permalink
cherrypick #94
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLecocq committed Jul 16, 2024
1 parent 13432d1 commit 5b12a78
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
55 changes: 36 additions & 19 deletions msnoise/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1979,35 +1979,52 @@ def preload_instrument_responses(session, return_format="dataframe"):
logging.debug("Processing %s" % file)
try:
inv = read_inventory(file)
all_inv += inv

if return_format == "inventory":
all_inv += inv
continue

for net in inv.networks:
for sta in net.stations:
for cha in sta.channels:
seed_id = "%s.%s.%s.%s" % (net.code, sta.code,
cha.location_code,
cha.code)
pzdict = {}
try:
resp = inv.get_response(seed_id,
cha.start_date + 10)
resp = inv.get_response(seed_id, cha.start_date + 10)
polezerostage = resp.get_paz()
except Exception as e:
logging.warning(
'Failed to get PAZ for SEED ID "%s", this '
'SEED ID will have an empty dictionary '
'for Poles and Zeros '
'information (Error message: %s).' % (
seed_id, str(e)))
else:
totalsensitivity = resp.instrument_sensitivity
pz = {'poles': polezerostage.poles,
'zeros': polezerostage.zeros,
'gain': polezerostage.normalization_factor,
'sensitivity': totalsensitivity.value}
channels.append([seed_id, cha.start_date,
cha.end_date or UTCDateTime(),
pz, cha.latitude, cha.longitude])
except:
logging.debug("There was an error loading PAZ for"
" %s" % seed_id)
traceback.print_exc()
except:
logging.debug("Can't read this file using obspy's read_inventory():"
" %s" % file)
continue
pzdict['poles'] = polezerostage.poles
pzdict['zeros'] = polezerostage.zeros
pzdict['gain'] = polezerostage.normalization_factor
pzdict['sensitivity'] = totalsensitivity.value
lat = cha.latitude
lon = cha.longitude
elevation = cha.elevation
if lat is None or lon is None or elevation is None:
lat = sta.latitude
lon = sta.longitude
elevation = sta.elevation
if lat is None or lon is None or elevation is None:
logging.error(
'Failed to look up coordinates for SEED '
'ID: %s' % seed_id)
channels.append([seed_id, cha.start_date,
cha.end_date or UTCDateTime(),
pzdict, lat, lon, elevation])

except Exception as e:
logging.error('Failed to process file %s: %s' % (file, str(e)))


logging.debug('Finished Loading instrument responses')
if return_format == "inventory":
Expand All @@ -2016,7 +2033,7 @@ def preload_instrument_responses(session, return_format="dataframe"):
if return_format == "dataframe":
channels = pd.DataFrame(channels, columns=["channel_id", "start_date",
"end_date", "paz",
"latitude", "longitude"],)
"latitude", "longitude", "elevation"],)
return channels


Expand Down
17 changes: 12 additions & 5 deletions msnoise/scripts/msnoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,18 @@ def config_sync():
if not len(coords):
logger.error("No coords for %s, skipping,..." % id)
continue
lon = float(coords["longitude"].values[0])
lat = float(coords["latitude"].values[0])
update_station(db, station.net, station.sta, lon, lat, 0, "DEG", )
logging.info("Added coordinates (%.5f %.5f) for station %s.%s" %
(lon, lat, station.net, station.sta))
try:
lon = float(coords["longitude"].values[0])
lat = float(coords["latitude"].values[0])
elevation = float(coords["elevation"].values[0])
except:
logging.warning(
'Problem getting coordinates for '
'"%s": %s' % (id, str(coords)))
continue
update_station(db, station.net, station.sta, lat, lon, elevation, "DEG", )
logging.info("Added coordinates (%.5f %.5f %.1f) for station %s.%s" %
(lon, lat, elevation, station.net, station.sta))
db.close()


Expand Down

0 comments on commit 5b12a78

Please sign in to comment.