Skip to content

Commit

Permalink
Drop duplicates, fix typo, uncomment compute_stats function.
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowcap committed Nov 16, 2023
1 parent 18e9bd1 commit 211699c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scripts/landcover.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def process(wd, worldcover, mgrs):
"""
Run statistics and sampling.
"""
# compute_stats(wd, worldcover, mgrs)
compute_stats(wd, worldcover, mgrs)
sample(wd)


Expand All @@ -88,9 +88,11 @@ def compute_stats(wd, worldcover, mgrs):
parts = shape(tile["geometry"]).geoms
pixels = []
for polygon in parts:
bounds = from_bounds(*polygon.bounds, cover.transform)
pixels.append(
cover.read(
1, window=from_bounds(*polygon.bounds, cover.transform)
1,
window=bounds,
).ravel()
)
pixels = numpy.hstack(pixels)
Expand Down Expand Up @@ -127,7 +129,7 @@ def compute_stats(wd, worldcover, mgrs):

def split_highest(data, column, size, pool=1000, seed=RANDOM_SEED):
"""
Split hightest values of a cloumn from a dataframe.
Split highest values of a column from a dataframe.
"""
data.sort_values(column, ascending=False, inplace=True)
return data[:pool].sample(size, random_state=seed)
Expand Down Expand Up @@ -195,6 +197,8 @@ def sample(wd):
]
)

result = result.drop_duplicates(subset=["name"])

result.to_file(Path(wd, "mgrs_sample.geojson", driver="GeoJSON"))


Expand Down

0 comments on commit 211699c

Please sign in to comment.