Skip to content
Snippets Groups Projects
Commit 7e3b1140 authored by Wernle, Alexandra Nicole's avatar Wernle, Alexandra Nicole
Browse files

Changed channels argument to str. Added add_empty_channels to get_timeseries....

Changed channels argument to str. Added add_empty_channels to get_timeseries. Changed split_stream_by_day to split stream, not individual traces.
parent d88cefd3
No related branches found
No related tags found
1 merge request!344New MetadataAlgorithm, SpikesAlgorithm, and flag-spikes application
...@@ -2,7 +2,6 @@ from pydantic import BaseModel ...@@ -2,7 +2,6 @@ from pydantic import BaseModel
from obspy import UTCDateTime, Stream from obspy import UTCDateTime, Stream
from datetime import timedelta from datetime import timedelta
from enum import Enum from enum import Enum
from typing import List
from ..metadata.flag.Flag import Flag from ..metadata.flag.Flag import Flag
from ..metadata import Metadata, MetadataFactory, MetadataCategory from ..metadata import Metadata, MetadataFactory, MetadataCategory
...@@ -18,7 +17,7 @@ class DataFactory(str, Enum): ...@@ -18,7 +17,7 @@ class DataFactory(str, Enum):
class MetadataAlgorithm(BaseModel): class MetadataAlgorithm(BaseModel):
factory: DataFactory = DataFactory.MINISEED factory: DataFactory = DataFactory.MINISEED
observatory: str observatory: str
channels: List[str] channels: str
metadata_token: str metadata_token: str
metadata_url: str metadata_url: str
type: str type: str
...@@ -47,6 +46,7 @@ class MetadataAlgorithm(BaseModel): ...@@ -47,6 +46,7 @@ class MetadataAlgorithm(BaseModel):
return data_factory.get_timeseries( return data_factory.get_timeseries(
starttime=self.starttime, starttime=self.starttime,
endtime=self.endtime, endtime=self.endtime,
add_empty_channels=True,
) )
except Exception as e: except Exception as e:
raise ValueError(f"Failed to retrieve data stream from {self.factory}: {e}") raise ValueError(f"Failed to retrieve data stream from {self.factory}: {e}")
...@@ -103,26 +103,28 @@ class MetadataAlgorithm(BaseModel): ...@@ -103,26 +103,28 @@ class MetadataAlgorithm(BaseModel):
def split_stream_by_day(self, stream: Stream) -> list[Stream]: def split_stream_by_day(self, stream: Stream) -> list[Stream]:
"""Split stream into daily streams to prevent metadata from overlapping.""" """Split stream into daily streams to prevent metadata from overlapping."""
daily_streams = [] daily_streams = []
# get min and max time
current_time = min(trace.stats.starttime for trace in stream)
end_time = max(trace.stats.endtime for trace in stream)
# loop through each day and slice the stream accordingly
while current_time <= end_time:
day_endtime = min(
UTCDateTime(
current_time.year, current_time.month, current_time.day, 23, 59, 59
),
end_time,
)
# slice stream for the current day
daily_stream = stream.slice(
starttime=current_time, endtime=day_endtime, nearest_sample=True
)
if daily_stream:
daily_streams.append(daily_stream)
for trace in stream: current_time += timedelta(days=1)
current_time = trace.stats.starttime
trace_endtime = trace.stats.endtime
while current_time <= trace_endtime:
day_endtime = min(
UTCDateTime(
current_time.year, current_time.month, current_time.day, 23, 59
),
trace_endtime,
)
daily_streams.append(
stream.slice(
starttime=current_time, endtime=day_endtime, nearest_sample=True
)
)
current_time += timedelta(days=1)
return daily_streams return daily_streams
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment