Skip to content

Commit

Permalink
stations: adding max_distance parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
marius committed Nov 26, 2024
1 parent e619326 commit 0ee4f5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/qseek/models/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from pyrocko.squirrel import Squirrel
from pyrocko.trace import Trace

from qseek.octree import Octree

from qseek.models.location import CoordSystem, Location

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -89,6 +91,12 @@ class Stations(BaseModel):
)
stations: list[Station] = []

max_distance: float | None = Field(
default=None,
description="Maximum distance in meters from the centroid location to "
"include stations for detection. If None, all stations are included.",
)

def model_post_init(self, __context: Any) -> None:
loaded_stations = []
for file in self.pyrocko_station_yamls:
Expand Down Expand Up @@ -171,6 +179,18 @@ def weed_from_squirrel_waveforms(self, squirrel: Squirrel) -> None:
if not self.stations:
raise ValueError("no stations available, add waveforms to start detection")

def prepare(self, octree: Octree) -> None:
if self.max_distance is not None:
for sta in self.stations.copy():
distance = octree.location.surface_distance_to(sta)
if distance > self.max_distance:
logger.warning(
"removing station %s: distance to octree is %d m",
sta.nsl.pretty,
distance,
)
self.stations.remove(sta)

def __iter__(self) -> Iterator[Station]:
blacklist_pretty = {nsl.pretty for nsl in self.blacklist}
return (sta for sta in self.stations if sta.nsl.pretty not in blacklist_pretty)
Expand Down
1 change: 1 addition & 0 deletions src/qseek/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ async def prepare(self) -> None:
asyncio.get_running_loop().set_exception_handler(
lambda loop, context: logger.error(context)
)
self.stations.prepare(self.octree)
self.data_provider.prepare(self.stations)
await self.pre_processing.prepare()

Expand Down
1 change: 0 additions & 1 deletion src/qseek/waveforms/squirrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ class PyrockoSquirrel(WaveformProvider):
description="Number of threads for loading waveforms,"
" important for large data sets.",
)

watch_waveforms: bool | timedelta = Field(
default=False,
description="Watch the waveform directories for changes. If `True` it will "
Expand Down

0 comments on commit 0ee4f5a

Please sign in to comment.