Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed improvements #94

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 34 additions & 14 deletions msnoise/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ def preload_instrument_responses(session):
channels = []
if response_format == "inventory":
for file in files:
print("Processing %s" % file)
logging.debug("Processing %s" % file)
try:
inv = read_inventory(file, format='STATIONXML')
for net in inv.networks:
Expand All @@ -1554,20 +1554,39 @@ def preload_instrument_responses(session):
seed_id = "%s.%s.%s.%s" % (net.code, sta.code,
cha.location_code,
cha.code)
resp = inv.get_response(seed_id, cha.start_date+10)
polezerostage = resp.get_paz()
totalsensitivity = resp.instrument_sensitivity
pzdict = {}
pzdict['poles'] = polezerostage.poles
pzdict['zeros'] = polezerostage.zeros
pzdict['gain'] = polezerostage.normalization_factor
pzdict['sensitivity'] = totalsensitivity.value
try:
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
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, cha.latitude,
cha.longitude])
except:
pass
pzdict, lat, lon, elevation])
except Exception as e:
logging.error('Failed to process file %s: %s' % (file, str(e)))

elif response_format == "dataless":
for file in files:
Expand All @@ -1581,12 +1600,13 @@ def preload_instrument_responses(session):
channel["end_date"] or UTCDateTime(),
resp,
channel["latitude"],
channel["longitude"]])
channel["longitude"],
channel["elevation_in_m"]])
except:
pass
channels = pd.DataFrame(channels, columns=["channel_id", "start_date",
"end_date", "paz", "latitude",
"longitude"],)
"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 @@ -251,11 +251,18 @@ def config(set, sync):
for station in get_stations(db):
id = "%s.%s" % (station.net, station.sta)
coords = responses[responses["netsta"] == id]
lon = float(coords["longitude"].values[0])
lat = float(coords["latitude"].values[0])
update_station(db, station.net, station.sta, lat, lon, 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()

else:
Expand Down