-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marius Isken
committed
Jul 5, 2024
1 parent
a138aea
commit 65e94e7
Showing
9 changed files
with
218 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from qseek.exporters.simple import Simple # noqa | ||
from qseek.exporters.velest import Velest # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Exporter(BaseModel): | ||
async def export(self, rundir: Path, outdir: Path) -> Path: | ||
raise NotImplementedError | ||
|
||
@classmethod | ||
def get_subclasses(cls) -> tuple[type[Exporter], ...]: | ||
"""Get the subclasses of this class. | ||
Returns: | ||
list[type]: The subclasses of this class. | ||
""" | ||
return tuple(cls.__subclasses__()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from rich import progress | ||
|
||
from qseek.exporters.base import Exporter | ||
from qseek.search import Search | ||
from qseek.utils import time_to_path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Simple(Exporter): | ||
"""Export simple travel times in CSV format (E. Biondi, 2023).""" | ||
|
||
async def export(self, rundir: Path, outdir: Path) -> Path: | ||
logger.info("Export simple travel times in CSV format.") | ||
|
||
search = Search.load_rundir(rundir) | ||
catalog = search.catalog | ||
|
||
traveltime_dir = outdir / "traveltimes" | ||
outdir.mkdir(parents=True) | ||
traveltime_dir.mkdir() | ||
|
||
event_file = outdir / "events.csv" | ||
self.search.stations.export_csv(outdir / "stations.csv") | ||
await catalog.export_csv(event_file) | ||
|
||
for ev in progress.track( | ||
catalog, | ||
description="Exporting travel times", | ||
total=catalog.n_events, | ||
): | ||
traveltime_file = traveltime_dir / f"{time_to_path(ev.time)}.csv" | ||
with traveltime_file.open("w") as file: | ||
file.write(f"# event_id: {ev.uid}\n") | ||
file.write(f"# event_time: {ev.time}\n") | ||
file.write(f"# event_lat: {ev.lat}\n") | ||
file.write(f"# event_lon: {ev.lon}\n") | ||
file.write(f"# event_depth: {ev.effective_depth}\n") | ||
file.write(f"# event_semblance: {ev.semblance}\n") | ||
file.write("# traveltime observations:\n") | ||
file.write( | ||
"lat,lon,elevation,network,station,location,phase,confidence,traveltime\n" | ||
) | ||
|
||
for receiver in ev.receivers: | ||
for phase, arrival in receiver.phase_arrivals.items(): | ||
if arrival.observed is None: | ||
continue | ||
traveltime = arrival.observed.time - ev.time | ||
file.write( | ||
f"{receiver.lat},{receiver.lon},{receiver.effective_elevation},{receiver.network},{receiver.station},{receiver.location},{phase},{arrival.observed.detection_value},{traveltime.total_seconds()}\n", | ||
) | ||
|
||
return outdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
import rich | ||
from rich.prompt import FloatPrompt | ||
|
||
from qseek.exporters.base import Exporter | ||
from qseek.search import Search | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Velest(Exporter): | ||
"""Crate a VELEST project folder for 1D velocity model estimation.""" | ||
|
||
min_pick_semblance: float = 0.3 | ||
n_picks: dict[str, int] = {} | ||
n_events: int = 0 | ||
|
||
async def export(self, rundir: Path, outdir: Path) -> Path: | ||
rich.print("Exporting qseek search to VELEST project folder") | ||
min_pick_semblance = FloatPrompt.ask("Minimum pick confidence", default=0.3) | ||
|
||
self.min_pick_semblance = min_pick_semblance | ||
|
||
outdir.mkdir() | ||
search = Search.load_rundir(rundir) | ||
catalog = search.catalog # noqa | ||
|
||
export_info = outdir / "export_info.json" | ||
export_info.write_text(self.model_dump_json(indent=2)) | ||
|
||
return outdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters