Skip to content

Commit

Permalink
fixes to squirrel persistence // adding local magnitude argetina
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed May 24, 2024
1 parent 5ff007a commit 3ba1cd6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
11 changes: 11 additions & 0 deletions src/qseek/magnitudes/local_magnitude_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,15 @@ def get_amp_attenuation(dist_hypo_km: float, dist_epi_km: float) -> float:
return 0.89 * np.log10(dist_epi_km / 100) + 0.00256 * (dist_epi_km - 100) + 3


class ArgentinaVolcanoes(WoodAnderson, LocalMagnitudeModel):
author = "Montenegro et al. (2021)"

epicentral_range = Range(0.0 * KM, 100.0 * KM) # Bounds are not clear
component = "north-east-separate"

@staticmethod
def get_amp_attenuation(dist_hypo_km: float, dist_epi_km: float) -> float:
return 2.76 * np.log10(dist_epi_km) - 2.48


ModelName = Literal[LocalMagnitudeModel.model_names()]
2 changes: 1 addition & 1 deletion src/qseek/octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class Octree(BaseModel):
description="The reference location of the octree.",
)
root_node_size: PositiveFloat = Field(
default=2 * KM,
default=1 * KM,
description="Initial size of the root octree node at level 0 in meters.",
)
n_levels: int = Field(
Expand Down
2 changes: 1 addition & 1 deletion src/qseek/pre_processing/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Downsample(BatchPreProcessing):

process: Literal["downsample"] = "downsample"
sampling_frequency: PositiveFloat = Field(
100.0,
default=100.0,
description="The new sampling frequency in Hz.",
)

Expand Down
11 changes: 6 additions & 5 deletions src/qseek/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from qseek.models.detection_uncertainty import DetectionUncertainty
from qseek.models.semblance import Semblance, SemblanceCache
from qseek.octree import NodeSplitError, Octree
from qseek.pre_processing.frequency_filters import Bandpass
from qseek.pre_processing.module import Downsample, PreProcessing
from qseek.signals import Signal
from qseek.station_weights import StationWeights
Expand Down Expand Up @@ -215,11 +216,11 @@ class Search(BaseModel):
description="Station inventory from StationXML or Pyrocko Station YAML.",
)
data_provider: WaveformProviderType = Field(
default=PyrockoSquirrel(),
default_factory=PyrockoSquirrel.model_construct,
description="Data provider for waveform data.",
)
pre_processing: PreProcessing = Field(
default=PreProcessing(root=[Downsample(sampling_frequency=100.0)]),
default=PreProcessing(root=[Downsample(), Bandpass()]),
description="Pre-processing steps for waveform data.",
)

Expand Down Expand Up @@ -379,7 +380,7 @@ def write_config(self, path: Path | None = None) -> None:
logger.debug("writing search config to %s", path)
path.write_text(self.model_dump_json(indent=2, exclude_unset=True))

logger.debug("dumping stations...")
logger.debug("dumping stations")
self.stations.export_pyrocko_stations(rundir / "pyrocko_stations.yaml")

csv_dir = rundir / "csv"
Expand Down Expand Up @@ -458,7 +459,7 @@ async def prepare(self) -> None:
Returns:
None
"""
logger.info("preparing search...")
logger.info("preparing search components")
self.data_provider.prepare(self.stations)
await self.pre_processing.prepare()

Expand Down Expand Up @@ -489,7 +490,7 @@ async def start(self, force_rundir: bool = False) -> None:

await self.prepare()

logger.info("starting search...")
logger.info("starting search")
stats = self._stats
stats.reset_start_time()

Expand Down
29 changes: 17 additions & 12 deletions src/qseek/waveforms/squirrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
PositiveInt,
PrivateAttr,
computed_field,
field_validator,
model_validator,
)
from pyrocko.squirrel import Squirrel
Expand Down Expand Up @@ -113,10 +112,14 @@ class PyrockoSquirrel(WaveformProvider):

provider: Literal["PyrockoSquirrel"] = "PyrockoSquirrel"

environment: DirectoryPath = Field(
default=Path("."),
environment: DirectoryPath | None = Field(
default=None,
description="Path to a Squirrel environment.",
)
persistent: str | None = Field(
default=None,
description="Name of the persistent collection for faster loading.",
)
waveform_dirs: list[Path] = Field(
default=[],
description="List of directories holding the waveform files.",
Expand Down Expand Up @@ -151,18 +154,20 @@ class PyrockoSquirrel(WaveformProvider):
def _validate_model(self) -> Self:
if self.start_time and self.end_time and self.start_time > self.end_time:
raise ValueError("start_time must be before end_time")
if not self.waveform_dirs and not self.persistent:
raise ValueError("no waveform directories or persistent selection provided")
return self

@field_validator("waveform_dirs")
def check_dirs(cls, dirs: list[Path]) -> list[Path]: # noqa: N805
if not dirs:
raise ValueError("no waveform directories provided!")
return dirs

def get_squirrel(self) -> Squirrel:
if not self._squirrel:
logger.info("initializing squirrel waveform provider")
squirrel = Squirrel(str(self.environment.expanduser()))
logger.info(
"initializing squirrel waveform provider in environment %s",
self.environment,
)
squirrel = Squirrel(
env=str(self.environment.expanduser()) if self.environment else None,
persistent=self.persistent,
)
paths = []
for path in self.waveform_dirs:
if "**" in str(path):
Expand All @@ -173,7 +178,7 @@ def get_squirrel(self) -> Squirrel:
squirrel.add(paths, check=False)
if self._stations:
for path in self._stations.station_xmls:
logger.info("loading responses from %s", path)
logger.info("loading StationXML responses from %s", path)
squirrel.add(str(path), check=False)
self._squirrel = squirrel
return self._squirrel
Expand Down

0 comments on commit 3ba1cd6

Please sign in to comment.