Skip to content

Commit

Permalink
bug fixes, clipping in GEE
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddkovacs committed Dec 22, 2024
1 parent 8b69111 commit 62c5a2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
25 changes: 8 additions & 17 deletions pyeogpr/gee_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(
bounding_box[0], bounding_box[1], bounding_box[2], bounding_box[3]
)
if "projects/ee-" in bounding_box: # So it accepts shps too!
self.bbox = ee.FeatureCollection(bounding_box)
self.bbox = ee.FeatureCollection(bounding_box).geometry()
# self.bbox_fc2geo = ee.FeatureCollection(bounding_box).geometry()

self.temporal_extent = temporal_extent
Expand All @@ -115,11 +115,9 @@ def __init__(
spec.loader.exec_module(user_module)

self.model_imported = user_module
print(self.model_imported.hyp_sig0_GREEN)

else:
url = f"https://raw.githubusercontent.com/daviddkovacs/pyeogpr/refs/heads/main/models/{search_sensor}_{self.biovar}_GEE.py"
print(url)
response = requests.get(url)

with open("model_imported.py", "w") as f:
Expand All @@ -130,7 +128,7 @@ def __init__(
import model_imported

self.model_imported = model_imported
print(model_imported.hyp_sig0_GREEN)


self.imcol = ee.ImageCollection(self.sensor).filterDate(
ee.Date(self.temporal_extent[0]), ee.Date(self.temporal_extent[1])
Expand Down Expand Up @@ -224,11 +222,11 @@ def calculate_GREEN(self, fecha_inicio, fecha_fin, variable):
model = self.model_imported
image = ee.Image(
self.imcol.filterDate(fecha_inicio, fecha_fin)
.filterBounds(ee.FeatureCollection(self.bbox))
.filterBounds(self.bbox)
.map(self.maskS3badPixels)
.select(model.bands) # .cast(model.bands_dict, model.bands)
.max()
.clipToCollection(ee.FeatureCollection(self.bbox))
.clip(self.bbox)
)
# .clip(fc));
# TODO: I should play around with this .clip() here..
Expand Down Expand Up @@ -338,24 +336,17 @@ def maploop(self):
.eq(80)
)
lakemask = lakes.eq(0)
# image_export = image_export.mask(lakemask)
# image_export = image_export.mask(bare_cover)
image_export = image_export.mask(lakemask)
image_export = image_export.mask(bare_cover)

# SHP-bbox misery
region = None
if type(self.bbox) is list:
region=self.bbox
image_export = image_export.clip(region)
elif isinstance(self.bbox, ee.FeatureCollection):
region = self.bbox.geometry()
image_export = image_export.clip(region)

image_export = image_export.set(
"system:time_start",
ee.Date(self.temporal_extent[0])
.advance(ee.Number(i).multiply(self.timeWindows), "days")
.millis(),
)
image_export = image_export.clip(self.bbox)

# Export the image to an asset
exportar = ee.batch.Export.image.toAsset(
Expand All @@ -368,7 +359,7 @@ def maploop(self):
maxPixels=17210617060,
description=self.getInputDates(i)["fecha_str"] + "_" + self.biovar,
scale=self.spatial_resolution,
region = region, # .bounds().getInfo()['coordinates']
region = self.bbox, # .bounds().getInfo()['coordinates']
)
exportar.start()
exportar.status()
4 changes: 2 additions & 2 deletions pyeogpr/openeo_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Datacube:
- SENTINEL2_L1C: Cab, Cm, Cw, FVC, LAI, laiCab, laiCm, laiCw
- SENTINEL2_L2A: Cab, Cm, Cw, FVC, LAI, laiCab, laiCm, laiCw, CNC_Cab, CNC_Cprot
- SENTINEL3_OLCI_L1B: FAPAR, FVC, LAI, LCC
- for own model, simply put the directory of your model
bounding_box : list
Your region of interest. Insert bbox as list. Can be selected from https://geojson.io/
(e.g.: [-4.55, 42.73,-4.48, 42.77])
Expand Down Expand Up @@ -219,7 +220,6 @@ def process_map(self, gapfill=False, fileformat="nc"):
fileformat : string
For netCDF4: "nc", for tiff: "tiff".
Insert the dir of the model you developed with ARTMO. Just simply put the directory.
"""
Expand Down

0 comments on commit 62c5a2e

Please sign in to comment.