Skip to content

Commit

Permalink
tidy up of 00_grids.ipynb by adding markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacortez committed Aug 6, 2024
1 parent 891e485 commit 2f757c3
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 41 deletions.
36 changes: 18 additions & 18 deletions geowrangler/grids.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/00_grids.ipynb.

# %% auto 0
__all__ = ['SquareGridBoundary', 'SquareGridGenerator', 'H3GridGenerator', 'BingTileGridGenerator', 'FastBingTileGridGenerator']
__all__ = ['SquareGridGenerator', 'H3GridGenerator', 'BingTileGridGenerator', 'FastBingTileGridGenerator']

# %% ../notebooks/00_grids.ipynb 5
import logging
Expand All @@ -26,7 +26,7 @@

logger = logging.getLogger(__name__)

# %% ../notebooks/00_grids.ipynb 6
# %% ../notebooks/00_grids.ipynb 7
class SquareGridBoundary:
"""Reusing Boundary. x_min, y_min, x_max, and y_max are in the the target crs"""

Expand Down Expand Up @@ -57,7 +57,7 @@ def get_range_subset(
yrange[y_mask],
)

# %% ../notebooks/00_grids.ipynb 7
# %% ../notebooks/00_grids.ipynb 8
class SquareGridGenerator:
def __init__(
self,
Expand All @@ -69,7 +69,7 @@ def __init__(
self.grid_projection = grid_projection
self.boundary = boundary

# %% ../notebooks/00_grids.ipynb 8
# %% ../notebooks/00_grids.ipynb 9
@patch
def create_cell(
self: SquareGridGenerator,
Expand All @@ -86,7 +86,7 @@ def create_cell(
]
)

# %% ../notebooks/00_grids.ipynb 9
# %% ../notebooks/00_grids.ipynb 10
@patch
def create_grid_for_polygon(self: SquareGridGenerator, boundary, geometry):
x_idx_offset, xrange, y_idx_offset, yrange = boundary.get_range_subset(
Expand All @@ -105,7 +105,7 @@ def create_grid_for_polygon(self: SquareGridGenerator, boundary, geometry):
)
return cells

# %% ../notebooks/00_grids.ipynb 10
# %% ../notebooks/00_grids.ipynb 11
@patch
def generate_grid(self: SquareGridGenerator, gdf: GeoDataFrame) -> GeoDataFrame:
reprojected_gdf = gdf.to_crs(self.grid_projection)
Expand Down Expand Up @@ -137,7 +137,7 @@ def generate_grid(self: SquareGridGenerator, gdf: GeoDataFrame) -> GeoDataFrame:
{"x": [], "y": [], "geometry": []}, geometry="geometry", crs=gdf.crs
)

# %% ../notebooks/00_grids.ipynb 11
# %% ../notebooks/00_grids.ipynb 13
class H3GridGenerator:
def __init__(
self,
Expand All @@ -147,7 +147,7 @@ def __init__(
self.resolution = resolution
self.return_geometry = return_geometry

# %% ../notebooks/00_grids.ipynb 12
# %% ../notebooks/00_grids.ipynb 14
@patch
def get_hexes_for_polygon(self: H3GridGenerator, poly: Polygon):
return h3.polyfill(
Expand All @@ -156,7 +156,7 @@ def get_hexes_for_polygon(self: H3GridGenerator, poly: Polygon):
geo_json_conformant=True,
)

# %% ../notebooks/00_grids.ipynb 13
# %% ../notebooks/00_grids.ipynb 15
@patch
def generate_grid(self: H3GridGenerator, gdf: GeoDataFrame) -> DataFrame:
reprojected_gdf = gdf.to_crs("epsg:4326") # h3 hexes are in epsg:4326 CRS
Expand All @@ -181,7 +181,7 @@ def generate_grid(self: H3GridGenerator, gdf: GeoDataFrame) -> DataFrame:
)
return h3_gdf.to_crs(gdf.crs)

# %% ../notebooks/00_grids.ipynb 14
# %% ../notebooks/00_grids.ipynb 17
class BingTileGridGenerator:
def __init__(
self,
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_tiles_for_polygon(
tiles = {qk: (geom, tile) for qk, geom, tile in tiles}
return tiles

# %% ../notebooks/00_grids.ipynb 15
# %% ../notebooks/00_grids.ipynb 18
@patch
def get_all_tiles_for_polygon(self: BingTileGridGenerator, polygon: Polygon):
"""Get the interseting tiles with polygon for a zoom level. Polygon should be in EPSG:4326"""
Expand All @@ -229,7 +229,7 @@ def get_all_tiles_for_polygon(self: BingTileGridGenerator, polygon: Polygon):
)
return tiles

# %% ../notebooks/00_grids.ipynb 16
# %% ../notebooks/00_grids.ipynb 19
@patch
def generate_grid(self: BingTileGridGenerator, gdf: GeoDataFrame) -> DataFrame:
reprojected_gdf = gdf.to_crs("epsg:4326") # quadkeys hexes are in epsg:4326 CRS
Expand Down Expand Up @@ -264,7 +264,7 @@ def generate_grid(self: BingTileGridGenerator, gdf: GeoDataFrame) -> DataFrame:

return tiles_gdf

# %% ../notebooks/00_grids.ipynb 17
# %% ../notebooks/00_grids.ipynb 20
def get_intersect_partition(item):
tiles_gdf, reprojected_gdf = item
tiles_gdf.sindex
Expand All @@ -274,7 +274,7 @@ def get_intersect_partition(item):
)
return intersect_tiles_gdf

# %% ../notebooks/00_grids.ipynb 18
# %% ../notebooks/00_grids.ipynb 21
def get_parallel_intersects(
tiles_gdf, reprojected_gdf, n_workers=defaults.cpus, progress=True
):
Expand All @@ -294,7 +294,7 @@ def get_parallel_intersects(
results.drop_duplicates(subset=["quadkey"], inplace=True)
return results

# %% ../notebooks/00_grids.ipynb 19
# %% ../notebooks/00_grids.ipynb 22
@patch
def generate_grid_join(
self: BingTileGridGenerator,
Expand Down Expand Up @@ -353,7 +353,7 @@ def generate_grid_join(

return tiles_gdf.to_crs(gdf.crs)

# %% ../notebooks/00_grids.ipynb 21
# %% ../notebooks/00_grids.ipynb 24
class FastBingTileGridGenerator:
EPSILON = 1e-14
PIXEL_DTYPE = pl.UInt32
Expand All @@ -375,7 +375,7 @@ def __init__(
f"Maximum allowed zoom level is {self.MAX_ZOOM}. Input was {self.zoom_level}"
)

# %% ../notebooks/00_grids.ipynb 22
# %% ../notebooks/00_grids.ipynb 25
@patch
def generate_grid(
self: FastBingTileGridGenerator,
Expand Down Expand Up @@ -464,7 +464,7 @@ def generate_grid(

return tiles_in_geom

# %% ../notebooks/00_grids.ipynb 23
# %% ../notebooks/00_grids.ipynb 26
@patch
def _lat_to_ytile(self: FastBingTileGridGenerator, lat: pl.Expr) -> pl.Expr:
logtan = pl.Expr.log(pl.Expr.tan((np.pi / 4) + (pl.Expr.radians(lat) / 2)))
Expand Down
Loading

0 comments on commit 2f757c3

Please sign in to comment.