Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shakemap
shakyground2
Commits
ce87885f
Commit
ce87885f
authored
May 26, 2021
by
g-weatherill
Browse files
Fixes datetime formatting and adds new error for FDSN failure
parent
a265e042
Pipeline
#23446
passed with stage
in 11 minutes and 18 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
shakyground2/earthquake.py
View file @
ce87885f
...
...
@@ -213,9 +213,9 @@ class Earthquake(object):
"object found in %s"
%
path
)
# Time is not necessarily in ISO format, so fix this for use with datetime object
h
ms
,
micsec
=
event
[
"time"
].
split
(
"
.
"
)
micsec
=
micsec
.
replace
(
"Z"
,
"
0
"
)
[:
6
]
event_time
=
"
.
"
.
join
([
h
ms
,
micsec
])
h
h
,
mm
,
ss
=
event
[
"time"
].
split
(
"
:
"
)
ss
=
"{:2.6f}"
.
format
(
float
(
ss
.
replace
(
"Z"
,
""
)
))
event_time
=
"
:
"
.
join
([
h
h
,
mm
,
ss
])
d_t
=
datetime
.
datetime
.
fromisoformat
(
" "
.
join
([
event
[
"date"
],
event_time
]))
# If the event has a focal mechanism then parse this into the correct format
if
event
[
"focalmechanism"
]:
...
...
shakyground2/io/import_fdsnws_eq.py
View file @
ce87885f
...
...
@@ -21,6 +21,7 @@ import os
import
sys
from
typing
import
List
,
Union
import
urllib.request
as
ul
from
http.client
import
HTTPException
from
xml.etree
import
ElementTree
as
ET
import
yaml
...
...
@@ -152,8 +153,11 @@ def fetch_quakeml_ws(evid: str) -> str:
)
)
)
req
=
ul
.
Request
(
url
)
u
=
ul
.
urlopen
(
req
)
if
u
.
code
!=
200
:
raise
HTTPException
(
"FDSN result not returned for event %s with url:
\n
%s"
%
(
evid
,
url
))
buf
=
u
.
read
().
decode
(
"utf8"
)
print
(
"Got"
,
len
(
buf
),
"char(s)."
)
...
...
tests/io/test_quakexml.py
View file @
ce87885f
...
...
@@ -8,6 +8,7 @@
# ----------------------------------------------------------------------
import
os
import
unittest
from
http.client
import
HTTPException
from
shakyground2.io.import_fdsnws_eq
import
fetch_quakeml
...
...
@@ -73,6 +74,22 @@ class QuakeMLReadTestCase(unittest.TestCase):
self
.
assertEqual
(
len
(
result
[
"origin"
]),
3
)
self
.
assertTrue
(
result
[
"time"
].
startswith
(
"08:08:23"
))
def
test_bad_html_connection
(
self
):
"""
If a bad url is given, check that it raises an HTTPException
"""
evid
=
"gfzabadname"
with
self
.
assertRaises
(
HTTPException
)
as
he
:
fetch_quakeml
(
evid
)
badurl
=
(
"http://geofon.gfz-potsdam.de/fdsnws/event/1/query?"
"includeallmagnitudes=true&includefocalmechanism=true&eventid={:s}"
.
format
(
evid
)
)
self
.
assertEqual
(
str
(
he
.
exception
),
"FDSN result not returned for event %s with url:
\n
%s"
%
(
evid
,
badurl
),
)
def
tearDown
(
self
):
try
:
os
.
unlink
(
self
.
outfile
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment