portguard-ais 1.0.0__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.
- portguard_ais-1.0.0/LICENSE +21 -0
- portguard_ais-1.0.0/PKG-INFO +220 -0
- portguard_ais-1.0.0/README.md +158 -0
- portguard_ais-1.0.0/pyproject.toml +112 -0
- portguard_ais-1.0.0/setup.cfg +4 -0
- portguard_ais-1.0.0/src/portguard_ais/__init__.py +15 -0
- portguard_ais-1.0.0/src/portguard_ais/alerts/__init__.py +1 -0
- portguard_ais-1.0.0/src/portguard_ais/alerts/rationale.py +33 -0
- portguard_ais-1.0.0/src/portguard_ais/alerts/state_machine.py +138 -0
- portguard_ais-1.0.0/src/portguard_ais/cli.py +118 -0
- portguard_ais-1.0.0/src/portguard_ais/colregs/__init__.py +1 -0
- portguard_ais-1.0.0/src/portguard_ais/colregs/context.py +49 -0
- portguard_ais-1.0.0/src/portguard_ais/config.py +111 -0
- portguard_ais-1.0.0/src/portguard_ais/encounters/__init__.py +1 -0
- portguard_ais-1.0.0/src/portguard_ais/encounters/classifier.py +38 -0
- portguard_ais-1.0.0/src/portguard_ais/encounters/multivessel.py +43 -0
- portguard_ais-1.0.0/src/portguard_ais/encounters/pairing.py +22 -0
- portguard_ais-1.0.0/src/portguard_ais/enums.py +55 -0
- portguard_ais-1.0.0/src/portguard_ais/evaluation/__init__.py +1 -0
- portguard_ais-1.0.0/src/portguard_ais/evaluation/article.py +40 -0
- portguard_ais-1.0.0/src/portguard_ais/evaluation/benchmark.py +142 -0
- portguard_ais-1.0.0/src/portguard_ais/evaluation/metrics.py +35 -0
- portguard_ais-1.0.0/src/portguard_ais/evaluation/synthetic.py +269 -0
- portguard_ais-1.0.0/src/portguard_ais/exceptions.py +13 -0
- portguard_ais-1.0.0/src/portguard_ais/geometry/__init__.py +1 -0
- portguard_ais-1.0.0/src/portguard_ais/geometry/geodesy.py +39 -0
- portguard_ais-1.0.0/src/portguard_ais/geometry/relative_motion.py +50 -0
- portguard_ais-1.0.0/src/portguard_ais/ingestion/__init__.py +5 -0
- portguard_ais-1.0.0/src/portguard_ais/ingestion/readers.py +49 -0
- portguard_ais-1.0.0/src/portguard_ais/ingestion/schema.py +13 -0
- portguard_ais-1.0.0/src/portguard_ais/ingestion/stream.py +19 -0
- portguard_ais-1.0.0/src/portguard_ais/models.py +188 -0
- portguard_ais-1.0.0/src/portguard_ais/near_miss/__init__.py +1 -0
- portguard_ais-1.0.0/src/portguard_ais/near_miss/episodes.py +120 -0
- portguard_ais-1.0.0/src/portguard_ais/near_miss/exposure_hotspots.py +261 -0
- portguard_ais-1.0.0/src/portguard_ais/near_miss/hotspots.py +54 -0
- portguard_ais-1.0.0/src/portguard_ais/near_miss/miner.py +58 -0
- portguard_ais-1.0.0/src/portguard_ais/pipeline.py +143 -0
- portguard_ais-1.0.0/src/portguard_ais/preprocessing/__init__.py +6 -0
- portguard_ais-1.0.0/src/portguard_ais/preprocessing/anomalies.py +42 -0
- portguard_ais-1.0.0/src/portguard_ais/preprocessing/causal_alignment.py +84 -0
- portguard_ais-1.0.0/src/portguard_ais/preprocessing/cleaning.py +68 -0
- portguard_ais-1.0.0/src/portguard_ais/preprocessing/resampling.py +63 -0
- portguard_ais-1.0.0/src/portguard_ais/py.typed +0 -0
- portguard_ais-1.0.0/src/portguard_ais/reporting.py +60 -0
- portguard_ais-1.0.0/src/portguard_ais/risk/__init__.py +1 -0
- portguard_ais-1.0.0/src/portguard_ais/risk/confidence.py +16 -0
- portguard_ais-1.0.0/src/portguard_ais/risk/domain.py +43 -0
- portguard_ais-1.0.0/src/portguard_ais/risk/probabilistic_proximity.py +221 -0
- portguard_ais-1.0.0/src/portguard_ais/risk/scoring.py +51 -0
- portguard_ais-1.0.0/src/portguard_ais/risk/trend.py +61 -0
- portguard_ais-1.0.0/src/portguard_ais/serialization.py +93 -0
- portguard_ais-1.0.0/src/portguard_ais/visualization/__init__.py +7 -0
- portguard_ais-1.0.0/src/portguard_ais/visualization/article.py +163 -0
- portguard_ais-1.0.0/src/portguard_ais/visualization/encounter.py +31 -0
- portguard_ais-1.0.0/src/portguard_ais/visualization/plots.py +67 -0
- portguard_ais-1.0.0/src/portguard_ais.egg-info/PKG-INFO +220 -0
- portguard_ais-1.0.0/src/portguard_ais.egg-info/SOURCES.txt +60 -0
- portguard_ais-1.0.0/src/portguard_ais.egg-info/dependency_links.txt +1 -0
- portguard_ais-1.0.0/src/portguard_ais.egg-info/entry_points.txt +2 -0
- portguard_ais-1.0.0/src/portguard_ais.egg-info/requires.txt +21 -0
- portguard_ais-1.0.0/src/portguard_ais.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Irmina Durlik and Tymoteusz Miller
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: portguard-ais
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Explainable collision-risk alerts and vessel-encounter analytics for restricted port waters.
|
|
5
|
+
Author: Irmina Durlik
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Irmina Durlik and Tymoteusz Miller
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Documentation, https://github.com/irmina-d/PortGuard-AIS#readme
|
|
29
|
+
Project-URL: Issues, https://github.com/irmina-d/PortGuard-AIS/issues
|
|
30
|
+
Project-URL: Source, https://github.com/irmina-d/PortGuard-AIS
|
|
31
|
+
Keywords: AIS,maritime safety,collision risk,COLREG,near miss
|
|
32
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
33
|
+
Classifier: Intended Audience :: Science/Research
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Operating System :: OS Independent
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
38
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
39
|
+
Requires-Python: >=3.13
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
License-File: LICENSE
|
|
42
|
+
Requires-Dist: numpy>=2.1
|
|
43
|
+
Requires-Dist: pandas>=2.2
|
|
44
|
+
Requires-Dist: pydantic>=2.10
|
|
45
|
+
Requires-Dist: rich>=13.9
|
|
46
|
+
Requires-Dist: typer>=0.15
|
|
47
|
+
Provides-Extra: viz
|
|
48
|
+
Requires-Dist: matplotlib>=3.9; extra == "viz"
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
51
|
+
Requires-Dist: hypothesis>=6.120; extra == "dev"
|
|
52
|
+
Requires-Dist: mkdocs>=1.6; extra == "dev"
|
|
53
|
+
Requires-Dist: mkdocs-material>=9.6; extra == "dev"
|
|
54
|
+
Requires-Dist: mypy>=2.3; extra == "dev"
|
|
55
|
+
Requires-Dist: pandas-stubs>=2.2; extra == "dev"
|
|
56
|
+
Requires-Dist: pip-audit>=2.8; extra == "dev"
|
|
57
|
+
Requires-Dist: pre-commit>=4.1; extra == "dev"
|
|
58
|
+
Requires-Dist: pytest>=9.0; extra == "dev"
|
|
59
|
+
Requires-Dist: pytest-cov>=6.0; extra == "dev"
|
|
60
|
+
Requires-Dist: ruff>=0.16; extra == "dev"
|
|
61
|
+
Dynamic: license-file
|
|
62
|
+
|
|
63
|
+
# PortGuard-AIS
|
|
64
|
+
|
|
65
|
+
[](https://github.com/TyMill/PortGuard-AIS/actions/workflows/ci.yml)
|
|
66
|
+
|
|
67
|
+
[](https://www.python.org/)
|
|
68
|
+
[](https://docs.astral.sh/ruff/)
|
|
69
|
+
[](LICENSE)
|
|
70
|
+
[](https://doi.org/10.5281/zenodo.21871438)
|
|
71
|
+
|
|
72
|
+
**PortGuard-AIS** is a modular Python 3.13 framework for explainable collision-risk
|
|
73
|
+
assessment, vessel-encounter classification, near-miss mining, and stateful alerts from AIS data.
|
|
74
|
+
It is intended for restricted port waters, approaches, anchorages, and other traffic-dense areas.
|
|
75
|
+
|
|
76
|
+
## Scientific scope
|
|
77
|
+
|
|
78
|
+
PortGuard-AIS answers four operational questions:
|
|
79
|
+
|
|
80
|
+
1. Which vessel pairs are on potentially conflicting motion vectors?
|
|
81
|
+
2. What encounter geometry is present and what COLREG context applies?
|
|
82
|
+
3. How severe and how immediate is the risk?
|
|
83
|
+
4. Why was an alert emitted, suppressed, escalated, or resolved?
|
|
84
|
+
|
|
85
|
+
The project deliberately **does not design fairways, generate routes, optimize waterways,
|
|
86
|
+
create waypoints, or prescribe autonomous avoidance trajectories**.
|
|
87
|
+
|
|
88
|
+
## Features
|
|
89
|
+
|
|
90
|
+
- validated AIS input model, configurable cleaning and kinematic anomaly detection;
|
|
91
|
+
- snapshot and historical processing;
|
|
92
|
+
- pairwise spatial pre-filtering;
|
|
93
|
+
- CPA/TCPA and relative-motion geometry;
|
|
94
|
+
- head-on, crossing, overtaking, being-overtaken, parallel and indeterminate classes;
|
|
95
|
+
- rule-context mapping for COLREG Rules 13–17;
|
|
96
|
+
- speed- and length-aware elliptical vessel domain;
|
|
97
|
+
- transparent multi-component collision-risk score;
|
|
98
|
+
- alert lifecycle with hysteresis, persistence, cooldown and deduplication;
|
|
99
|
+
- explicit machine-readable rationale for every assessment;
|
|
100
|
+
- historical near-miss event mining, risk trends and spatial hotspot aggregation;
|
|
101
|
+
- CSV, JSON, GeoJSON and standalone HTML reporting;
|
|
102
|
+
- Typer CLI, MkDocs documentation, strict mypy, Ruff, pytest and GitHub Actions.
|
|
103
|
+
|
|
104
|
+
## Installation
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
python3.13 -m venv .venv
|
|
108
|
+
source .venv/bin/activate
|
|
109
|
+
python -m pip install -e ".[viz]"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
For development:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
python -m pip install -e ".[dev,viz]"
|
|
116
|
+
pre-commit install
|
|
117
|
+
make quality
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Using `uv`:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
uv sync --all-extras
|
|
124
|
+
uv run portguard-ais validate examples/data/sample_ais.csv
|
|
125
|
+
uv run portguard-ais assess examples/data/sample_ais.csv --output-dir outputs
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Python API
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from portguard_ais.config import PortGuardConfig
|
|
132
|
+
from portguard_ais.pipeline import PortGuardPipeline
|
|
133
|
+
|
|
134
|
+
pipeline = PortGuardPipeline(PortGuardConfig())
|
|
135
|
+
result = pipeline.process_csv("examples/data/sample_ais.csv")
|
|
136
|
+
|
|
137
|
+
print(result.assessments[0].model_dump(mode="json"))
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## CLI
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
portguard-ais validate INPUT.csv
|
|
144
|
+
portguard-ais assess INPUT.csv --output-dir outputs
|
|
145
|
+
portguard-ais near-misses INPUT.csv --output outputs/near_misses.csv
|
|
146
|
+
portguard-ais synthetic --output examples/data/generated_scenarios.csv
|
|
147
|
+
portguard-ais benchmark --steps 12
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Input schema
|
|
151
|
+
|
|
152
|
+
Required columns:
|
|
153
|
+
|
|
154
|
+
| Column | Meaning | Unit |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| `timestamp` | timezone-aware observation time | ISO 8601 |
|
|
157
|
+
| `mmsi` | Maritime Mobile Service Identity | integer |
|
|
158
|
+
| `lat` | latitude | decimal degrees |
|
|
159
|
+
| `lon` | longitude | decimal degrees |
|
|
160
|
+
| `sog` | speed over ground | knots |
|
|
161
|
+
| `cog` | course over ground | degrees, true |
|
|
162
|
+
|
|
163
|
+
Optional columns include `heading`, `rot`, `length_m`, `beam_m`, `vessel_type`,
|
|
164
|
+
`position_accuracy_m`, and `source`.
|
|
165
|
+
|
|
166
|
+
## Repository quality gates
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
make format-check
|
|
170
|
+
make lint
|
|
171
|
+
make typecheck
|
|
172
|
+
make test
|
|
173
|
+
make audit
|
|
174
|
+
make build
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Safety notice
|
|
178
|
+
|
|
179
|
+
PortGuard-AIS is research and decision-support software. It is not certified navigational
|
|
180
|
+
equipment and must not replace COLREG-compliant watchkeeping, VTS procedures, bridge systems,
|
|
181
|
+
or the judgement of qualified maritime personnel.
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT. See [LICENSE](LICENSE).
|
|
186
|
+
|
|
187
|
+
## SoftwareX reproducibility suite
|
|
188
|
+
|
|
189
|
+
The publication-oriented benchmark is intentionally separate from the legacy four-vessel
|
|
190
|
+
regression dataset. It contains three spatially isolated and physically consistent encounter
|
|
191
|
+
pairs so that each expected geometry can be evaluated without cross-scenario pairing:
|
|
192
|
+
|
|
193
|
+
- `head-on` - reciprocal courses, COLREG Rule 14 context;
|
|
194
|
+
- `crossing` - target on the own vessel's starboard side, Rule 15 context;
|
|
195
|
+
- `overtaking` - faster own vessel approaching from abaft the target's beam, Rule 13 context.
|
|
196
|
+
|
|
197
|
+
Generate the dataset and compact benchmark directly from the CLI:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
portguard-ais article-data --steps 12 --interval-seconds 30 --output article_scenarios.csv
|
|
201
|
+
portguard-ais article-benchmark --steps 12 --interval-seconds 30
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Generate the complete SoftwareX evidence pack, including CSV/JSON/GeoJSON exports, the HTML
|
|
205
|
+
report, manuscript-ready scenario table, encounter figures and the stateful risk timeline:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
python examples/softwarex_article_run.py
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
For a clean development environment that also executes Ruff, strict mypy, pytest, package build
|
|
212
|
+
and dependency audit, use:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
bash scripts/run_softwarex_article.sh
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
The reference run is written to `article_run_v1/`. Classification consistency reported by this
|
|
219
|
+
suite is a deterministic regression check against controlled scenario geometry; it is **not** a
|
|
220
|
+
claim of real-world classifier accuracy.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# PortGuard-AIS
|
|
2
|
+
|
|
3
|
+
[](https://github.com/TyMill/PortGuard-AIS/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/)
|
|
6
|
+
[](https://docs.astral.sh/ruff/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://doi.org/10.5281/zenodo.21871438)
|
|
9
|
+
|
|
10
|
+
**PortGuard-AIS** is a modular Python 3.13 framework for explainable collision-risk
|
|
11
|
+
assessment, vessel-encounter classification, near-miss mining, and stateful alerts from AIS data.
|
|
12
|
+
It is intended for restricted port waters, approaches, anchorages, and other traffic-dense areas.
|
|
13
|
+
|
|
14
|
+
## Scientific scope
|
|
15
|
+
|
|
16
|
+
PortGuard-AIS answers four operational questions:
|
|
17
|
+
|
|
18
|
+
1. Which vessel pairs are on potentially conflicting motion vectors?
|
|
19
|
+
2. What encounter geometry is present and what COLREG context applies?
|
|
20
|
+
3. How severe and how immediate is the risk?
|
|
21
|
+
4. Why was an alert emitted, suppressed, escalated, or resolved?
|
|
22
|
+
|
|
23
|
+
The project deliberately **does not design fairways, generate routes, optimize waterways,
|
|
24
|
+
create waypoints, or prescribe autonomous avoidance trajectories**.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- validated AIS input model, configurable cleaning and kinematic anomaly detection;
|
|
29
|
+
- snapshot and historical processing;
|
|
30
|
+
- pairwise spatial pre-filtering;
|
|
31
|
+
- CPA/TCPA and relative-motion geometry;
|
|
32
|
+
- head-on, crossing, overtaking, being-overtaken, parallel and indeterminate classes;
|
|
33
|
+
- rule-context mapping for COLREG Rules 13–17;
|
|
34
|
+
- speed- and length-aware elliptical vessel domain;
|
|
35
|
+
- transparent multi-component collision-risk score;
|
|
36
|
+
- alert lifecycle with hysteresis, persistence, cooldown and deduplication;
|
|
37
|
+
- explicit machine-readable rationale for every assessment;
|
|
38
|
+
- historical near-miss event mining, risk trends and spatial hotspot aggregation;
|
|
39
|
+
- CSV, JSON, GeoJSON and standalone HTML reporting;
|
|
40
|
+
- Typer CLI, MkDocs documentation, strict mypy, Ruff, pytest and GitHub Actions.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python3.13 -m venv .venv
|
|
46
|
+
source .venv/bin/activate
|
|
47
|
+
python -m pip install -e ".[viz]"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For development:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
python -m pip install -e ".[dev,viz]"
|
|
54
|
+
pre-commit install
|
|
55
|
+
make quality
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Using `uv`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uv sync --all-extras
|
|
62
|
+
uv run portguard-ais validate examples/data/sample_ais.csv
|
|
63
|
+
uv run portguard-ais assess examples/data/sample_ais.csv --output-dir outputs
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Python API
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from portguard_ais.config import PortGuardConfig
|
|
70
|
+
from portguard_ais.pipeline import PortGuardPipeline
|
|
71
|
+
|
|
72
|
+
pipeline = PortGuardPipeline(PortGuardConfig())
|
|
73
|
+
result = pipeline.process_csv("examples/data/sample_ais.csv")
|
|
74
|
+
|
|
75
|
+
print(result.assessments[0].model_dump(mode="json"))
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## CLI
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
portguard-ais validate INPUT.csv
|
|
82
|
+
portguard-ais assess INPUT.csv --output-dir outputs
|
|
83
|
+
portguard-ais near-misses INPUT.csv --output outputs/near_misses.csv
|
|
84
|
+
portguard-ais synthetic --output examples/data/generated_scenarios.csv
|
|
85
|
+
portguard-ais benchmark --steps 12
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Input schema
|
|
89
|
+
|
|
90
|
+
Required columns:
|
|
91
|
+
|
|
92
|
+
| Column | Meaning | Unit |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `timestamp` | timezone-aware observation time | ISO 8601 |
|
|
95
|
+
| `mmsi` | Maritime Mobile Service Identity | integer |
|
|
96
|
+
| `lat` | latitude | decimal degrees |
|
|
97
|
+
| `lon` | longitude | decimal degrees |
|
|
98
|
+
| `sog` | speed over ground | knots |
|
|
99
|
+
| `cog` | course over ground | degrees, true |
|
|
100
|
+
|
|
101
|
+
Optional columns include `heading`, `rot`, `length_m`, `beam_m`, `vessel_type`,
|
|
102
|
+
`position_accuracy_m`, and `source`.
|
|
103
|
+
|
|
104
|
+
## Repository quality gates
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
make format-check
|
|
108
|
+
make lint
|
|
109
|
+
make typecheck
|
|
110
|
+
make test
|
|
111
|
+
make audit
|
|
112
|
+
make build
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Safety notice
|
|
116
|
+
|
|
117
|
+
PortGuard-AIS is research and decision-support software. It is not certified navigational
|
|
118
|
+
equipment and must not replace COLREG-compliant watchkeeping, VTS procedures, bridge systems,
|
|
119
|
+
or the judgement of qualified maritime personnel.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT. See [LICENSE](LICENSE).
|
|
124
|
+
|
|
125
|
+
## SoftwareX reproducibility suite
|
|
126
|
+
|
|
127
|
+
The publication-oriented benchmark is intentionally separate from the legacy four-vessel
|
|
128
|
+
regression dataset. It contains three spatially isolated and physically consistent encounter
|
|
129
|
+
pairs so that each expected geometry can be evaluated without cross-scenario pairing:
|
|
130
|
+
|
|
131
|
+
- `head-on` - reciprocal courses, COLREG Rule 14 context;
|
|
132
|
+
- `crossing` - target on the own vessel's starboard side, Rule 15 context;
|
|
133
|
+
- `overtaking` - faster own vessel approaching from abaft the target's beam, Rule 13 context.
|
|
134
|
+
|
|
135
|
+
Generate the dataset and compact benchmark directly from the CLI:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
portguard-ais article-data --steps 12 --interval-seconds 30 --output article_scenarios.csv
|
|
139
|
+
portguard-ais article-benchmark --steps 12 --interval-seconds 30
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Generate the complete SoftwareX evidence pack, including CSV/JSON/GeoJSON exports, the HTML
|
|
143
|
+
report, manuscript-ready scenario table, encounter figures and the stateful risk timeline:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
python examples/softwarex_article_run.py
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
For a clean development environment that also executes Ruff, strict mypy, pytest, package build
|
|
150
|
+
and dependency audit, use:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
bash scripts/run_softwarex_article.sh
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The reference run is written to `article_run_v1/`. Classification consistency reported by this
|
|
157
|
+
suite is a deterministic regression check against controlled scenario geometry; it is **not** a
|
|
158
|
+
claim of real-world classifier accuracy.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=75"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "portguard-ais"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Explainable collision-risk alerts and vessel-encounter analytics for restricted port waters."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.13"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Irmina Durlik" },
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
keywords = ["AIS", "maritime safety", "collision risk", "COLREG", "near miss"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 5 - Production/Stable",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"numpy>=2.1",
|
|
28
|
+
"pandas>=2.2",
|
|
29
|
+
"pydantic>=2.10",
|
|
30
|
+
"rich>=13.9",
|
|
31
|
+
"typer>=0.15",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
viz = ["matplotlib>=3.9"]
|
|
36
|
+
dev = [
|
|
37
|
+
"build>=1.2",
|
|
38
|
+
"hypothesis>=6.120",
|
|
39
|
+
"mkdocs>=1.6",
|
|
40
|
+
"mkdocs-material>=9.6",
|
|
41
|
+
"mypy>=2.3",
|
|
42
|
+
"pandas-stubs>=2.2",
|
|
43
|
+
"pip-audit>=2.8",
|
|
44
|
+
"pre-commit>=4.1",
|
|
45
|
+
"pytest>=9.0",
|
|
46
|
+
"pytest-cov>=6.0",
|
|
47
|
+
"ruff>=0.16",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.scripts]
|
|
51
|
+
portguard-ais = "portguard_ais.cli:app"
|
|
52
|
+
|
|
53
|
+
[project.urls]
|
|
54
|
+
Documentation = "https://github.com/irmina-d/PortGuard-AIS#readme"
|
|
55
|
+
Issues = "https://github.com/irmina-d/PortGuard-AIS/issues"
|
|
56
|
+
Source = "https://github.com/irmina-d/PortGuard-AIS"
|
|
57
|
+
|
|
58
|
+
[tool.setuptools.packages.find]
|
|
59
|
+
where = ["src"]
|
|
60
|
+
|
|
61
|
+
[tool.setuptools.package-data]
|
|
62
|
+
portguard_ais = ["py.typed"]
|
|
63
|
+
|
|
64
|
+
[tool.ruff]
|
|
65
|
+
target-version = "py313"
|
|
66
|
+
line-length = 100
|
|
67
|
+
src = ["src", "tests"]
|
|
68
|
+
|
|
69
|
+
[tool.ruff.lint]
|
|
70
|
+
select = [
|
|
71
|
+
"E", "F", "W", "I", "B", "UP", "SIM", "RUF", "N", "PTH", "DTZ",
|
|
72
|
+
]
|
|
73
|
+
ignore = ["E501"]
|
|
74
|
+
|
|
75
|
+
[tool.ruff.lint.per-file-ignores]
|
|
76
|
+
"tests/**/*.py" = ["S101"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.format]
|
|
79
|
+
docstring-code-format = true
|
|
80
|
+
quote-style = "double"
|
|
81
|
+
|
|
82
|
+
[tool.pytest.ini_options]
|
|
83
|
+
minversion = "9.0"
|
|
84
|
+
addopts = "-ra --strict-config --strict-markers --cov=portguard_ais --cov-report=term-missing --cov-fail-under=85"
|
|
85
|
+
testpaths = ["tests"]
|
|
86
|
+
markers = [
|
|
87
|
+
"integration: end-to-end or filesystem integration tests",
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
[tool.coverage.run]
|
|
91
|
+
branch = true
|
|
92
|
+
source = ["portguard_ais"]
|
|
93
|
+
|
|
94
|
+
[tool.coverage.report]
|
|
95
|
+
show_missing = true
|
|
96
|
+
skip_covered = true
|
|
97
|
+
exclude_also = [
|
|
98
|
+
"if TYPE_CHECKING:",
|
|
99
|
+
"if __name__ == .__main__.:",
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
[tool.mypy]
|
|
103
|
+
python_version = "3.13"
|
|
104
|
+
packages = ["portguard_ais"]
|
|
105
|
+
strict = true
|
|
106
|
+
warn_unreachable = true
|
|
107
|
+
show_error_codes = true
|
|
108
|
+
pretty = true
|
|
109
|
+
|
|
110
|
+
[[tool.mypy.overrides]]
|
|
111
|
+
module = ["matplotlib.*"]
|
|
112
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""PortGuard-AIS public package interface."""
|
|
2
|
+
|
|
3
|
+
from portguard_ais.config import PortGuardConfig
|
|
4
|
+
from portguard_ais.models import EncounterAssessment, VesselObservation
|
|
5
|
+
from portguard_ais.pipeline import PortGuardPipeline, ProcessingResult
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"EncounterAssessment",
|
|
9
|
+
"PortGuardConfig",
|
|
10
|
+
"PortGuardPipeline",
|
|
11
|
+
"ProcessingResult",
|
|
12
|
+
"VesselObservation",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Explainable alert generation and lifecycle management."""
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Deterministic, machine-readable alert rationale."""
|
|
2
|
+
|
|
3
|
+
from portguard_ais.enums import EncounterType, RiskLevel
|
|
4
|
+
from portguard_ais.models import DomainAssessment, RelativeMotion, RiskComponents
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def build_rationale(
|
|
8
|
+
encounter_type: EncounterType,
|
|
9
|
+
level: RiskLevel,
|
|
10
|
+
motion: RelativeMotion,
|
|
11
|
+
domain: DomainAssessment,
|
|
12
|
+
components: RiskComponents,
|
|
13
|
+
) -> tuple[str, ...]:
|
|
14
|
+
"""Explain the principal physical and model factors behind an assessment."""
|
|
15
|
+
reasons = [f"encounter geometry classified as {encounter_type.value}"]
|
|
16
|
+
if not motion.converging:
|
|
17
|
+
reasons.append("relative motion is not converging")
|
|
18
|
+
if motion.tcpa_min <= 10.0 and motion.converging:
|
|
19
|
+
reasons.append("closest point of approach is expected within 10 minutes")
|
|
20
|
+
if motion.dcpa_nm < 0.5:
|
|
21
|
+
reasons.append("predicted closest passing distance is below 0.5 nautical miles")
|
|
22
|
+
if motion.current_distance_nm < 1.0:
|
|
23
|
+
reasons.append("current separation is below 1 nautical mile")
|
|
24
|
+
if domain.violated:
|
|
25
|
+
reasons.append("predicted CPA enters the configured own-vessel domain")
|
|
26
|
+
dominant_name, dominant_value = max(
|
|
27
|
+
components.model_dump().items(),
|
|
28
|
+
key=lambda item: item[1],
|
|
29
|
+
)
|
|
30
|
+
reasons.append(f"dominant normalized risk component is {dominant_name} ({dominant_value:.3f})")
|
|
31
|
+
if level in {RiskLevel.WARNING, RiskLevel.CRITICAL}:
|
|
32
|
+
reasons.append(f"combined score exceeds the {level.value} threshold")
|
|
33
|
+
return tuple(reasons)
|