dynos-adaptive-resampling 0.1.2__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.
- dynos_adaptive_resampling-0.1.2/PKG-INFO +190 -0
- dynos_adaptive_resampling-0.1.2/README.md +177 -0
- dynos_adaptive_resampling-0.1.2/pyproject.toml +22 -0
- dynos_adaptive_resampling-0.1.2/setup.cfg +4 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling/__init__.py +8 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling/domain.py +40 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling/mission.py +52 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling/resampler.py +146 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling/runnable.py +41 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling.egg-info/PKG-INFO +190 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling.egg-info/SOURCES.txt +13 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling.egg-info/dependency_links.txt +1 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling.egg-info/requires.txt +6 -0
- dynos_adaptive_resampling-0.1.2/src/dynos_adaptive_resampling.egg-info/top_level.txt +1 -0
- dynos_adaptive_resampling-0.1.2/tests/test_resampler.py +71 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dynos-adaptive-resampling
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Adaptive resampling extension for DYNOS Sentry surveys
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: dynos-client>=0.1.2
|
|
9
|
+
Requires-Dist: dynos-sentry-domain==0.1.2
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest; extra == "dev"
|
|
13
|
+
|
|
14
|
+
# dynos-adaptive-resampling
|
|
15
|
+
|
|
16
|
+
A worked example: chain an ML-driven resampling step onto a Sentry survey. This
|
|
17
|
+
package is scaffolding: it ships a stub `AdaptiveResampler` that you
|
|
18
|
+
replace with your model, plus the wiring (`runnable.py`, `mission.py`) that
|
|
19
|
+
lets `dynos connect` find it and that lets the planner sequence "survey,
|
|
20
|
+
resample, resurvey".
|
|
21
|
+
|
|
22
|
+
The package contributes one new transition (`resample_zone`) and one new
|
|
23
|
+
mission template (`build_resample_mission`). Everything else is for you to
|
|
24
|
+
edit.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
You will be modifying the source, so install editable:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install -e dynos-adaptive-resampling
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This pulls in `dynos-client`, `dynos-sentry-domain`, and `numpy`.
|
|
35
|
+
|
|
36
|
+
## What's in this repository
|
|
37
|
+
|
|
38
|
+
### `domain.py`
|
|
39
|
+
|
|
40
|
+
Declares `resample_zone` (transition), `ResampleZoneParams` (its parameter
|
|
41
|
+
dataclass), `resampling_complete` (a fluent the transition adds). Edit if
|
|
42
|
+
you need new fluents or parameters.
|
|
43
|
+
|
|
44
|
+
### `resampler.py`
|
|
45
|
+
|
|
46
|
+
Provides `AdaptiveResampler` class with `@Action(transition=resample_zone)`.
|
|
47
|
+
Edit `_gather_historic_data` and `_predict_new_zone` or whatever else you
|
|
48
|
+
need to get your model integrated.
|
|
49
|
+
|
|
50
|
+
### `mission.py`
|
|
51
|
+
|
|
52
|
+
Provides `build_resample_mission(zone_name)` returns a `Mission` that does
|
|
53
|
+
survey, resample, resurvey. Edit If you want a different sequence.
|
|
54
|
+
|
|
55
|
+
### `runnable.py`
|
|
56
|
+
|
|
57
|
+
Provides `AdaptiveResamplingNode`, the `dynos connect`-compatible entry point.
|
|
58
|
+
You probably don't need to edit this.
|
|
59
|
+
|
|
60
|
+
## How the round-trip works
|
|
61
|
+
|
|
62
|
+
1. You launch the resampler as a servant: `dynos connect
|
|
63
|
+
dynos_adaptive_resampling.runnable:AdaptiveResamplingNode`. The servant
|
|
64
|
+
idles, polling the backend for assignments.
|
|
65
|
+
2. From a second terminal you build the mission and call `execute_blocks`. The
|
|
66
|
+
first plan block surveys the source zone end-to-end.
|
|
67
|
+
3. The planner reaches `resample_zone(source_zone=site_alpha)`. It dispatches
|
|
68
|
+
the assignment over HTTP to your servant.
|
|
69
|
+
4. Your `AdaptiveResampler` runs `_gather_historic_data`, then
|
|
70
|
+
`_predict_new_zone`, then writes the resulting `ZoneProposal` back as a new
|
|
71
|
+
`Zone` object on the backend.
|
|
72
|
+
5. The next plan block surveys the new zone. The mission ends with abort +
|
|
73
|
+
recover.
|
|
74
|
+
|
|
75
|
+
## Replacing the stub
|
|
76
|
+
|
|
77
|
+
You will edit two methods in `resampler.py`:
|
|
78
|
+
|
|
79
|
+
`_gather_historic_data(zone_name)`: return whatever your model needs. The
|
|
80
|
+
shipped stub returns an empty dict; you replace it with calls to a shared
|
|
81
|
+
database, ROS bag, the backend API (`orch.get_objects(type="zone")`), an
|
|
82
|
+
offline NetCDF, etc.
|
|
83
|
+
|
|
84
|
+
`_predict_new_zone(historic_data)`: return a `ZoneProposal` with
|
|
85
|
+
`vertices`, `altitude`, `speed`, and `confidence`:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
def _predict_new_zone(self, historic_data):
|
|
89
|
+
features = self._extract_features(historic_data["sonar_readings"])
|
|
90
|
+
prediction = self._model.predict(features)
|
|
91
|
+
return ZoneProposal(
|
|
92
|
+
vertices=self._prediction_to_polygon(prediction),
|
|
93
|
+
altitude=70.0,
|
|
94
|
+
speed=0.8,
|
|
95
|
+
confidence=float(prediction.confidence),
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
You can add fields to `ResampleZoneParams` (e.g. a confidence threshold, or
|
|
100
|
+
whatever else you want), but don't change the `Zone` parameter: the backend's
|
|
101
|
+
coverage planner reads `Zone.vertices`, `Zone.coverage_width`, etc. to draw
|
|
102
|
+
tracklines, and it expects the public schema.
|
|
103
|
+
|
|
104
|
+
## Test offline
|
|
105
|
+
|
|
106
|
+
Before pointing at the real backend, run the package's own tests:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install -e "dynos-adaptive-resampling/[dev]"
|
|
110
|
+
pytest dynos-adaptive-resampling/tests/ -v
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
These exercise `_gather_historic_data` and `_predict_new_zone` against a stub
|
|
114
|
+
backend. No network or session needed.
|
|
115
|
+
|
|
116
|
+
## Run it for real
|
|
117
|
+
|
|
118
|
+
Two terminals.
|
|
119
|
+
|
|
120
|
+
Terminal 1 is your resampler. This can be your laptop, a lab server, or the
|
|
121
|
+
same machine as the backend; the backend dispatches each assignment to
|
|
122
|
+
whichever servant is currently registered for `resample_zone`.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
dynos login # logins persist across terminals but expire after an hour
|
|
126
|
+
dynos session create
|
|
127
|
+
dynos connect dynos_adaptive_resampling.runnable:AdaptiveResamplingNode
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Leave it running. It executes `resample_zone` whenever the backend reaches that
|
|
131
|
+
step.
|
|
132
|
+
|
|
133
|
+
Terminal 2 is mission. Create the source zone and run the adaptive mission:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
dynos call create zone.json
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from dynos_client import RemoteOrchestrator
|
|
141
|
+
from dynos_adaptive_resampling.mission import build_resample_mission
|
|
142
|
+
|
|
143
|
+
orch = RemoteOrchestrator.from_config(timeout_s=3600)
|
|
144
|
+
results = orch.execute_blocks(build_resample_mission("site_alpha"))
|
|
145
|
+
for r in results:
|
|
146
|
+
print(r)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
While it runs, monitor from a third terminal:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
dynos call state --scope public # current symbolic state, pruned only for the symbols you're expecting
|
|
153
|
+
dynos call goal # current goal
|
|
154
|
+
dynos call objects --type zone # source + proposed zones
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## What the mission does, step by step
|
|
158
|
+
|
|
159
|
+
1. Init. Takeover, descent, mode setup.
|
|
160
|
+
2. Survey the source zone (`full_coverage_of(site_alpha)`).
|
|
161
|
+
3. Resample. Plan dispatches `resample_zone(source_zone=site_alpha)` to your servant; your model creates `resampled_site_alpha`.
|
|
162
|
+
4. Resurvey. `full_coverage_of(resampled_site_alpha)`.
|
|
163
|
+
5. Recover. Abort and ascend.
|
|
164
|
+
|
|
165
|
+
## Public API
|
|
166
|
+
|
|
167
|
+
| Symbol | From | Purpose |
|
|
168
|
+
|-------------------------------------|---------------------------------------|------------------------------------------------|
|
|
169
|
+
| `resample_zone` | `dynos_adaptive_resampling.domain` | The transition that fires your `@Action`. |
|
|
170
|
+
| `ResampleZoneParams` | `dynos_adaptive_resampling.domain` | Its parameter dataclass (`source_zone: Zone`). |
|
|
171
|
+
| `resampling_complete` | `dynos_adaptive_resampling.domain` | Fluent the transition adds. |
|
|
172
|
+
| `AdaptiveResampler` | `dynos_adaptive_resampling.resampler` | The class you edit. |
|
|
173
|
+
| `AdaptiveResamplingNode` | `dynos_adaptive_resampling.runnable` | The `dynos connect` entry point. |
|
|
174
|
+
| `build_resample_mission(zone_name)` | `dynos_adaptive_resampling.mission` | Survey, resample, resurvey. |
|
|
175
|
+
|
|
176
|
+
## Troubleshooting
|
|
177
|
+
|
|
178
|
+
Resampler never gets an assignment: The mission hasn't reached `resample_zone`
|
|
179
|
+
yet. Check `dynos call state --scope public`.
|
|
180
|
+
|
|
181
|
+
`No plan found`: The source zone doesn't exist, has no `vertices`, or has
|
|
182
|
+
`coverage_width <= 0`. Check `dynos call objects --type zone`.
|
|
183
|
+
|
|
184
|
+
Resurvey failed: The proposed zone is missing fields. `resampled_*` needs
|
|
185
|
+
`vertices` (3+), `coverage_width > 0`, `robot_width > 0`, and
|
|
186
|
+
`coordinate_frame`. The `ZoneProposal` dataclass populates these; if you
|
|
187
|
+
bypassed it, double-check.
|
|
188
|
+
|
|
189
|
+
For cross-package issues (login, session, connection), see `user_guide.md` or
|
|
190
|
+
`dynos-client`'s README.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# dynos-adaptive-resampling
|
|
2
|
+
|
|
3
|
+
A worked example: chain an ML-driven resampling step onto a Sentry survey. This
|
|
4
|
+
package is scaffolding: it ships a stub `AdaptiveResampler` that you
|
|
5
|
+
replace with your model, plus the wiring (`runnable.py`, `mission.py`) that
|
|
6
|
+
lets `dynos connect` find it and that lets the planner sequence "survey,
|
|
7
|
+
resample, resurvey".
|
|
8
|
+
|
|
9
|
+
The package contributes one new transition (`resample_zone`) and one new
|
|
10
|
+
mission template (`build_resample_mission`). Everything else is for you to
|
|
11
|
+
edit.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
You will be modifying the source, so install editable:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install -e dynos-adaptive-resampling
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This pulls in `dynos-client`, `dynos-sentry-domain`, and `numpy`.
|
|
22
|
+
|
|
23
|
+
## What's in this repository
|
|
24
|
+
|
|
25
|
+
### `domain.py`
|
|
26
|
+
|
|
27
|
+
Declares `resample_zone` (transition), `ResampleZoneParams` (its parameter
|
|
28
|
+
dataclass), `resampling_complete` (a fluent the transition adds). Edit if
|
|
29
|
+
you need new fluents or parameters.
|
|
30
|
+
|
|
31
|
+
### `resampler.py`
|
|
32
|
+
|
|
33
|
+
Provides `AdaptiveResampler` class with `@Action(transition=resample_zone)`.
|
|
34
|
+
Edit `_gather_historic_data` and `_predict_new_zone` or whatever else you
|
|
35
|
+
need to get your model integrated.
|
|
36
|
+
|
|
37
|
+
### `mission.py`
|
|
38
|
+
|
|
39
|
+
Provides `build_resample_mission(zone_name)` returns a `Mission` that does
|
|
40
|
+
survey, resample, resurvey. Edit If you want a different sequence.
|
|
41
|
+
|
|
42
|
+
### `runnable.py`
|
|
43
|
+
|
|
44
|
+
Provides `AdaptiveResamplingNode`, the `dynos connect`-compatible entry point.
|
|
45
|
+
You probably don't need to edit this.
|
|
46
|
+
|
|
47
|
+
## How the round-trip works
|
|
48
|
+
|
|
49
|
+
1. You launch the resampler as a servant: `dynos connect
|
|
50
|
+
dynos_adaptive_resampling.runnable:AdaptiveResamplingNode`. The servant
|
|
51
|
+
idles, polling the backend for assignments.
|
|
52
|
+
2. From a second terminal you build the mission and call `execute_blocks`. The
|
|
53
|
+
first plan block surveys the source zone end-to-end.
|
|
54
|
+
3. The planner reaches `resample_zone(source_zone=site_alpha)`. It dispatches
|
|
55
|
+
the assignment over HTTP to your servant.
|
|
56
|
+
4. Your `AdaptiveResampler` runs `_gather_historic_data`, then
|
|
57
|
+
`_predict_new_zone`, then writes the resulting `ZoneProposal` back as a new
|
|
58
|
+
`Zone` object on the backend.
|
|
59
|
+
5. The next plan block surveys the new zone. The mission ends with abort +
|
|
60
|
+
recover.
|
|
61
|
+
|
|
62
|
+
## Replacing the stub
|
|
63
|
+
|
|
64
|
+
You will edit two methods in `resampler.py`:
|
|
65
|
+
|
|
66
|
+
`_gather_historic_data(zone_name)`: return whatever your model needs. The
|
|
67
|
+
shipped stub returns an empty dict; you replace it with calls to a shared
|
|
68
|
+
database, ROS bag, the backend API (`orch.get_objects(type="zone")`), an
|
|
69
|
+
offline NetCDF, etc.
|
|
70
|
+
|
|
71
|
+
`_predict_new_zone(historic_data)`: return a `ZoneProposal` with
|
|
72
|
+
`vertices`, `altitude`, `speed`, and `confidence`:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
def _predict_new_zone(self, historic_data):
|
|
76
|
+
features = self._extract_features(historic_data["sonar_readings"])
|
|
77
|
+
prediction = self._model.predict(features)
|
|
78
|
+
return ZoneProposal(
|
|
79
|
+
vertices=self._prediction_to_polygon(prediction),
|
|
80
|
+
altitude=70.0,
|
|
81
|
+
speed=0.8,
|
|
82
|
+
confidence=float(prediction.confidence),
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
You can add fields to `ResampleZoneParams` (e.g. a confidence threshold, or
|
|
87
|
+
whatever else you want), but don't change the `Zone` parameter: the backend's
|
|
88
|
+
coverage planner reads `Zone.vertices`, `Zone.coverage_width`, etc. to draw
|
|
89
|
+
tracklines, and it expects the public schema.
|
|
90
|
+
|
|
91
|
+
## Test offline
|
|
92
|
+
|
|
93
|
+
Before pointing at the real backend, run the package's own tests:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install -e "dynos-adaptive-resampling/[dev]"
|
|
97
|
+
pytest dynos-adaptive-resampling/tests/ -v
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
These exercise `_gather_historic_data` and `_predict_new_zone` against a stub
|
|
101
|
+
backend. No network or session needed.
|
|
102
|
+
|
|
103
|
+
## Run it for real
|
|
104
|
+
|
|
105
|
+
Two terminals.
|
|
106
|
+
|
|
107
|
+
Terminal 1 is your resampler. This can be your laptop, a lab server, or the
|
|
108
|
+
same machine as the backend; the backend dispatches each assignment to
|
|
109
|
+
whichever servant is currently registered for `resample_zone`.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
dynos login # logins persist across terminals but expire after an hour
|
|
113
|
+
dynos session create
|
|
114
|
+
dynos connect dynos_adaptive_resampling.runnable:AdaptiveResamplingNode
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Leave it running. It executes `resample_zone` whenever the backend reaches that
|
|
118
|
+
step.
|
|
119
|
+
|
|
120
|
+
Terminal 2 is mission. Create the source zone and run the adaptive mission:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
dynos call create zone.json
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from dynos_client import RemoteOrchestrator
|
|
128
|
+
from dynos_adaptive_resampling.mission import build_resample_mission
|
|
129
|
+
|
|
130
|
+
orch = RemoteOrchestrator.from_config(timeout_s=3600)
|
|
131
|
+
results = orch.execute_blocks(build_resample_mission("site_alpha"))
|
|
132
|
+
for r in results:
|
|
133
|
+
print(r)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
While it runs, monitor from a third terminal:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
dynos call state --scope public # current symbolic state, pruned only for the symbols you're expecting
|
|
140
|
+
dynos call goal # current goal
|
|
141
|
+
dynos call objects --type zone # source + proposed zones
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## What the mission does, step by step
|
|
145
|
+
|
|
146
|
+
1. Init. Takeover, descent, mode setup.
|
|
147
|
+
2. Survey the source zone (`full_coverage_of(site_alpha)`).
|
|
148
|
+
3. Resample. Plan dispatches `resample_zone(source_zone=site_alpha)` to your servant; your model creates `resampled_site_alpha`.
|
|
149
|
+
4. Resurvey. `full_coverage_of(resampled_site_alpha)`.
|
|
150
|
+
5. Recover. Abort and ascend.
|
|
151
|
+
|
|
152
|
+
## Public API
|
|
153
|
+
|
|
154
|
+
| Symbol | From | Purpose |
|
|
155
|
+
|-------------------------------------|---------------------------------------|------------------------------------------------|
|
|
156
|
+
| `resample_zone` | `dynos_adaptive_resampling.domain` | The transition that fires your `@Action`. |
|
|
157
|
+
| `ResampleZoneParams` | `dynos_adaptive_resampling.domain` | Its parameter dataclass (`source_zone: Zone`). |
|
|
158
|
+
| `resampling_complete` | `dynos_adaptive_resampling.domain` | Fluent the transition adds. |
|
|
159
|
+
| `AdaptiveResampler` | `dynos_adaptive_resampling.resampler` | The class you edit. |
|
|
160
|
+
| `AdaptiveResamplingNode` | `dynos_adaptive_resampling.runnable` | The `dynos connect` entry point. |
|
|
161
|
+
| `build_resample_mission(zone_name)` | `dynos_adaptive_resampling.mission` | Survey, resample, resurvey. |
|
|
162
|
+
|
|
163
|
+
## Troubleshooting
|
|
164
|
+
|
|
165
|
+
Resampler never gets an assignment: The mission hasn't reached `resample_zone`
|
|
166
|
+
yet. Check `dynos call state --scope public`.
|
|
167
|
+
|
|
168
|
+
`No plan found`: The source zone doesn't exist, has no `vertices`, or has
|
|
169
|
+
`coverage_width <= 0`. Check `dynos call objects --type zone`.
|
|
170
|
+
|
|
171
|
+
Resurvey failed: The proposed zone is missing fields. `resampled_*` needs
|
|
172
|
+
`vertices` (3+), `coverage_width > 0`, `robot_width > 0`, and
|
|
173
|
+
`coordinate_frame`. The `ZoneProposal` dataclass populates these; if you
|
|
174
|
+
bypassed it, double-check.
|
|
175
|
+
|
|
176
|
+
For cross-package issues (login, session, connection), see `user_guide.md` or
|
|
177
|
+
`dynos-client`'s README.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dynos-adaptive-resampling"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
requires-python = ">=3.8"
|
|
9
|
+
description = "Adaptive resampling extension for DYNOS Sentry surveys"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
dependencies = [
|
|
13
|
+
"dynos-client>=0.1.2", # stay locked but assume backwards-compatible
|
|
14
|
+
"dynos-sentry-domain==0.1.2", # stay locked to the domain version
|
|
15
|
+
"numpy",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
dev = ["pytest"]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.packages.find]
|
|
22
|
+
where = ["src"]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Adaptive resampling extension for DYNOS Sentry surveys.
|
|
2
|
+
|
|
3
|
+
Adds a resample_zone transition that generates a new survey zone from
|
|
4
|
+
ML model predictions based on historic survey data. Designed to be
|
|
5
|
+
chained after a standard coverage survey.
|
|
6
|
+
|
|
7
|
+
Example stub, modify as you wish.
|
|
8
|
+
"""
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Adaptive resampling domain extension.
|
|
2
|
+
|
|
3
|
+
Adds vocabulary for ML-driven zone resampling to the Sentry domain.
|
|
4
|
+
This module defines the transition, fluents, and parameters that describe
|
|
5
|
+
the resampling capability. It does NOT contain the ML model itself;
|
|
6
|
+
that lives in the action implementation (robot class).
|
|
7
|
+
|
|
8
|
+
Import this alongside the sentry domain::
|
|
9
|
+
|
|
10
|
+
from dynos_sentry.sentry import phase_ascending, Zone, full_coverage_of
|
|
11
|
+
from dynos_adaptive_resampling.domain import resample_zone, resampling_complete
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from dynos_client.domain import (
|
|
15
|
+
Transition,
|
|
16
|
+
TransitionParams,
|
|
17
|
+
make_new_fluent,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from dynos_sentry.sentry import Zone
|
|
21
|
+
|
|
22
|
+
resampling_complete = make_new_fluent(default=False)
|
|
23
|
+
|
|
24
|
+
class ResampleZoneParams(TransitionParams):
|
|
25
|
+
"""Parameters for the resample_zone transition.
|
|
26
|
+
|
|
27
|
+
source_zone: the zone that was just surveyed
|
|
28
|
+
"""
|
|
29
|
+
source_zone: Zone
|
|
30
|
+
#confidence: Float # You can add other things if you need to, just don't mess with Zone since the backend needs it to figure out what tracklines to draw
|
|
31
|
+
|
|
32
|
+
resample_zone = Transition(
|
|
33
|
+
params_type=ResampleZoneParams,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
resample_zone.define(
|
|
37
|
+
preconditions=[],
|
|
38
|
+
adds=[resampling_complete()],
|
|
39
|
+
removes=[],
|
|
40
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Example mission: standard survey followed by adaptive resampling.
|
|
2
|
+
|
|
3
|
+
This file shows how to build a mission that chains a coverage survey
|
|
4
|
+
with an ML-driven resampling step. It can be executed against either
|
|
5
|
+
a local or remote backend.
|
|
6
|
+
|
|
7
|
+
Usage::
|
|
8
|
+
|
|
9
|
+
from dynos_adaptive_resampling.mission import build_resample_mission
|
|
10
|
+
from dynos_client import RemoteOrchestrator
|
|
11
|
+
|
|
12
|
+
orch = RemoteOrchestrator("http://backend:8421")
|
|
13
|
+
mission = build_resample_mission("site_alpha")
|
|
14
|
+
results = mission.execute(orch)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from dynos_client import Mission
|
|
18
|
+
from dynos_sentry.sentry import full_coverage_of
|
|
19
|
+
from dynos_adaptive_resampling.domain import resample_zone, ResampleZoneParams
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def build_resample_mission(zone_name: str) -> Mission:
|
|
23
|
+
"""Build a mission: survey zone -> resample -> survey new zone -> abort.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
zone_name: name of the initial survey zone (must already exist
|
|
27
|
+
as a domain object on the backend)
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
A Mission object ready for execution
|
|
31
|
+
"""
|
|
32
|
+
mission = Mission(name=f"adaptive_survey_{zone_name}")
|
|
33
|
+
|
|
34
|
+
# Phase 1: initialize the vehicle
|
|
35
|
+
mission.add_action("takeover_control")
|
|
36
|
+
|
|
37
|
+
# Phase 2: survey the original zone
|
|
38
|
+
mission.add_plan([full_coverage_of(zone_name)])
|
|
39
|
+
|
|
40
|
+
# Phase 3: run the ML resampler
|
|
41
|
+
mission.add_action(
|
|
42
|
+
resample_zone,
|
|
43
|
+
params=ResampleZoneParams(source_zone=zone_name),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Phase 4: survey the resampled zone
|
|
47
|
+
mission.add_plan([full_coverage_of(f"resampled_{zone_name}")])
|
|
48
|
+
|
|
49
|
+
# Phase 5: abort and recover
|
|
50
|
+
mission.add_action("full_abort") # specifying steps as strings is not preferred but does work when you don't have the backend implelementation.
|
|
51
|
+
|
|
52
|
+
return mission
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Adaptive resampling robot class.
|
|
2
|
+
|
|
3
|
+
This is the action implementation that runs the ML model and creates
|
|
4
|
+
a new survey zone. It is registered with the Orchestrator alongside
|
|
5
|
+
the standard Sentry robot class.
|
|
6
|
+
|
|
7
|
+
STUB: replace the ML model placeholder with your trained model.
|
|
8
|
+
|
|
9
|
+
Usage with a remote backend::
|
|
10
|
+
|
|
11
|
+
from dynos_adaptive_resampling.resampler import AdaptiveResampler
|
|
12
|
+
from dynos_adaptive_resampling.domain import resample_zone
|
|
13
|
+
|
|
14
|
+
# In your Runnable.register():
|
|
15
|
+
orchestrator.register_class(AdaptiveResampler)
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from typing import Any, Dict, List, Optional
|
|
19
|
+
|
|
20
|
+
# vvv Recommended that you don't touch any of this vvv
|
|
21
|
+
from dynos_client.domain import ObjectType, SymbolicObject, ValueField, make_new_object
|
|
22
|
+
from dynos_adaptive_resampling.domain import resample_zone, ResampleZoneParams
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
from dynos.databases.typed_action import Action
|
|
26
|
+
except ImportError:
|
|
27
|
+
from dynos_client.action import Action # type: ignore
|
|
28
|
+
|
|
29
|
+
# ^^^ Recommended you don't touch any of this ^^^
|
|
30
|
+
|
|
31
|
+
# Edit away down here
|
|
32
|
+
class ZoneProposal:
|
|
33
|
+
"""A proposed survey zone from the ML model. Modify as needed (except as noted)
|
|
34
|
+
|
|
35
|
+
Attributes:
|
|
36
|
+
vertices: list of (latitude, longitude) tuples
|
|
37
|
+
altitude: survey altitude in meters
|
|
38
|
+
speed: survey speed in m/s
|
|
39
|
+
confidence: model confidence (0.0:1.0)
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
vertices: List[tuple],
|
|
45
|
+
altitude: float = 70.0,
|
|
46
|
+
speed: float = 0.8,
|
|
47
|
+
confidence: float = 0.0,
|
|
48
|
+
):
|
|
49
|
+
self.vertices = vertices # need
|
|
50
|
+
self.altitude = altitude # need, but can be overridden during execution by the operator
|
|
51
|
+
self.speed = speed # need, but can be overridden during execution by the operator
|
|
52
|
+
self.confidence = confidence # don't need, not used internally, feel free to add this or other things if helpful
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class AdaptiveResampler:
|
|
56
|
+
"""Robot class that implements ML-driven zone resampling.
|
|
57
|
+
|
|
58
|
+
Register this alongside the standard Sentry robot class::
|
|
59
|
+
|
|
60
|
+
orchestrator.register_class(SentryMock)
|
|
61
|
+
orchestrator.register_class(AdaptiveResampler)
|
|
62
|
+
|
|
63
|
+
The ``resample_zone`` action:
|
|
64
|
+
1. Reads historic survey data from the source zone
|
|
65
|
+
2. "Runs" the ML model to predict high-interest regions
|
|
66
|
+
3. Creates a new Zone object with the predicted vertices
|
|
67
|
+
4. Returns success with the new zone name in telemetry
|
|
68
|
+
|
|
69
|
+
STUB: the ``_predict_new_zone`` method returns a
|
|
70
|
+
hardcoded rectangle that should be replaced with the
|
|
71
|
+
method of selecting the new zone (or zones).
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
def __init__(self):
|
|
75
|
+
self._model = None # Replace with your ML model
|
|
76
|
+
self._prediction_history: List[ZoneProposal] = []
|
|
77
|
+
|
|
78
|
+
@Action(transition=resample_zone)
|
|
79
|
+
def do_resample(self, params: ResampleZoneParams, ctx) -> dict:
|
|
80
|
+
"""Execute the resampling action. Sample implementation.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
params: ResampleZoneParams with source_zone
|
|
84
|
+
ctx: ActionContext (provides logging, config)
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
ActionResult-compatible dict with success status and telemetry
|
|
88
|
+
"""
|
|
89
|
+
source_zone_name = str(params.source_zone)
|
|
90
|
+
|
|
91
|
+
historic_data = self._gather_historic_data(source_zone_name)
|
|
92
|
+
proposal = self._predict_new_zone(historic_data)
|
|
93
|
+
self._prediction_history.append(proposal)
|
|
94
|
+
|
|
95
|
+
# The new zone is created at runtime via the orchestrator (or remote orchestrator):
|
|
96
|
+
#
|
|
97
|
+
# remote_orch.create_object(
|
|
98
|
+
# type_name="zone",
|
|
99
|
+
# name=f"resampled_{source_zone_name}",
|
|
100
|
+
# vertices=proposal.vertices,
|
|
101
|
+
# altitude=proposal.altitude,
|
|
102
|
+
# speed=proposal.speed,
|
|
103
|
+
# )
|
|
104
|
+
|
|
105
|
+
new_zone_name = f"resampled_{source_zone_name}"
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
"success": True,
|
|
109
|
+
"telemetry": {
|
|
110
|
+
"new_zone": new_zone_name,
|
|
111
|
+
"vertices": proposal.vertices,
|
|
112
|
+
"confidence": proposal.confidence,
|
|
113
|
+
"source_zone": source_zone_name,
|
|
114
|
+
},
|
|
115
|
+
} # Telemetery isn't used for anything internally, it's just for logging so edit away. 'success' param matters though: if false, we'll try again or eventually give up.
|
|
116
|
+
|
|
117
|
+
def _gather_historic_data(self, zone_name: str) -> Dict[str, Any]:
|
|
118
|
+
"""Gather historic survey data for a zone.
|
|
119
|
+
|
|
120
|
+
STUB: returns empty data in a format we don't care about on the backend.
|
|
121
|
+
"""
|
|
122
|
+
return {
|
|
123
|
+
"zone_name": zone_name,
|
|
124
|
+
"tracklines_completed": 0,
|
|
125
|
+
"sonar_readings": [],
|
|
126
|
+
"anomalies_detected": [],
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
def _predict_new_zone(self, historic_data: Dict[str, Any]) -> ZoneProposal:
|
|
130
|
+
"""Run the ML model to predict a high-interest zone.
|
|
131
|
+
|
|
132
|
+
STUB: returns a hardcoded rectangle offset from the original zone.
|
|
133
|
+
|
|
134
|
+
Your model should return a polygon (list of lat/lon vertices) defining the new zone
|
|
135
|
+
"""
|
|
136
|
+
return ZoneProposal(
|
|
137
|
+
vertices=[
|
|
138
|
+
(41.0, -70.0),
|
|
139
|
+
(41.0, -69.9),
|
|
140
|
+
(41.1, -69.9),
|
|
141
|
+
(41.1, -70.0),
|
|
142
|
+
],
|
|
143
|
+
altitude=70.0,
|
|
144
|
+
speed=0.8,
|
|
145
|
+
confidence=0.5,
|
|
146
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Runnable for the adaptive resampling extension.
|
|
2
|
+
|
|
3
|
+
This is the entry point for ``dynos connect``. It registers the
|
|
4
|
+
AdaptiveResampler robot class alongside any existing Sentry classes
|
|
5
|
+
on the local orchestrator, then the servant loop handles the rest.
|
|
6
|
+
|
|
7
|
+
Usage::
|
|
8
|
+
|
|
9
|
+
dynos connect dynos_adaptive_resampling.runnable:AdaptiveResamplingNode \\
|
|
10
|
+
--to http://backend:8421
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import List
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AdaptiveResamplingNode:
|
|
17
|
+
"""Runnable that provides the adaptive resampling action to a remote backend.
|
|
18
|
+
|
|
19
|
+
This registers ``AdaptiveResampler`` so that the ``resample_zone``
|
|
20
|
+
transition can be executed on this hardware node. The standard
|
|
21
|
+
Sentry actions (fly_trackline, etc.) are handled by a separate
|
|
22
|
+
servant node running the Sentry hardware class.
|
|
23
|
+
|
|
24
|
+
This is a standardized format that the backend expects.
|
|
25
|
+
It shouldn't be necessary for you to modify this.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def register(orchestrator, cli):
|
|
30
|
+
from dynos_adaptive_resampling.resampler import AdaptiveResampler
|
|
31
|
+
orchestrator.register_class(AdaptiveResampler)
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def get_start_state(cli) -> List:
|
|
35
|
+
# No initial state; the backend already has the mission state
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def get_start_goal(cli) -> List:
|
|
40
|
+
# No default goal; the backend sets the mission goal
|
|
41
|
+
return []
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dynos-adaptive-resampling
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Adaptive resampling extension for DYNOS Sentry surveys
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: dynos-client>=0.1.2
|
|
9
|
+
Requires-Dist: dynos-sentry-domain==0.1.2
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest; extra == "dev"
|
|
13
|
+
|
|
14
|
+
# dynos-adaptive-resampling
|
|
15
|
+
|
|
16
|
+
A worked example: chain an ML-driven resampling step onto a Sentry survey. This
|
|
17
|
+
package is scaffolding: it ships a stub `AdaptiveResampler` that you
|
|
18
|
+
replace with your model, plus the wiring (`runnable.py`, `mission.py`) that
|
|
19
|
+
lets `dynos connect` find it and that lets the planner sequence "survey,
|
|
20
|
+
resample, resurvey".
|
|
21
|
+
|
|
22
|
+
The package contributes one new transition (`resample_zone`) and one new
|
|
23
|
+
mission template (`build_resample_mission`). Everything else is for you to
|
|
24
|
+
edit.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
You will be modifying the source, so install editable:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install -e dynos-adaptive-resampling
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This pulls in `dynos-client`, `dynos-sentry-domain`, and `numpy`.
|
|
35
|
+
|
|
36
|
+
## What's in this repository
|
|
37
|
+
|
|
38
|
+
### `domain.py`
|
|
39
|
+
|
|
40
|
+
Declares `resample_zone` (transition), `ResampleZoneParams` (its parameter
|
|
41
|
+
dataclass), `resampling_complete` (a fluent the transition adds). Edit if
|
|
42
|
+
you need new fluents or parameters.
|
|
43
|
+
|
|
44
|
+
### `resampler.py`
|
|
45
|
+
|
|
46
|
+
Provides `AdaptiveResampler` class with `@Action(transition=resample_zone)`.
|
|
47
|
+
Edit `_gather_historic_data` and `_predict_new_zone` or whatever else you
|
|
48
|
+
need to get your model integrated.
|
|
49
|
+
|
|
50
|
+
### `mission.py`
|
|
51
|
+
|
|
52
|
+
Provides `build_resample_mission(zone_name)` returns a `Mission` that does
|
|
53
|
+
survey, resample, resurvey. Edit If you want a different sequence.
|
|
54
|
+
|
|
55
|
+
### `runnable.py`
|
|
56
|
+
|
|
57
|
+
Provides `AdaptiveResamplingNode`, the `dynos connect`-compatible entry point.
|
|
58
|
+
You probably don't need to edit this.
|
|
59
|
+
|
|
60
|
+
## How the round-trip works
|
|
61
|
+
|
|
62
|
+
1. You launch the resampler as a servant: `dynos connect
|
|
63
|
+
dynos_adaptive_resampling.runnable:AdaptiveResamplingNode`. The servant
|
|
64
|
+
idles, polling the backend for assignments.
|
|
65
|
+
2. From a second terminal you build the mission and call `execute_blocks`. The
|
|
66
|
+
first plan block surveys the source zone end-to-end.
|
|
67
|
+
3. The planner reaches `resample_zone(source_zone=site_alpha)`. It dispatches
|
|
68
|
+
the assignment over HTTP to your servant.
|
|
69
|
+
4. Your `AdaptiveResampler` runs `_gather_historic_data`, then
|
|
70
|
+
`_predict_new_zone`, then writes the resulting `ZoneProposal` back as a new
|
|
71
|
+
`Zone` object on the backend.
|
|
72
|
+
5. The next plan block surveys the new zone. The mission ends with abort +
|
|
73
|
+
recover.
|
|
74
|
+
|
|
75
|
+
## Replacing the stub
|
|
76
|
+
|
|
77
|
+
You will edit two methods in `resampler.py`:
|
|
78
|
+
|
|
79
|
+
`_gather_historic_data(zone_name)`: return whatever your model needs. The
|
|
80
|
+
shipped stub returns an empty dict; you replace it with calls to a shared
|
|
81
|
+
database, ROS bag, the backend API (`orch.get_objects(type="zone")`), an
|
|
82
|
+
offline NetCDF, etc.
|
|
83
|
+
|
|
84
|
+
`_predict_new_zone(historic_data)`: return a `ZoneProposal` with
|
|
85
|
+
`vertices`, `altitude`, `speed`, and `confidence`:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
def _predict_new_zone(self, historic_data):
|
|
89
|
+
features = self._extract_features(historic_data["sonar_readings"])
|
|
90
|
+
prediction = self._model.predict(features)
|
|
91
|
+
return ZoneProposal(
|
|
92
|
+
vertices=self._prediction_to_polygon(prediction),
|
|
93
|
+
altitude=70.0,
|
|
94
|
+
speed=0.8,
|
|
95
|
+
confidence=float(prediction.confidence),
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
You can add fields to `ResampleZoneParams` (e.g. a confidence threshold, or
|
|
100
|
+
whatever else you want), but don't change the `Zone` parameter: the backend's
|
|
101
|
+
coverage planner reads `Zone.vertices`, `Zone.coverage_width`, etc. to draw
|
|
102
|
+
tracklines, and it expects the public schema.
|
|
103
|
+
|
|
104
|
+
## Test offline
|
|
105
|
+
|
|
106
|
+
Before pointing at the real backend, run the package's own tests:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install -e "dynos-adaptive-resampling/[dev]"
|
|
110
|
+
pytest dynos-adaptive-resampling/tests/ -v
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
These exercise `_gather_historic_data` and `_predict_new_zone` against a stub
|
|
114
|
+
backend. No network or session needed.
|
|
115
|
+
|
|
116
|
+
## Run it for real
|
|
117
|
+
|
|
118
|
+
Two terminals.
|
|
119
|
+
|
|
120
|
+
Terminal 1 is your resampler. This can be your laptop, a lab server, or the
|
|
121
|
+
same machine as the backend; the backend dispatches each assignment to
|
|
122
|
+
whichever servant is currently registered for `resample_zone`.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
dynos login # logins persist across terminals but expire after an hour
|
|
126
|
+
dynos session create
|
|
127
|
+
dynos connect dynos_adaptive_resampling.runnable:AdaptiveResamplingNode
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Leave it running. It executes `resample_zone` whenever the backend reaches that
|
|
131
|
+
step.
|
|
132
|
+
|
|
133
|
+
Terminal 2 is mission. Create the source zone and run the adaptive mission:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
dynos call create zone.json
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from dynos_client import RemoteOrchestrator
|
|
141
|
+
from dynos_adaptive_resampling.mission import build_resample_mission
|
|
142
|
+
|
|
143
|
+
orch = RemoteOrchestrator.from_config(timeout_s=3600)
|
|
144
|
+
results = orch.execute_blocks(build_resample_mission("site_alpha"))
|
|
145
|
+
for r in results:
|
|
146
|
+
print(r)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
While it runs, monitor from a third terminal:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
dynos call state --scope public # current symbolic state, pruned only for the symbols you're expecting
|
|
153
|
+
dynos call goal # current goal
|
|
154
|
+
dynos call objects --type zone # source + proposed zones
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## What the mission does, step by step
|
|
158
|
+
|
|
159
|
+
1. Init. Takeover, descent, mode setup.
|
|
160
|
+
2. Survey the source zone (`full_coverage_of(site_alpha)`).
|
|
161
|
+
3. Resample. Plan dispatches `resample_zone(source_zone=site_alpha)` to your servant; your model creates `resampled_site_alpha`.
|
|
162
|
+
4. Resurvey. `full_coverage_of(resampled_site_alpha)`.
|
|
163
|
+
5. Recover. Abort and ascend.
|
|
164
|
+
|
|
165
|
+
## Public API
|
|
166
|
+
|
|
167
|
+
| Symbol | From | Purpose |
|
|
168
|
+
|-------------------------------------|---------------------------------------|------------------------------------------------|
|
|
169
|
+
| `resample_zone` | `dynos_adaptive_resampling.domain` | The transition that fires your `@Action`. |
|
|
170
|
+
| `ResampleZoneParams` | `dynos_adaptive_resampling.domain` | Its parameter dataclass (`source_zone: Zone`). |
|
|
171
|
+
| `resampling_complete` | `dynos_adaptive_resampling.domain` | Fluent the transition adds. |
|
|
172
|
+
| `AdaptiveResampler` | `dynos_adaptive_resampling.resampler` | The class you edit. |
|
|
173
|
+
| `AdaptiveResamplingNode` | `dynos_adaptive_resampling.runnable` | The `dynos connect` entry point. |
|
|
174
|
+
| `build_resample_mission(zone_name)` | `dynos_adaptive_resampling.mission` | Survey, resample, resurvey. |
|
|
175
|
+
|
|
176
|
+
## Troubleshooting
|
|
177
|
+
|
|
178
|
+
Resampler never gets an assignment: The mission hasn't reached `resample_zone`
|
|
179
|
+
yet. Check `dynos call state --scope public`.
|
|
180
|
+
|
|
181
|
+
`No plan found`: The source zone doesn't exist, has no `vertices`, or has
|
|
182
|
+
`coverage_width <= 0`. Check `dynos call objects --type zone`.
|
|
183
|
+
|
|
184
|
+
Resurvey failed: The proposed zone is missing fields. `resampled_*` needs
|
|
185
|
+
`vertices` (3+), `coverage_width > 0`, `robot_width > 0`, and
|
|
186
|
+
`coordinate_frame`. The `ZoneProposal` dataclass populates these; if you
|
|
187
|
+
bypassed it, double-check.
|
|
188
|
+
|
|
189
|
+
For cross-package issues (login, session, connection), see `user_guide.md` or
|
|
190
|
+
`dynos-client`'s README.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/dynos_adaptive_resampling/__init__.py
|
|
4
|
+
src/dynos_adaptive_resampling/domain.py
|
|
5
|
+
src/dynos_adaptive_resampling/mission.py
|
|
6
|
+
src/dynos_adaptive_resampling/resampler.py
|
|
7
|
+
src/dynos_adaptive_resampling/runnable.py
|
|
8
|
+
src/dynos_adaptive_resampling.egg-info/PKG-INFO
|
|
9
|
+
src/dynos_adaptive_resampling.egg-info/SOURCES.txt
|
|
10
|
+
src/dynos_adaptive_resampling.egg-info/dependency_links.txt
|
|
11
|
+
src/dynos_adaptive_resampling.egg-info/requires.txt
|
|
12
|
+
src/dynos_adaptive_resampling.egg-info/top_level.txt
|
|
13
|
+
tests/test_resampler.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dynos_adaptive_resampling
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Tests for the adaptive resampler; runnable without a backend."""
|
|
2
|
+
|
|
3
|
+
from dynos_adaptive_resampling.resampler import AdaptiveResampler, ZoneProposal
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestZoneProposal:
|
|
7
|
+
def test_default_values(self):
|
|
8
|
+
p = ZoneProposal(vertices=[(0, 0), (0, 1), (1, 1), (1, 0)])
|
|
9
|
+
assert p.altitude == 70.0
|
|
10
|
+
assert p.speed == 0.8
|
|
11
|
+
assert p.confidence == 0.0
|
|
12
|
+
assert len(p.vertices) == 4
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestAdaptiveResampler:
|
|
16
|
+
def test_predict_returns_proposal(self):
|
|
17
|
+
resampler = AdaptiveResampler()
|
|
18
|
+
proposal = resampler._predict_new_zone({"zone_name": "test"})
|
|
19
|
+
assert isinstance(proposal, ZoneProposal)
|
|
20
|
+
assert len(proposal.vertices) == 4
|
|
21
|
+
assert proposal.confidence > 0
|
|
22
|
+
|
|
23
|
+
def test_gather_historic_data_stub(self):
|
|
24
|
+
resampler = AdaptiveResampler()
|
|
25
|
+
data = resampler._gather_historic_data("zone_a")
|
|
26
|
+
assert data["zone_name"] == "zone_a"
|
|
27
|
+
|
|
28
|
+
def test_do_resample_returns_success(self):
|
|
29
|
+
resampler = AdaptiveResampler()
|
|
30
|
+
|
|
31
|
+
class FakeParams:
|
|
32
|
+
source_zone = "zone_a"
|
|
33
|
+
|
|
34
|
+
class FakeCtx:
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
result = resampler.do_resample(FakeParams(), FakeCtx())
|
|
38
|
+
assert result["success"] is True
|
|
39
|
+
assert "new_zone" in result["telemetry"]
|
|
40
|
+
assert result["telemetry"]["source_zone"] == "zone_a"
|
|
41
|
+
assert result["telemetry"]["new_zone"] == "resampled_zone_a"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class TestDomain:
|
|
45
|
+
def test_resample_zone_transition_exists(self):
|
|
46
|
+
from dynos_adaptive_resampling.domain import resample_zone
|
|
47
|
+
assert resample_zone.name == "resample_zone"
|
|
48
|
+
|
|
49
|
+
def test_resampling_complete_fluent(self):
|
|
50
|
+
from dynos_adaptive_resampling.domain import resampling_complete
|
|
51
|
+
assert str(resampling_complete) == "resampling_complete"
|
|
52
|
+
|
|
53
|
+
def test_resample_zone_has_effects(self):
|
|
54
|
+
from dynos_adaptive_resampling.domain import resample_zone
|
|
55
|
+
assert len(resample_zone._effects_pos) == 1
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class TestMission:
|
|
59
|
+
def test_build_resample_mission(self):
|
|
60
|
+
from dynos_adaptive_resampling.mission import build_resample_mission
|
|
61
|
+
m = build_resample_mission("site_alpha")
|
|
62
|
+
assert m.name == "adaptive_survey_site_alpha"
|
|
63
|
+
assert len(m.blocks) == 5 # takeover + survey + resample + resurvey + abort
|
|
64
|
+
|
|
65
|
+
def test_mission_serializes_to_json(self):
|
|
66
|
+
from dynos_adaptive_resampling.mission import build_resample_mission
|
|
67
|
+
m = build_resample_mission("site_alpha")
|
|
68
|
+
j = m.to_json()
|
|
69
|
+
assert "takeover_control" in j
|
|
70
|
+
assert "resample_zone" in j
|
|
71
|
+
assert "full_coverage_of" in j
|