Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 21, 2024
1 parent e0856b3 commit 1b1498e
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/compare_covermaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,23 @@ def get_binary_image(self, aoi, projection="EPSG:4326"):

return binary_image.rename("crop")

def compute_map_area(self, country: str, dataset_name, projection="EPSG:4326", tile_grid=[1, 1], export=False):
def compute_map_area(
self, country: str, dataset_name, projection="EPSG:4326", tile_grid=[1, 1], export=False
):
aoi = ee.FeatureCollection("FAO/GAUL/2015/level0").filter(
ee.Filter.eq("ADM0_NAME", country)
)

binary_image = self.get_binary_image(aoi=aoi, projection=projection)

if tile_grid == [1, 1]:
crop_px_sum = (
binary_image.reduceRegion(
reducer=ee.Reducer.sum().unweighted(),
geometry=aoi.geometry(),
scale=self.resolution,
maxPixels=MAX_PIXELS,
bestEffort=True,
)
.get("crop")
)
crop_px_sum = binary_image.reduceRegion(
reducer=ee.Reducer.sum().unweighted(),
geometry=aoi.geometry(),
scale=self.resolution,
maxPixels=MAX_PIXELS,
bestEffort=True,
).get("crop")
noncrop_px_sum = (
binary_image.Not()
.reduceRegion(
Expand All @@ -271,14 +270,16 @@ def compute_map_area(self, country: str, dataset_name, projection="EPSG:4326", t
if export:
# export the computation and retrieve result later
export_task = ee.batch.Export.table.toDrive(
collection = ee.FeatureCollection([
ee.Feature(None, {'crop_sum': crop_px_sum, 'noncrop_sum': noncrop_px_sum})
]),
description=f'Crop_NonCrop_Area_Sum_Export-{country}-{dataset_name}',
fileFormat='CSV'
collection=ee.FeatureCollection(
[ee.Feature(None, {"crop_sum": crop_px_sum, "noncrop_sum": noncrop_px_sum})]
),
description=f"Crop_NonCrop_Area_Sum_Export-{country}-{dataset_name}",
fileFormat="CSV",
)
export_task.start()
print(f'Export task started for {dataset_name} map of {country}. Returning null area for now.')
print(
f"Export task started for {dataset_name} map of {country}. Returning null area for now."
)
a_j = np.array([None, None])

else:
Expand Down Expand Up @@ -622,16 +623,13 @@ def get_ensemble_area(country: str, covermaps, tile_grid=[1, 1], export=False):
min_scale = min([c.resolution for c in covermaps])

if tile_grid == [1, 1]:
crop_px_sum = (
ensemble_image.reduceRegion(
reducer=ee.Reducer.sum().unweighted(),
geometry=aoi.geometry(),
scale=min_scale,
maxPixels=MAX_PIXELS,
bestEffort=True,
)
.get("crop")
)
crop_px_sum = ensemble_image.reduceRegion(
reducer=ee.Reducer.sum().unweighted(),
geometry=aoi.geometry(),
scale=min_scale,
maxPixels=MAX_PIXELS,
bestEffort=True,
).get("crop")
noncrop_px_sum = (
ensemble_image.Not()
.reduceRegion(
Expand All @@ -647,14 +645,16 @@ def get_ensemble_area(country: str, covermaps, tile_grid=[1, 1], export=False):
if export:
# export the computation and retrieve result later
export_task = ee.batch.Export.table.toDrive(
collection=ee.FeatureCollection([
ee.Feature(None, {'crop_sum': crop_px_sum, 'noncrop_sum': noncrop_px_sum})
]),
description=f'Crop_NonCrop_Ensemble_Area_Sum_Export-{country}',
fileFormat='CSV'
collection=ee.FeatureCollection(
[ee.Feature(None, {"crop_sum": crop_px_sum, "noncrop_sum": noncrop_px_sum})]
),
description=f"Crop_NonCrop_Ensemble_Area_Sum_Export-{country}",
fileFormat="CSV",
)
export_task.start()
print(f'Export task started for ensemble map of {country}. Returning null area for now.')
print(
f"Export task started for ensemble map of {country}. Returning null area for now."
)
a_j = np.array([None, None])

else:
Expand Down

0 comments on commit 1b1498e

Please sign in to comment.