Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed Mar 18, 2024
1 parent 92ed89c commit ea11223
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
9 changes: 4 additions & 5 deletions src/qseek/images/phase_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,15 @@ def search_phase_arrival(
peak_delay = peak_times - event_time.timestamp()

# Limit to post-event peaks
post_event_peaks = peak_delay > 0.0
peak_idx = peak_idx[post_event_peaks]
peak_times = peak_times[post_event_peaks]
peak_delay = peak_delay[post_event_peaks]
after_event_peaks = peak_delay > 0.0
peak_idx = peak_idx[after_event_peaks]
peak_times = peak_times[after_event_peaks]
peak_delay = peak_delay[after_event_peaks]

if not peak_idx.size:
return None

peak_values = search_trace.get_ydata()[peak_idx]

closest_peak_idx = np.argmin(peak_delay)

return ObservedArrival(
Expand Down
9 changes: 3 additions & 6 deletions src/qseek/models/semblance.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,10 @@ def _populate_table(self, table: Table) -> None:
)
table.add_row(
"Semblance size",
f"{human_readable_bytes(self.semblance_size_bytes)}"
f"{human_readable_bytes(self.semblance_size_bytes)}/"
f"{human_readable_bytes(self.semblance_allocation_bytes)}"
f" ({self.last_nodes_stacked} nodes)",
)
table.add_row(
"Memory allocated",
f"{human_readable_bytes(self.semblance_allocation_bytes)}",
)


class SemblanceCache(dict[bytes, np.ndarray]):
Expand Down Expand Up @@ -240,7 +237,7 @@ async def apply_cache(self, cache: SemblanceCache) -> None:
self.semblance_unpadded,
data,
mask,
nthreads=1,
nthreads=8,
)

def maximum_node_semblance(self) -> np.ndarray:
Expand Down
17 changes: 12 additions & 5 deletions src/qseek/models/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import TYPE_CHECKING, Any, Iterable, Iterator

import numpy as np
from pydantic import BaseModel, Field, FilePath, constr
from pydantic import BaseModel, DirectoryPath, Field, FilePath, constr
from pyrocko.io.stationxml import load_xml
from pyrocko.model import Station as PyrockoStation
from pyrocko.model import dump_stations_yaml, load_stations
Expand Down Expand Up @@ -76,7 +76,7 @@ class Stations(BaseModel):
description="List of [Pyrocko station YAML]"
"(https://pyrocko.org/docs/current/formats/yaml.html) files.",
)
station_xmls: list[FilePath] = Field(
station_xmls: list[FilePath | DirectoryPath] = Field(
default=[],
description="List of StationXML files.",
)
Expand All @@ -93,9 +93,16 @@ def model_post_init(self, __context: Any) -> None:
for file in self.pyrocko_station_yamls:
loaded_stations += load_stations(filename=str(file.expanduser()))

for file in self.station_xmls:
station_xml = load_xml(filename=str(file.expanduser()))
loaded_stations += station_xml.get_pyrocko_stations()
for path in self.station_xmls:
if path.is_dir():
station_xmls = path.glob("*.xml")
elif path.is_file():
station_xmls = [path]
else:
continue
for file in station_xmls:
station_xml = load_xml(filename=str(file.expanduser()))
loaded_stations += station_xml.get_pyrocko_stations()

for sta in loaded_stations:
sta = Station.from_pyrocko_station(sta)
Expand Down
21 changes: 21 additions & 0 deletions src/qseek/octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,27 @@ def save_pickle(self, filename: Path) -> None:
with filename.open("wb") as f:
pickle.dump(self, f)

def get_corners(self) -> list[Location]:
"""Get the corners of the octree.
Returns:
list[Location]: List of locations.
"""
reference = self.location
return [
Location(
lat=reference.lat,
lon=reference.lon,
elevation=reference.elevation,
east_shift=reference.east_shift + east,
north_shift=reference.north_shift + north,
depth=reference.depth + depth,
)
for east in (self.east_bounds.min, self.east_bounds.max)
for north in (self.north_bounds.min, self.north_bounds.max)
for depth in (self.depth_bounds.min, self.depth_bounds.max)
]

def __hash__(self) -> int:
return hash(
(
Expand Down

0 comments on commit ea11223

Please sign in to comment.