Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.3
rev: v8.23.3
hooks:
- id: gitleaks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pylint-dev/pylint
rev: v2.17.2
rev: v3.3.4
hooks:
- id: pylint
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.6
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Please have a look at https://github.com/wuan/bo-server for related scripts/cron
## Install pip

> wget https://bootstrap.pypa.io/get-pip.py
> sudo pypy3 get-pip.py
> sudo pypy3 get-pip.py
Install manually by entering

## Install library with dependencies
Expand All @@ -36,4 +36,3 @@ or build a debian package by entering
The following software has to be installed manually, depending on their availability as debian/ubuntu packages.

Scipy and fastcluster is required for the (optional) clustering

45 changes: 21 additions & 24 deletions blitzortung/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

"""

Copyright 2014-2022 Andreas Würl
Copyright 2014-2022 Andreas Würl

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""

"""
blitzortung python modules
"""
import logging

__version__ = '1.7.1'
import injector


__version__ = "1.7.1"


# -----------------------------------------------------------------------------
Expand All @@ -39,6 +39,7 @@ class Error(Exception):
"""
General Blitzortung error class.
"""

pass


Expand All @@ -47,18 +48,14 @@ class Error(Exception):
# -----------------------------------------------------------------------------


import injector
def create_injector():
from . import config
from . import db

return injector.Injector([config.ConfigModule(), db.DbModule()])

from . import builder
from . import config
from . import dataimport
from . import db
from . import geom
from . import util
from . import base

INJECTOR = injector.Injector(
[config.ConfigModule(), db.DbModule()])
INJECTOR = create_injector()

root_logger = logging.getLogger(__name__)
root_logger.setLevel(logging.WARN)
Expand Down
54 changes: 33 additions & 21 deletions blitzortung/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@

"""

Copyright 2014-2016 Andreas Würl
Copyright 2014-2016 Andreas Würl

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""

import math

import pyproj
from typing import Any, Self, override, Optional, Union


class EqualityAndHash:
def __eq__(self, other):
def __eq__(self, other: Any):
if isinstance(other, self.__class__):
return self.__dict__ == other.__dict__
return NotImplemented

def __ne__(self, other):
def __ne__(self, other: Any):
if isinstance(other, self.__class__):
return not self.__eq__(other)
return NotImplemented

@override
def __hash__(self):
return hash(tuple(sorted(self.__dict__.items())))

Expand All @@ -43,34 +45,44 @@ class Point:
Base class for Point like objects
"""

x: float
y: float

__radians_factor = math.pi / 180

__geod = pyproj.Geod(ellps='WGS84', units='m')
__geod = pyproj.Geod(ellps="WGS84", units="m")

__slots__ = ('x', 'y')
__slots__: tuple[str, str] = "x", "y"

def __init__(self, x_coord_or_point, y_coord=None):
def __init__(
self, x_coord_or_point: float | Self, y_coord: float | None = None
) -> None:
(self.x, self.y) = self.__get_point_coordinates(x_coord_or_point, y_coord)

def distance_to(self, other):
def distance_to(self, other: Self):
return self.geodesic_relation_to(other)[1]

def azimuth_to(self, other):
return self.geodesic_relation_to(other)[0]

def geodesic_shift(self, azimuth, distance):
result = self.__geod.fwd(self.x, self.y, azimuth / self.__radians_factor, distance, radians=False)
return Point(result[0], result[1])
def geodesic_shift(self, azimuth: float, distance: float) -> Self:
result: tuple[float, float, float] = self.__geod.fwd(
self.x, self.y, azimuth / self.__radians_factor, distance, radians=False
)
return type(self)(result[0], result[1])

def geodesic_relation_to(self, other):
def geodesic_relation_to(self, other: Self) -> tuple[float, float]:
result = self.__geod.inv(self.x, self.y, other.x, other.y, radians=False)
return result[0] * self.__radians_factor, result[2]

@staticmethod
def __get_point_coordinates(x_coord_or_point, y_coord):
def __get_point_coordinates(
x_coord_or_point: Union[float, "Point"], y_coord: Optional[float]
) -> tuple[float, float]:
if isinstance(x_coord_or_point, Point):
return x_coord_or_point.x, x_coord_or_point.y
else:
assert y_coord is not None
return x_coord_or_point, y_coord

def __eq__(self, other):
Expand Down
4 changes: 2 additions & 2 deletions blitzortung/builder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import Timestamp, Event, BuilderError
from .raw_signal import RawWaveformEvent, ChannelWaveform
from .station import Station, StationOffline
from .strike import Strike

__all__ = [Strike, Timestamp, Event, BuilderError]
20 changes: 10 additions & 10 deletions blitzortung/builder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

"""

Copyright 2014-2022 Andreas Würl
Copyright 2014-2022 Andreas Würl

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""

Expand Down
Loading
Loading