Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geomag-algorithms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Geomagnetism Program
geomag-algorithms
Commits
ccfe33cb
Commit
ccfe33cb
authored
8 years ago
by
Jeremy M Fee
Browse files
Options
Downloads
Patches
Plain Diff
Update TimeseriesFactory.put_timeseries to merge data being written into existing data files
parent
be3d8371
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/TimeseriesFactory.py
+36
-1
36 additions, 1 deletion
geomagio/TimeseriesFactory.py
with
36 additions
and
1 deletion
geomagio/TimeseriesFactory.py
+
36
−
1
View file @
ccfe33cb
...
@@ -3,6 +3,7 @@ import obspy.core
...
@@ -3,6 +3,7 @@ import obspy.core
import
os
import
os
import
sys
import
sys
from
TimeseriesFactoryException
import
TimeseriesFactoryException
from
TimeseriesFactoryException
import
TimeseriesFactoryException
import
TimeseriesUtility
import
Util
import
Util
...
@@ -103,7 +104,10 @@ class TimeseriesFactory(object):
...
@@ -103,7 +104,10 @@ class TimeseriesFactory(object):
type
=
type
,
type
=
type
,
interval
=
interval
,
interval
=
interval
,
channels
=
channels
)
channels
=
channels
)
data
=
Util
.
read_url
(
url
)
try
:
data
=
Util
.
read_url
(
url
)
except
IOError
as
e
:
continue
try
:
try
:
timeseries
+=
self
.
parse_string
(
data
,
timeseries
+=
self
.
parse_string
(
data
,
observatory
=
observatory
,
observatory
=
observatory
,
...
@@ -189,6 +193,37 @@ class TimeseriesFactory(object):
...
@@ -189,6 +193,37 @@ class TimeseriesFactory(object):
# subtract delta to omit the sample at end: `[start, end)`
# subtract delta to omit the sample at end: `[start, end)`
endtime
=
(
urlInterval
[
'
end
'
]
-
delta
))
endtime
=
(
urlInterval
[
'
end
'
]
-
delta
))
url_file
=
Util
.
get_file_from_url
(
url
,
createParentDirectory
=
True
)
url_file
=
Util
.
get_file_from_url
(
url
,
createParentDirectory
=
True
)
# existing data file, merge new data into existing
if
os
.
path
.
isfile
(
url_file
):
try
:
existing_data
=
Util
.
read_file
(
url_file
)
existing_data
=
self
.
parse_string
(
existing_data
,
observatory
=
url_data
[
0
].
stats
.
station
,
type
=
type
,
interval
=
interval
,
channels
=
channels
)
# TODO: make parse_string return the correct location code
for
trace
in
existing_data
:
# make location codes match, just in case
new_trace
=
url_data
.
select
(
network
=
trace
.
stats
.
network
,
station
=
trace
.
stats
.
station
,
channel
=
trace
.
stats
.
channel
)[
0
]
trace
.
stats
.
location
=
new_trace
.
stats
.
location
url_data
=
TimeseriesUtility
.
merge_streams
(
existing_data
,
url_data
)
except
IOError
:
# no data yet
pass
except
NotImplementedError
:
# factory only supports output
pass
except
Exception
as
e
:
print
>>
sys
.
stderr
,
\
'
Unable to merge with existing data.
'
+
\
'
\n
file={}
'
+
\
'
\n
error={}
'
.
format
(
url_file
,
str
(
e
))
raise
e
with
open
(
url_file
,
'
wb
'
)
as
fh
:
with
open
(
url_file
,
'
wb
'
)
as
fh
:
try
:
try
:
self
.
write_file
(
fh
,
url_data
,
channels
)
self
.
write_file
(
fh
,
url_data
,
channels
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment