Skip to content

Commit

Permalink
Merge pull request #67 from earth-chris/annotation-progress
Browse files Browse the repository at this point in the history
add progress bar to point annotation
  • Loading branch information
Christopher Anderson authored Oct 5, 2022
2 parents 574e80f + 6450a12 commit b5c6229
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions elapid/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)

tqdm = get_tqdm()
tqdm_opts = {"bar_format": "{l_bar}{bar:20}{r_bar}{bar:-20b}"}
tqdm_opts = {"bar_format": "{l_bar}{bar:30}{r_bar}{bar:-30b}"}

# sampling tools

Expand Down Expand Up @@ -284,24 +284,6 @@ def crs_match(crs1: CRSType, crs2: CRSType) -> bool:
# raster reading tools


def _read_pixel_value(point: gpd.GeoSeries, source: rio.io.DatasetReader) -> np.ndarray:
"""Reads raster value from an open rasterio dataset.
Designed to be run using a `geodataframe.apply()` function.
Args:
point: a row from gdf.apply() or gdf.iterrows()
source: an open rasterio data source
Returns:
values: 1-d n-length array with the pixel values of each raster band.
"""
row, col = source.index(point.geometry.x, point.geometry.y)
window = rio.windows.Window(col, row, 1, 1)
values = source.read(window=window, boundless=True)
return np.squeeze(values)


def annotate(
points: Union[str, gpd.GeoSeries, gpd.GeoDataFrame],
raster_paths: Union[str, list],
Expand Down Expand Up @@ -425,7 +407,11 @@ def annotate_geoseries(
xys = [(point.x, point.y) for point in points]

# read each pixel value
samples = np.array(list(src.sample(xys, masked=False)), dtype=dtype)
n_points = len(points)
samples_iter = list(
tqdm(src.sample(xys, masked=False), desc="Sample", total=n_points, leave=False, **tqdm_opts)
)
samples = np.array(samples_iter, dtype=dtype)

# identify nodata points to remove later
if drop_na and src.nodata is not None:
Expand Down

0 comments on commit b5c6229

Please sign in to comment.