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

SC3ML: Set depth to 0 if missing, fix issue with finding publicIDs (fixes #1816) #1817

Merged
merged 7 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
44 changes: 34 additions & 10 deletions obspy/io/seiscomp/sc3ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ def _read_channel(inventory_root, cha_element, _ns):
unit=True)
depth = _read_floattype(cha_element, _ns("depth"), Distance,
unit=True)

# Set values to 0 if they are is missing (see #1816)
if longitude is None:
msg = "Sensor is missing longitude information, using 0.0"
warnings.warn(msg)
longitude = 0
if latitude is None:
msg = "Sensor is missing latitude information, using 0.0"
warnings.warn(msg)
latitude = 0
if elevation is None:
msg = "Sensor is missing elevation information, using 0.0"
warnings.warn(msg)
elevation = 0
if depth is None:
msg = "Channel is missing depth information, using 0.0"
warnings.warn(msg)
depth = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for longitude/latitude/elevation, they're all not mandatory in sc3ml according to the schema..

Also, please show a warning message, e.g.

    if depth is None:
        msg = "Channel is missing depth information, using '0.0'"
        warnings.warn(msg)
        depth = 0


channel = obspy.core.inventory.Channel(
code=code, location_code=location_code, latitude=latitude,
longitude=longitude, elevation=elevation, depth=depth)
Expand All @@ -396,17 +415,22 @@ def _read_channel(inventory_root, cha_element, _ns):
# obtain the poles and zeros responseID and link to particular
# <responsePAZ> publicID element in the inventory base node
if sensor_element is not None:

response_id = sensor_element.get("response")
if response_id is not None:
resp_type = response_id.split("#")[0]
if resp_type == 'ResponsePAZ':
search = "responsePAZ[@publicID='" + response_id + "']"
response_element = inventory_root.find(_ns(search))
elif resp_type == 'ResponsePolynomial':
search = "responsePolynomial[@publicID='" + response_id + "']"
response_element = inventory_root.find(_ns(search))
else:
response_element = None
response_elements = []

for resp_type in ['responsePAZ', 'responsePolynomial']:
search = "{}[@publicID='{}']".format(resp_type, response_id)
response_elements += inventory_root.findall(_ns(search))
if len(response_elements) == 0:
msg = ("Could not find response tag with public ID "
"'{}'.".format(response_id))
raise ObsPyException(msg)
elif len(response_elements) > 1:
msg = ("Found multiple matching response tags with the same "
"public ID '{}'.".format(response_id))
raise ObsPyException(msg)
response_element = response_elements[0]
else:
response_element = None

Expand Down