Skip to content

Commit f21b221

Browse files
author
Marius Isken
committed
wip
1 parent fad8d29 commit f21b221

4 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/qseek/search.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
from qseek.cache_lru import CACHES
2626
from qseek.corrections.corrections import StationCorrectionType, corrections_from_path
27-
from qseek.distance_weights import DistanceWeights
2827
from qseek.features import FeatureExtractorType
2928
from qseek.images.images import ImageFunctions, WaveformImages
3029
from qseek.magnitudes import EventMagnitudeCalculatorType
@@ -38,14 +37,15 @@
3837
from qseek.pre_processing.module import Downsample, PreProcessing
3938
from qseek.reduce import DelaySumReduce
4039
from qseek.signals import Signal
40+
from qseek.station_weights import StationWeights
4141
from qseek.stats import RuntimeStats, Stats
4242
from qseek.tracers.tracers import RayTracer, RayTracers
4343
from qseek.utils import (
4444
BackgroundTasks,
4545
CpuCount,
4646
PhaseDescription,
47+
_get_cpu_count,
4748
datetime_now,
48-
get_cpu_count,
4949
get_total_memory,
5050
human_readable_bytes,
5151
time_to_path,
@@ -265,10 +265,11 @@ class Search(BaseModel):
265265
),
266266
description="List of ray tracers for travel time calculation.",
267267
)
268-
distance_weights: DistanceWeights | None = Field(
269-
default_factory=DistanceWeights,
268+
station_weights: StationWeights | None = Field(
269+
default_factory=StationWeights,
270270
validation_alias=AliasChoices("spatial_weights", "distance_weights"),
271-
description="Spatial weights for distance weighting.",
271+
description="Station weighting based on station density and "
272+
"source-station distance.",
272273
)
273274
station_corrections: StationCorrectionType | None = Field(
274275
default=None,
@@ -357,7 +358,7 @@ class Search(BaseModel):
357358
_rundir: Path = PrivateAttr()
358359

359360
_compute_semaphore: asyncio.Semaphore = PrivateAttr(
360-
asyncio.Semaphore(max(1, get_cpu_count() - 4))
361+
asyncio.Semaphore(max(1, _get_cpu_count() - 4))
361362
)
362363

363364
# Signals
@@ -493,8 +494,8 @@ async def prepare(self) -> None:
493494
await self.pre_processing.prepare()
494495
await self.image_functions.prepare()
495496

496-
if self.distance_weights:
497-
self.distance_weights.prepare(self.stations, self.octree)
497+
if self.station_weights:
498+
self.station_weights.prepare(self.stations, self.octree)
498499

499500
if self.station_corrections:
500501
await self.station_corrections.prepare(
@@ -552,7 +553,7 @@ async def start(self, force_rundir: bool = False) -> None:
552553
ray_tracers=self.ray_tracers,
553554
window_padding=window_padding,
554555
station_corrections=self.station_corrections,
555-
distance_weights=self.distance_weights,
556+
distance_weights=self.station_weights,
556557
detection_threshold=self.detection_threshold,
557558
pick_confidence_threshold=self.pick_confidence_threshold,
558559
node_interpolation=self.node_interpolation,
@@ -698,7 +699,7 @@ def __init__(
698699
ray_tracers: RayTracers,
699700
window_padding: timedelta,
700701
station_corrections: StationCorrectionType | None = None,
701-
distance_weights: DistanceWeights | None = None,
702+
distance_weights: StationWeights | None = None,
702703
detection_threshold: float | Literal["MAD"] = "MAD",
703704
detection_blinding: timedelta = timedelta(seconds=1.0),
704705
pick_confidence_threshold: float = 0.3,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def weights_gaussian(
210210
return weights
211211

212212

213-
class DistanceWeights(BaseModel):
213+
class StationWeights(BaseModel):
214214
plateau_weight: PositiveFloat = Field(
215215
default=4.0,
216216
description="The cumulative station weight required to define the"
@@ -256,7 +256,7 @@ def prepare(self, stations: StationInventory, octree: Octree) -> None:
256256
logger.info("calculating overall station weights")
257257
station_weights = _station_weights(self._interstation_distances)
258258
for sta, weight in zip(stations, station_weights, strict=True):
259-
sta.set_apparent_weight(weight)
259+
sta.set_apparent_weight(float(weight))
260260

261261
self.fill_lut(nodes=octree.nodes)
262262

src/qseek/tracers/fast_marching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from qseek.stats import get_progress
2323
from qseek.tracers.base import ModelledArrival, RayTracer
2424
from qseek.tracers.utils import LayeredEarthModel1D, surface_distances_reference
25-
from qseek.utils import Range, alog_call, datetime_now, get_cpu_count
25+
from qseek.utils import Range, _get_cpu_count, alog_call, datetime_now
2626

2727
if TYPE_CHECKING:
2828
from qseek.models.location import Location
@@ -321,7 +321,7 @@ async def _calculate_travel_times(self) -> None:
321321
if self._layered_model is None:
322322
raise ValueError("layered model must be set for FastMarchingTracer")
323323

324-
nthreads = self.nthreads if self.nthreads > 0 else get_cpu_count() * 2
324+
nthreads = self.nthreads if self.nthreads > 0 else _get_cpu_count() * 2
325325
executor = ThreadPoolExecutor(
326326
max_workers=nthreads,
327327
thread_name_prefix="qseek-fmm",

src/qseek_inversion/inversion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ async def prepare(self) -> None:
6565
await self.event_selection.prepare(rundir=self.import_rundir)
6666
# await search.prepare()
6767
self._search = search
68-
if search.distance_weights:
69-
search.distance_weights.prepare(
68+
if search.station_weights:
69+
search.station_weights.prepare(
7070
self.event_selection.stations,
7171
search.octree,
7272
)
@@ -84,7 +84,7 @@ async def prepare(self) -> None:
8484
detection_blinding=search.detection_blinding,
8585
pick_confidence_threshold=search.pick_confidence_threshold,
8686
station_corrections=search.station_corrections,
87-
distance_weights=search.distance_weights,
87+
distance_weights=search.station_weights,
8888
ignore_boundary=search.ignore_boundary,
8989
ignore_boundary_width=search.ignore_boundary_width,
9090
node_interpolation=False,

0 commit comments

Comments
 (0)