Skip to content

Commit

Permalink
exporter: simple reworks
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed Jul 7, 2024
1 parent fbdc17f commit 551c544
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
29 changes: 18 additions & 11 deletions src/qseek/exporters/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ async def export(self, rundir: Path, outdir: Path) -> Path:
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)
search.stations.export_csv(outdir / "stations.csv")
await catalog.export_csv(outdir / "events.csv")

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"

observed_arrivals = [
(receiver, phase, arrival)
for receiver in ev.receivers
for phase, arrival in receiver.phase_arrivals.items()
if arrival.observed is not None
]

if not observed_arrivals:
continue

with traveltime_file.open("w") as file:
file.write(f"# event_id: {ev.uid}\n")
file.write(f"# event_time: {ev.time}\n")
Expand All @@ -47,13 +57,10 @@ async def export(self, rundir: Path, outdir: Path) -> Path:
"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",
)
for receiver, phase, arrival in observed_arrivals:
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
10 changes: 5 additions & 5 deletions src/qseek/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SearchStats(Stats):
batch_time: datetime = datetime.min
batch_count: int = 0
batch_count_total: int = 0
processed_duration: timedelta = timedelta(seconds=0.0)
processed_time: timedelta = timedelta(seconds=0.0)
processed_bytes: int = 0
processing_time: timedelta = timedelta(seconds=0.0)
latest_processing_rate: float = 0.0
Expand All @@ -95,8 +95,8 @@ def time_remaining(self) -> timedelta:
if not remaining_batches:
return timedelta()

duration = datetime_now() - self._search_start
return duration / self.batch_count * remaining_batches
elapsed_time = datetime_now() - self._search_start
return (elapsed_time / self.batch_count) * remaining_batches

@computed_field
@property
Expand All @@ -115,7 +115,7 @@ def processing_rate(self) -> float:
def processing_speed(self) -> timedelta:
if not self.processing_time:
return timedelta(seconds=0.0)
return self.processed_duration / self.processing_time.total_seconds()
return self.processed_time / self.processing_time.total_seconds()

@computed_field
@property
Expand Down Expand Up @@ -152,7 +152,7 @@ def add_processed_batch(
self.batch_count_total = batch.n_batches
self.batch_time = batch.end_time
self.processed_bytes += batch.cumulative_bytes
self.processed_duration += batch.duration
self.processed_time += batch.duration
self.processing_time += duration
self.latest_processing_rate = batch.cumulative_bytes / duration.total_seconds()
self.latest_processing_speed = batch.duration / duration.total_seconds()
Expand Down

0 comments on commit 551c544

Please sign in to comment.