diff --git a/src/qseek/exporters/simple.py b/src/qseek/exporters/simple.py index 63dde913..5c6b8e62 100644 --- a/src/qseek/exporters/simple.py +++ b/src/qseek/exporters/simple.py @@ -25,9 +25,8 @@ 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, @@ -35,6 +34,17 @@ async def export(self, rundir: Path, outdir: Path) -> Path: 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") @@ -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 diff --git a/src/qseek/search.py b/src/qseek/search.py index 3b5d48fe..6ccf85b5 100644 --- a/src/qseek/search.py +++ b/src/qseek/search.py @@ -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 @@ -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 @@ -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 @@ -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()