blitzortung 1.11.33__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. blitzortung-1.11.33/LICENSE +177 -0
  2. blitzortung-1.11.33/PKG-INFO +75 -0
  3. blitzortung-1.11.33/README.md +43 -0
  4. blitzortung-1.11.33/blitzortung/__init__.py +74 -0
  5. blitzortung-1.11.33/blitzortung/base.py +87 -0
  6. blitzortung-1.11.33/blitzortung/builder/__init__.py +2 -0
  7. blitzortung-1.11.33/blitzortung/builder/base.py +65 -0
  8. blitzortung-1.11.33/blitzortung/builder/strike.py +111 -0
  9. blitzortung-1.11.33/blitzortung/cache.py +138 -0
  10. blitzortung-1.11.33/blitzortung/cli/__init__.py +0 -0
  11. blitzortung-1.11.33/blitzortung/cli/db.py +209 -0
  12. blitzortung-1.11.33/blitzortung/cli/imprt.py +145 -0
  13. blitzortung-1.11.33/blitzortung/cli/imprt_websocket.py +144 -0
  14. blitzortung-1.11.33/blitzortung/cli/start_webservice.py +19 -0
  15. blitzortung-1.11.33/blitzortung/cli/update.py +298 -0
  16. blitzortung-1.11.33/blitzortung/cli/webservice.py +435 -0
  17. blitzortung-1.11.33/blitzortung/cli/webservice_insertlog.py +144 -0
  18. blitzortung-1.11.33/blitzortung/config.py +80 -0
  19. blitzortung-1.11.33/blitzortung/convert.py +4 -0
  20. blitzortung-1.11.33/blitzortung/data.py +402 -0
  21. blitzortung-1.11.33/blitzortung/dataimport/__init__.py +8 -0
  22. blitzortung-1.11.33/blitzortung/dataimport/base.py +110 -0
  23. blitzortung-1.11.33/blitzortung/dataimport/strike.py +69 -0
  24. blitzortung-1.11.33/blitzortung/db/__init__.py +103 -0
  25. blitzortung-1.11.33/blitzortung/db/compat.py +33 -0
  26. blitzortung-1.11.33/blitzortung/db/grid_result.py +10 -0
  27. blitzortung-1.11.33/blitzortung/db/mapper.py +63 -0
  28. blitzortung-1.11.33/blitzortung/db/query.py +344 -0
  29. blitzortung-1.11.33/blitzortung/db/query_builder.py +109 -0
  30. blitzortung-1.11.33/blitzortung/db/table.py +311 -0
  31. blitzortung-1.11.33/blitzortung/geom.py +191 -0
  32. blitzortung-1.11.33/blitzortung/gis/__init__.py +0 -0
  33. blitzortung-1.11.33/blitzortung/gis/constants.py +25 -0
  34. blitzortung-1.11.33/blitzortung/gis/local_grid.py +47 -0
  35. blitzortung-1.11.33/blitzortung/lock.py +21 -0
  36. blitzortung-1.11.33/blitzortung/logger.py +32 -0
  37. blitzortung-1.11.33/blitzortung/service/__init__.py +48 -0
  38. blitzortung-1.11.33/blitzortung/service/cache.py +39 -0
  39. blitzortung-1.11.33/blitzortung/service/db.py +84 -0
  40. blitzortung-1.11.33/blitzortung/service/general.py +64 -0
  41. blitzortung-1.11.33/blitzortung/service/histogram.py +57 -0
  42. blitzortung-1.11.33/blitzortung/service/metrics.py +34 -0
  43. blitzortung-1.11.33/blitzortung/service/strike.py +110 -0
  44. blitzortung-1.11.33/blitzortung/service/strike_grid.py +195 -0
  45. blitzortung-1.11.33/blitzortung/util.py +119 -0
  46. blitzortung-1.11.33/blitzortung/websocket.py +18 -0
  47. blitzortung-1.11.33/pyproject.toml +51 -0
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: blitzortung
3
+ Version: 1.11.33
4
+ Summary: blitzortung.org python modules
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Author: Andreas Würl
8
+ Author-email: andi@tryb.de
9
+ Requires-Python: >=3.11,<4.0
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Requires-Dist: fasteners (>=0.19)
16
+ Requires-Dist: geoip2 (>=5.1)
17
+ Requires-Dist: incremental (>=22.10)
18
+ Requires-Dist: injector (>=0.22)
19
+ Requires-Dist: psycopg2 (>=2.9)
20
+ Requires-Dist: psycopg2cffi (>=2.9)
21
+ Requires-Dist: pyproj (>=3.7)
22
+ Requires-Dist: requests (>=2.32)
23
+ Requires-Dist: shapely (>=2.0)
24
+ Requires-Dist: statsd (>=4.0)
25
+ Requires-Dist: stopit (>=1.1)
26
+ Requires-Dist: twisted (>=25.5)
27
+ Requires-Dist: txjsonrpc-ng (>=0.8)
28
+ Requires-Dist: txpostgres (>=1.7)
29
+ Requires-Dist: websocket-client (>=1.9)
30
+ Description-Content-Type: text/markdown
31
+
32
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
33
+ [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
34
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=coverage)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
35
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
36
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/wuan/bo-python/badge)](https://scorecard.dev/viewer/?uri=github.com/wuan/bo-python)
37
+
38
+ python-blitzortung a python module for blitzortung.org related stuff
39
+ --------------------------------------------------------------------
40
+
41
+ # Introduction
42
+
43
+ This module contains the following independent components
44
+
45
+ * Database setup and access for local storage of blitzortung.org data.
46
+ * Strike data import from data.blitzortung.org.
47
+ * JsonRPC Webservice providing strike data in different formats.
48
+ * Clustering of strike data (under development).
49
+
50
+ # Installation
51
+
52
+ It is recommended to install the package in a virtual environment:
53
+
54
+ ```bash
55
+ python -m venv venv
56
+ source venv/bin/activate # On Windows: venv\Scripts\activate
57
+ pip install blitzortung
58
+ ```
59
+
60
+ For development installation from source:
61
+
62
+ ```bash
63
+ python -m venv venv
64
+ source venv/bin/activate # On Windows: venv\Scripts\activate
65
+ pip install -e .
66
+ ```
67
+
68
+ ## Optional Dependencies
69
+
70
+ Scipy and fastcluster are required for the (optional) clustering functionality. These can be installed via:
71
+
72
+ ```bash
73
+ pip install scipy fastcluster
74
+ ```
75
+
@@ -0,0 +1,43 @@
1
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
2
+ [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
3
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=coverage)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
4
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=wuan_bo-python&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=wuan_bo-python)
5
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/wuan/bo-python/badge)](https://scorecard.dev/viewer/?uri=github.com/wuan/bo-python)
6
+
7
+ python-blitzortung a python module for blitzortung.org related stuff
8
+ --------------------------------------------------------------------
9
+
10
+ # Introduction
11
+
12
+ This module contains the following independent components
13
+
14
+ * Database setup and access for local storage of blitzortung.org data.
15
+ * Strike data import from data.blitzortung.org.
16
+ * JsonRPC Webservice providing strike data in different formats.
17
+ * Clustering of strike data (under development).
18
+
19
+ # Installation
20
+
21
+ It is recommended to install the package in a virtual environment:
22
+
23
+ ```bash
24
+ python -m venv venv
25
+ source venv/bin/activate # On Windows: venv\Scripts\activate
26
+ pip install blitzortung
27
+ ```
28
+
29
+ For development installation from source:
30
+
31
+ ```bash
32
+ python -m venv venv
33
+ source venv/bin/activate # On Windows: venv\Scripts\activate
34
+ pip install -e .
35
+ ```
36
+
37
+ ## Optional Dependencies
38
+
39
+ Scipy and fastcluster are required for the (optional) clustering functionality. These can be installed via:
40
+
41
+ ```bash
42
+ pip install scipy fastcluster
43
+ ```
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf8 -*-
2
+
3
+ """
4
+
5
+ Copyright 2014-2022 Andreas Würl
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ """
20
+
21
+ import logging
22
+
23
+ __version__ = '1.7.1'
24
+
25
+
26
+ # -----------------------------------------------------------------------------
27
+ # Constants.
28
+ # -----------------------------------------------------------------------------
29
+
30
+ # -----------------------------------------------------------------------------
31
+ # Custom exceptions.
32
+ # -----------------------------------------------------------------------------
33
+
34
+
35
+ class Error(Exception):
36
+ """
37
+ General Blitzortung error class.
38
+ """
39
+ pass
40
+
41
+
42
+ # -----------------------------------------------------------------------------
43
+ # Public interface and exports.
44
+ # -----------------------------------------------------------------------------
45
+
46
+
47
+ import injector
48
+
49
+ from . import builder
50
+ from . import config
51
+ from . import data
52
+ from . import dataimport
53
+ from . import db
54
+ from . import geom
55
+ from . import util
56
+ from . import base
57
+
58
+ INJECTOR = injector.Injector(
59
+ [config.ConfigModule(), db.DbModule()])
60
+
61
+ root_logger = logging.getLogger(__name__)
62
+ root_logger.setLevel(logging.WARN)
63
+
64
+
65
+ def set_parent_logger(logger):
66
+ logger.parent = root_logger
67
+
68
+
69
+ def set_log_level(log_level):
70
+ root_logger.setLevel(log_level)
71
+
72
+
73
+ def add_log_handler(log_handler):
74
+ root_logger.addHandler(log_handler)
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf8 -*-
2
+
3
+ """
4
+
5
+ Copyright 2014-2016 Andreas Würl
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ """
20
+
21
+ import math
22
+
23
+ import pyproj
24
+
25
+
26
+ class EqualityAndHash:
27
+ def __eq__(self, other):
28
+ if isinstance(other, self.__class__):
29
+ return self.__dict__ == other.__dict__
30
+ return NotImplemented
31
+
32
+ def __ne__(self, other):
33
+ if isinstance(other, self.__class__):
34
+ return not self.__eq__(other)
35
+ return NotImplemented
36
+
37
+ def __hash__(self):
38
+ return hash(tuple(sorted(self.__dict__.items())))
39
+
40
+
41
+ class Point:
42
+ """
43
+ Base class for Point like objects
44
+ """
45
+
46
+ __radians_factor = math.pi / 180
47
+
48
+ __geod = pyproj.Geod(ellps='WGS84', units='m')
49
+
50
+ __slots__ = ('x', 'y')
51
+
52
+ def __init__(self, x_coord_or_point, y_coord=None):
53
+ (self.x, self.y) = self.__get_point_coordinates(x_coord_or_point, y_coord)
54
+
55
+ def distance_to(self, other):
56
+ return self.geodesic_relation_to(other)[1]
57
+
58
+ def azimuth_to(self, other):
59
+ return self.geodesic_relation_to(other)[0]
60
+
61
+ def geodesic_shift(self, azimuth, distance):
62
+ result = self.__geod.fwd(self.x, self.y, azimuth / self.__radians_factor, distance, radians=False)
63
+ return Point(result[0], result[1])
64
+
65
+ def geodesic_relation_to(self, other):
66
+ result = self.__geod.inv(self.x, self.y, other.x, other.y, radians=False)
67
+ return result[0] * self.__radians_factor, result[2]
68
+
69
+ @staticmethod
70
+ def __get_point_coordinates(x_coord_or_point, y_coord):
71
+ if isinstance(x_coord_or_point, Point):
72
+ return x_coord_or_point.x, x_coord_or_point.y
73
+ else:
74
+ return x_coord_or_point, y_coord
75
+
76
+ def __eq__(self, other):
77
+ return self.equal(self.x, other.x) and self.equal(self.y, other.y)
78
+
79
+ @staticmethod
80
+ def equal(a, b):
81
+ return abs(a - b) < 1e-4
82
+
83
+ def __str__(self):
84
+ return "(%.4f, %.4f)" % (self.x, self.y)
85
+
86
+ def __hash__(self):
87
+ return hash(self.x) ^ hash(self.y)
@@ -0,0 +1,2 @@
1
+ from .base import Timestamp, Event, BuilderError
2
+ from .strike import Strike
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf8 -*-
2
+
3
+ """
4
+
5
+ Copyright 2014-2022 Andreas Würl
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ """
20
+
21
+ from .. import data, Error
22
+
23
+
24
+ class BuilderError(Error):
25
+ pass
26
+
27
+
28
+ class Base:
29
+ pass
30
+
31
+
32
+ class Timestamp(Base):
33
+ def __init__(self):
34
+ super().__init__()
35
+ self.timestamp = None
36
+
37
+ def set_timestamp(self, timestamp, nanosecond=0):
38
+ if not timestamp:
39
+ self.timestamp = None
40
+ elif isinstance(timestamp, data.Timestamp):
41
+ self.timestamp = timestamp + nanosecond
42
+ else:
43
+ self.timestamp = data.Timestamp(timestamp, nanosecond=nanosecond)
44
+ return self
45
+
46
+ def build(self):
47
+ return self.timestamp
48
+
49
+
50
+ class Event(Timestamp):
51
+ def __init__(self):
52
+ super().__init__()
53
+ self.x_coord = 0
54
+ self.y_coord = 0
55
+
56
+ def set_x(self, x_coord):
57
+ self.x_coord = x_coord
58
+ return self
59
+
60
+ def set_y(self, y_coord):
61
+ self.y_coord = y_coord
62
+ return self
63
+
64
+ def build(self):
65
+ return data.Event(self.timestamp, self.x_coord, self.y_coord)
@@ -0,0 +1,111 @@
1
+ # -*- coding: utf8 -*-
2
+
3
+ """
4
+
5
+ Copyright 2014-2025 Andreas Würl
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ """
20
+
21
+ import re
22
+
23
+ from .base import Event, BuilderError
24
+ from .. import data
25
+ from ..data import Timestamp
26
+ from ..util import force_range
27
+
28
+
29
+ class Strike(Event):
30
+ """
31
+ class for building strike objects
32
+ """
33
+ position_parser = re.compile(r'pos;([-0-9.]+);([-0-9.]+);([-0-9.]+)')
34
+ amplitude_parser = re.compile(r'str;([0-9.]+)')
35
+ deviation_parser = re.compile(r'dev;([0-9.]+)')
36
+ stations_parser = re.compile(r'sta;(\d+);(\d+);([^ ]*)')
37
+
38
+ def __init__(self):
39
+ super().__init__()
40
+ self.id_value = -1
41
+ self.altitude = None
42
+ self.amplitude = None
43
+ self.lateral_error = None
44
+ self.station_count = None
45
+ self.stations = []
46
+
47
+ def set_id(self, id_value):
48
+ self.id_value = id_value
49
+ return self
50
+
51
+ def set_altitude(self, altitude):
52
+ self.altitude = altitude
53
+ return self
54
+
55
+ def set_amplitude(self, amplitude):
56
+ self.amplitude = amplitude
57
+ return self
58
+
59
+ def set_lateral_error(self, lateral_error):
60
+ self.lateral_error = force_range(0, lateral_error, 32767) if lateral_error is not None else None
61
+ return self
62
+
63
+ def set_station_count(self, station_count):
64
+ self.station_count = station_count
65
+ return self
66
+
67
+ def set_stations(self, stations):
68
+ self.stations = stations
69
+ return self
70
+
71
+ def from_line(self, line):
72
+ """ Construct strike from new blitzortung text format data line """
73
+ try:
74
+ self.set_timestamp(line[0:29])
75
+
76
+ position = self.position_parser.findall(line)[0]
77
+ self.set_x(float(position[1]))
78
+ self.set_y(float(position[0]))
79
+ self.set_altitude(float(position[2]))
80
+
81
+ self.set_amplitude(float(self.amplitude_parser.findall(line)[0]))
82
+
83
+ self.set_lateral_error(float(self.deviation_parser.findall(line)[0]))
84
+ stations = self.stations_parser.findall(line)[0]
85
+ self.set_station_count(int(stations[0]))
86
+ self.set_stations([int(station) for station in stations[2].split(',') if station])
87
+ except (KeyError, ValueError, IndexError) as e:
88
+ raise BuilderError(e)
89
+
90
+ return self
91
+
92
+ def from_json(self, json_data: dict):
93
+ """ Construct strike from json data """
94
+ try:
95
+ self.set_altitude(json_data.get('alt',0))
96
+ self.set_x(round(json_data['lon'], 4))
97
+ self.set_y(round(json_data['lat'], 4))
98
+ self.set_timestamp(Timestamp(json_data['time']))
99
+ self.set_lateral_error(json_data.get('mds', 0))
100
+
101
+ self.set_altitude(0)
102
+ self.set_amplitude(0)
103
+ self.set_station_count(0)
104
+ except (KeyError, ValueError, IndexError) as e:
105
+ raise BuilderError(e)
106
+
107
+ return self
108
+
109
+ def build(self):
110
+ return data.Strike(self.id_value, self.timestamp, self.x_coord, self.y_coord, self.altitude,
111
+ self.amplitude, self.lateral_error, self.station_count, self.stations)