darts_acquisition.utils.grid
¶
Major Tom grid implementation following the paper https://arxiv.org/html/2402.12095v2.
Cell
dataclass
¶
Cell(
d: float,
row_idx: int,
col_idx: int,
row_direction: typing.Literal["U", "D"],
col_direction: typing.Literal["L", "R"],
lat: float,
lon: float,
utm_zone: int,
)
Cell in the Major Tom grid.
get_bounds
¶
Get the bounds of the cell as a shapely Polygon in the respective local utm_zone coordinates.
Parameters:
Returns:
-
shapely.Polygon–shapely.Polygon: The bounds of the cell as a shapely Polygon.
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
to_shape
¶
Convert the cell to a shapely Point object.
Returns:
-
shapely.Point–shapely.Point: The cell as a shapely Point object.
MajorTomGrid
¶
MajorTomGrid(d: float)
Major Tom grid following the implementation from https://arxiv.org/html/2402.12095v2.
Initialize the Major Tom grid with a given resolution.
Parameters:
-
d(float) –Resolution of the grid in km.
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
__getitem__
¶
__getitem__(idx: str) -> darts_acquisition.utils.grid.Cell
Get the grid cell at the given index.
Parameters:
-
idx(str) –Major Tom grid index in the format re'/\d+(D|U)\d+(L|R)/g'.
Returns:
-
Cell(darts_acquisition.utils.grid.Cell) –The grid cell at the given index.
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
dlon
¶
n_c
cached
¶
Calculate the number of columns (longitudes) in the grid at a given latitude.
Parameters:
-
lat(float) –Latitude at which to calculate the number of columns.
Returns:
-
int(int) –Number of columns at the given latitude.
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
to_geodataframe
¶
to_geodataframe(
bounds: tuple[float, float, float, float]
| shapely.Polygon
| None = None,
) -> geopandas.GeoDataFrame
Convert the Major Tom grid to a geopandas GeoDataFrame.
Parameters:
-
bounds(tuple[float, float, float, float] | shapely.Polygon | None, default:None) –The bounds of the grid. If the bounds are a polygon, only cells within the polygon are yielded. If the bounds are a tuple, the format must be (min_lon, min_lat, max_lon, max_lat). If None, the entire grid is yielded. Coordinates must be in EPSG:4326. Defaults to None.
Returns:
-
geopandas.GeoDataFrame–geopandas.GeoDataFrame: The Major Tom grid as a GeoDataFrame.
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
yield_cells
¶
yield_cells(
bounds: tuple[float, float, float, float]
| shapely.Polygon
| None = None,
) -> collections.abc.Generator[
darts_acquisition.utils.grid.Cell, None, None
]
Generate all cells in the Major Tom grid.
Starting at the North Pole, the generator yields cells from west to east and from north to south.
Parameters:
-
bounds(tuple[float, float, float, float] | shapely.Polygon | None, default:None) –The bounds of the grid. If the bounds are a polygon, only cells within the polygon are yielded. If the bounds are a tuple, the format must be (min_lon, min_lat, max_lon, max_lat). If None, the entire grid is yielded. Coordinates must be in EPSG:4326. Please note that bounds around the antimetidian (180°/-180°) and the poles (90°/-90°) are not supported. Defaults to None.
Yields:
-
Cell(darts_acquisition.utils.grid.Cell) –The next cell in the grid.
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
yield_latitudes
¶
Generate the latitudes of the Major Tom grid from north to south.
Yields:
-
tuple[float, int, str]–tuple[float, int, str]: The next latitude in the grid. (latitude, row index, direction)
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
yield_longitudes
¶
Generate the longitudes of the Major Tom grid at a given latitude.
Parameters:
-
lat(float) –Latitude at which to generate the longitudes.
Yields:
-
tuple[float, int, str]–tuple[float, int, str]: The next longitude at the given latitude. (longitude, column index, direction)
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
get_utm_zone_from_latlng
¶
Get the UTM zone from a latlng list and return the corresponding EPSG code.
Parameters:
-
latitude(float | int) –The latitude of the point.
-
longitude(float | int) –The longitude of the point.
Returns:
-
str(str) –The EPSG code corresponding to the UTM zone of the point.
Raises:
-
ValueError–If the point is out of bounds.
Source code in darts-acquisition/src/darts_acquisition/utils/grid.py
parse_cell_idx
¶
Parse the Major Tom grid index into its components.
Parameters:
-
idx(str) –Major Tom grid index in the format re'/\d+(D|U)\d+(L|R)/g'.
Returns:
-
tuple[int, str, int, str]–tuple[int, str, int, str]: The row index, row direction, column index, and column direction.
Raises:
-
ValueError–If the index is invalid.