From b513d351577066ab0026825f8b1d89335c47421e Mon Sep 17 00:00:00 2001 From: miili Date: Wed, 6 Mar 2024 10:17:00 +0100 Subject: [PATCH] chores: update pyproject.toml and ruff --- .pre-commit-config.yaml | 4 ++-- pyproject.toml | 14 ++++++++++++-- src/qseek/apps/qseek.py | 7 ++++--- src/qseek/corrections/base.py | 3 +-- src/qseek/images/base.py | 6 ++---- src/qseek/images/images.py | 6 +++--- src/qseek/models/catalog.py | 7 ++++--- src/qseek/models/detection.py | 6 +++--- src/qseek/models/station.py | 3 +-- src/qseek/octree.py | 3 +-- src/qseek/search.py | 6 +++--- src/qseek/tracers/base.py | 6 ++---- src/qseek/tracers/cake.py | 7 ++++--- src/qseek/waveforms/base.py | 3 +-- test/test_location.py | 1 - test/test_search.py | 1 - 16 files changed, 43 insertions(+), 40 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f1dab5e7..0b1451b4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,11 +10,11 @@ repos: - id: mixed-line-ending - repo: https://github.com/charliermarsh/ruff-pre-commit # Ruff version. - rev: v0.2.2 + rev: v0.3.0 hooks: - id: ruff - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.2.2 + rev: v0.3.0 hooks: - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index d79e30be..c72ad3a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,13 @@ maintainers = [ { name = "Marius Paul Isken", email = "mi@gfz-potsdam.de" }, { name = "Sebastian Heimann", email = "heimann@uni-potsdam.de" }, ] -keywords = ["earthquake", "detection", "locatiosation", "stacking-migration"] +keywords = [ + "earthquake", + "detection", + "localization", + "stacking-migration", + "beamforming", +] dependencies = [ "numpy>=1.17.3", @@ -64,7 +70,11 @@ dev = [ "pytest-asyncio>=0.21", ] -docs = ["mkdocs-material>=9.4.8", "mkdocstrings[python]>=0.23", "qseek-extra"] +docs = [ + "mkdocs-material>=9.4.8", + "mkdocstrings[python]>=0.23", + "qseek-insights", +] completion = ["argcomplete>=3.2"] [project.scripts] diff --git a/src/qseek/apps/qseek.py b/src/qseek/apps/qseek.py index 066d73fd..f1712824 100644 --- a/src/qseek/apps/qseek.py +++ b/src/qseek/apps/qseek.py @@ -286,9 +286,10 @@ async def extract() -> None: search = Search.load_rundir(args.rundir) webserver = WebServer(search) - loop = asyncio.get_event_loop() - loop.create_task(webserver.start()) - loop.run_forever() + async def start() -> None: + await webserver.start() + + asyncio.run(start(), debug=loop_debug) case "clear-cache": logger.info("clearing cache directory %s", CACHE_DIR) diff --git a/src/qseek/corrections/base.py b/src/qseek/corrections/base.py index 0f46295e..10b614e5 100644 --- a/src/qseek/corrections/base.py +++ b/src/qseek/corrections/base.py @@ -29,8 +29,7 @@ def get_subclasses(cls) -> tuple[type[TravelTimeCorrections], ...]: return tuple(cls.__subclasses__()) @property - def n_stations(self) -> int: - ... + def n_stations(self) -> int: ... def get_delay( self, diff --git a/src/qseek/images/base.py b/src/qseek/images/base.py index 31939e87..af78c846 100644 --- a/src/qseek/images/base.py +++ b/src/qseek/images/base.py @@ -26,8 +26,7 @@ class ObservedArrival: class ImageFunction(BaseModel): image: Literal["base"] = "base" - async def process_traces(self, traces: list[Trace]) -> list[WaveformImage]: - ... + async def process_traces(self, traces: list[Trace]) -> list[WaveformImage]: ... @property def name(self) -> str: @@ -38,8 +37,7 @@ def blinding(self) -> timedelta: """Blinding duration for the image function. Added to padded waveforms.""" raise NotImplementedError("must be implemented by subclass") - def get_provided_phases(self) -> tuple[PhaseDescription, ...]: - ... + def get_provided_phases(self) -> tuple[PhaseDescription, ...]: ... @dataclass diff --git a/src/qseek/images/images.py b/src/qseek/images/images.py index e8e09625..526f0a26 100644 --- a/src/qseek/images/images.py +++ b/src/qseek/images/images.py @@ -36,9 +36,9 @@ class ImageFunctionsStats(Stats): time_per_batch: timedelta = timedelta() bytes_per_second: float = 0.0 - _queue: asyncio.Queue[ - Tuple[WaveformImages | WaveformBatch] | None - ] | None = PrivateAttr(None) + _queue: asyncio.Queue[Tuple[WaveformImages | WaveformBatch] | None] | None = ( + PrivateAttr(None) + ) def set_queue( self, diff --git a/src/qseek/models/catalog.py b/src/qseek/models/catalog.py index f2803628..8bb3a370 100644 --- a/src/qseek/models/catalog.py +++ b/src/qseek/models/catalog.py @@ -110,9 +110,10 @@ def load_rundir(cls, rundir: Path) -> EventCatalog: logger.warning("cannot find %s", detection_file) return catalog - with console.status(f"loading detections from {rundir}..."), open( - detection_file - ) as f: + with ( + console.status(f"loading detections from {rundir}..."), + open(detection_file) as f, + ): for idx, line in enumerate(f): detection = EventDetection.model_validate_json(line) detection.set_index(idx) diff --git a/src/qseek/models/detection.py b/src/qseek/models/detection.py index 10db4482..4a9d89c9 100644 --- a/src/qseek/models/detection.py +++ b/src/qseek/models/detection.py @@ -108,9 +108,9 @@ def _get_csv_dict(self) -> dict[str, Any]: if self.observed: csv_dict[f"{prefix}.model.time"] = self.observed.time if self.traveltime_delay: - csv_dict[ - f"{prefix}.traveltime_delay" - ] = self.traveltime_delay.total_seconds() + csv_dict[f"{prefix}.traveltime_delay"] = ( + self.traveltime_delay.total_seconds() + ) return csv_dict def as_pyrocko_markers(self) -> list[marker.PhaseMarker]: diff --git a/src/qseek/models/station.py b/src/qseek/models/station.py index 437658fd..513787d2 100644 --- a/src/qseek/models/station.py +++ b/src/qseek/models/station.py @@ -233,8 +233,7 @@ def export_csv(self, filename: Path) -> None: f"{sta.lat},{sta.lon},{sta.elevation},{sta.depth}\n" ) - def export_vtk(self, reference: Location | None = None) -> None: - ... + def export_vtk(self, reference: Location | None = None) -> None: ... def __hash__(self) -> int: return hash(sta for sta in self) diff --git a/src/qseek/octree.py b/src/qseek/octree.py index a2255503..0a84adcd 100644 --- a/src/qseek/octree.py +++ b/src/qseek/octree.py @@ -63,8 +63,7 @@ def get_node_coordinates( raise ValueError(f"Unknown coordinate system: {system}") -class NodeSplitError(Exception): - ... +class NodeSplitError(Exception): ... @dataclass(slots=True) diff --git a/src/qseek/search.py b/src/qseek/search.py index 558e7c6d..f5bfccf1 100644 --- a/src/qseek/search.py +++ b/src/qseek/search.py @@ -291,9 +291,9 @@ class Search(BaseModel): _shift_range: timedelta = PrivateAttr(timedelta(seconds=0.0)) _window_padding: timedelta = PrivateAttr(timedelta(seconds=0.0)) _distance_range: tuple[float, float] = PrivateAttr((0.0, 0.0)) - _travel_time_ranges: dict[ - PhaseDescription, tuple[timedelta, timedelta] - ] = PrivateAttr({}) + _travel_time_ranges: dict[PhaseDescription, tuple[timedelta, timedelta]] = ( + PrivateAttr({}) + ) _last_detection_export: int = 0 _catalog: EventCatalog = PrivateAttr() diff --git a/src/qseek/tracers/base.py b/src/qseek/tracers/base.py index 36f67d9c..656e73f8 100644 --- a/src/qseek/tracers/base.py +++ b/src/qseek/tracers/base.py @@ -37,11 +37,9 @@ async def prepare( octree: Octree, stations: Stations, rundir: Path | None = None, - ): - ... + ): ... - def get_available_phases(self) -> tuple[str, ...]: - ... + def get_available_phases(self) -> tuple[str, ...]: ... def get_travel_time_location( self, diff --git a/src/qseek/tracers/cake.py b/src/qseek/tracers/cake.py index 83bc892e..f00f1054 100644 --- a/src/qseek/tracers/cake.py +++ b/src/qseek/tracers/cake.py @@ -358,9 +358,10 @@ def _load_sptree(self) -> spit.SPTree: if not self._file or not self._file.exists(): raise FileNotFoundError(f"file {self._file} not found") - with zipfile.ZipFile( - self._file, "r" - ) as archive, TemporaryDirectory() as temp_dir: + with ( + zipfile.ZipFile(self._file, "r") as archive, + TemporaryDirectory() as temp_dir, + ): archive.extract("model.sptree", path=temp_dir) return spit.SPTree(filename=str(Path(temp_dir) / "model.sptree")) diff --git a/src/qseek/waveforms/base.py b/src/qseek/waveforms/base.py index aba5ccda..8f067d26 100644 --- a/src/qseek/waveforms/base.py +++ b/src/qseek/waveforms/base.py @@ -77,8 +77,7 @@ def get_subclasses(cls) -> tuple[type[WaveformProvider], ...]: def get_squirrel(self) -> Squirrel: raise NotImplementedError - def prepare(self, stations: Stations) -> None: - ... + def prepare(self, stations: Stations) -> None: ... async def iter_batches( self, diff --git a/test/test_location.py b/test/test_location.py index cf80bbaa..e48813af 100644 --- a/test/test_location.py +++ b/test/test_location.py @@ -3,7 +3,6 @@ import random import numpy as np - from lassie.models import Location KM = 1e3 diff --git a/test/test_search.py b/test/test_search.py index f99747b6..21114dab 100644 --- a/test/test_search.py +++ b/test/test_search.py @@ -1,7 +1,6 @@ from pathlib import Path import pytest - from lassie.models.location import locations_to_csv from lassie.search import Search