-
Notifications
You must be signed in to change notification settings - Fork 32
[uss_qualifier/resource] Add base class for geospatial modifier #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BenjaminPelletier
merged 1 commit into
interuss:main
from
Orbitalize:1458_geospatial_modifier
Jun 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| from abc import ABC, abstractmethod | ||
| from math import isqrt | ||
| from typing import Self | ||
|
|
||
| from implicitdict import ImplicitDict | ||
|
|
||
| from monitoring.monitorlib.geo import LatLngBoundingBox, flatten | ||
| from monitoring.uss_qualifier.resources.resource import ( | ||
| Resource, | ||
| ResourceProvidingResource, | ||
| ) | ||
|
|
||
|
|
||
| class GeospatialResource(Resource, ABC): | ||
| @abstractmethod | ||
| def get_extents(self) -> LatLngBoundingBox: | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def move(self, meters_east: float, meters_north: float) -> Self: | ||
|
the-glu marked this conversation as resolved.
|
||
| """Return a copy of this resource that has been moved the specified number of meters east and north.""" | ||
| pass | ||
|
|
||
|
|
||
| class TriangularCascadeSoutheastSpecification(ImplicitDict): | ||
| meters_east_margin: float | ||
| """Modify the resource by moving it this far along the east-west axis to separate it from other modification instances.""" | ||
|
|
||
| meters_north_margin: float | ||
| """Modify the resource by moving it this far along the north-south axis to separate it from other modification instances.""" | ||
|
|
||
|
|
||
| class TriangularCascadeSoutheastResource[GeospatialResourceType: GeospatialResource]( | ||
| ResourceProvidingResource[ | ||
| TriangularCascadeSoutheastSpecification, GeospatialResourceType | ||
| ] | ||
| ): | ||
| """Provides modified copies of a base geospatial resource which are offset east and south of the original resource.""" | ||
|
|
||
| base_resource: GeospatialResourceType | ||
|
|
||
| def __init__( | ||
| self, | ||
| specification: TriangularCascadeSoutheastSpecification, | ||
| resource_origin: str, | ||
| base_resource: GeospatialResourceType, | ||
| ): | ||
| super().__init__(specification, resource_origin) | ||
| self._spec = specification | ||
| self.base_resource = base_resource | ||
|
|
||
| def provide_resource_for(self, **kwargs) -> GeospatialResourceType: | ||
|
|
||
| if "index" not in kwargs: | ||
| raise ValueError("Need an index") | ||
|
|
||
| index = kwargs["index"] | ||
| assert isinstance(index, int) | ||
|
|
||
| # Make a grid based on index: | ||
| # x -> | ||
| # y 0 1 3 6 | ||
| # | 2 4 7 | ||
| # v 5 8 | ||
| # 9 | ||
| k = (isqrt(1 + 8 * index) - 1) // 2 | ||
| offset = index - k * (k + 1) // 2 | ||
| x = k - offset | ||
| y = offset | ||
|
|
||
| rect = self.base_resource.get_extents().to_latlngrect() | ||
| width_m, height_m = flatten(rect.lo(), rect.hi()) | ||
| width_m += self._spec.meters_east_margin | ||
| height_m += self._spec.meters_north_margin | ||
| return self.base_resource.move(x * width_m, y * height_m) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import unittest | ||
|
|
||
| from monitoring.monitorlib.geo import area_of_latlngrect | ||
| from monitoring.uss_qualifier.resources.definitions import ( | ||
| ResourceDeclaration, | ||
| ResourceID, | ||
| ) | ||
| from monitoring.uss_qualifier.resources.dev.test_modifier import ( | ||
| TestSquareSpecification, | ||
| ) | ||
| from monitoring.uss_qualifier.resources.geospatial import ( | ||
| TriangularCascadeSoutheastSpecification, | ||
| ) | ||
| from monitoring.uss_qualifier.resources.resource import create_resources | ||
|
|
||
|
|
||
| class TestGeospatialModifier(unittest.TestCase): | ||
| def _build_declarations(self) -> dict[ResourceID, ResourceDeclaration]: | ||
| return { | ||
| "square": ResourceDeclaration( | ||
| resource_type="resources.dev.TestSquareResource", | ||
| specification=TestSquareSpecification(lat_center=46.5, lng_center=6.5), | ||
| ), | ||
| "square_modifier": ResourceDeclaration( | ||
| resource_type="resources.dev.TestSquareModifier", | ||
| specification=TriangularCascadeSoutheastSpecification( | ||
| meters_east_margin=1000, meters_north_margin=1000 | ||
| ), | ||
| dependencies={ | ||
| "base_resource": "square", | ||
| }, | ||
| ), | ||
| } | ||
|
|
||
| def test_overlap_only_for_same_index(self): | ||
| resources = create_resources(self._build_declarations(), "test", True) | ||
| modifier = resources["square_modifier"] | ||
|
|
||
| extents = [ | ||
| modifier.provide_resource_for(index=i).get_extents() for i in range(11) | ||
| ] | ||
| square_area = ( | ||
| resources["square"].SQUARE_SIDE_M * resources["square"].SQUARE_SIDE_M | ||
| ) | ||
|
|
||
| for i in range(11): | ||
| for j in range(11): | ||
| rect_i = extents[i].to_latlngrect() | ||
| rect_j = extents[j].to_latlngrect() | ||
| overlap = area_of_latlngrect(rect_i.intersection(rect_j)) | ||
| if i == j: | ||
| assert ( | ||
| overlap > 0.99 * square_area | ||
| ), ( # Use 99% to compensate for errors | ||
| f"index {i}: self-overlap area {overlap:.2f}m² " | ||
| f"expected ~{square_area:.2f}m²" | ||
| ) | ||
| else: | ||
| assert ( | ||
| overlap < 0.01 * square_area | ||
| ), ( # Use 1% to compensate for errors | ||
| f"indices {i},{j}: unexpected overlap area {overlap:.2f}m²" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
schemas/monitoring/uss_qualifier/resources/dev/test_modifier/TestSquareSpecification.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "$id": "https://github.com/interuss/monitoring/blob/main/schemas/monitoring/uss_qualifier/resources/dev/test_modifier/TestSquareSpecification.json", | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "description": "monitoring.uss_qualifier.resources.dev.test_modifier.TestSquareSpecification, as defined in monitoring/uss_qualifier/resources/dev/test_modifier.py", | ||
| "properties": { | ||
| "$ref": { | ||
| "description": "Path to content that replaces the $ref", | ||
| "type": "string" | ||
| }, | ||
| "lat_center": { | ||
| "type": "number" | ||
| }, | ||
| "lng_center": { | ||
| "type": "number" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "lat_center", | ||
| "lng_center" | ||
| ], | ||
| "type": "object" | ||
| } |
24 changes: 24 additions & 0 deletions
24
...onitoring/uss_qualifier/resources/geospatial/TriangularCascadeSoutheastSpecification.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "$id": "https://github.com/interuss/monitoring/blob/main/schemas/monitoring/uss_qualifier/resources/geospatial/TriangularCascadeSoutheastSpecification.json", | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "description": "monitoring.uss_qualifier.resources.geospatial.TriangularCascadeSoutheastSpecification, as defined in monitoring/uss_qualifier/resources/geospatial.py", | ||
| "properties": { | ||
| "$ref": { | ||
| "description": "Path to content that replaces the $ref", | ||
| "type": "string" | ||
| }, | ||
| "meters_east_margin": { | ||
| "description": "Modify the resource by moving it this far along the east-west axis to separate it from other modification instances.", | ||
| "type": "number" | ||
| }, | ||
| "meters_north_margin": { | ||
| "description": "Modify the resource by moving it this far along the north-south axis to separate it from other modification instances.", | ||
| "type": "number" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "meters_east_margin", | ||
| "meters_north_margin" | ||
| ], | ||
| "type": "object" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.