Skip to content

Commit

Permalink
adjusted raw_datacube_s2 to also handle point extractions
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentVerelst committed Jun 12, 2024
1 parent a5fa384 commit dcb95e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
5 changes: 3 additions & 2 deletions scripts/extractions/patch_extractions/extract_optical.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ def create_datacube_optical(
bands_to_download,
FetchType.POLYGON,
filter_tile=s2_tile,
apply_mask=False,
additional_masks=True,
distance_to_cloud_flag=True,
apply_mask_flag=False,
additional_masks_flag=True,
)

# Increase the memory of the jobs depending on the number of polygons to extract
Expand Down
20 changes: 3 additions & 17 deletions scripts/extractions/point_extractions/point_extractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import geopandas as gpd
import openeo
import pandas as pd
from openeo.processes import ProcessBuilder, array_create
from openeo_gfmap import Backend, BackendContext, FetchType, TemporalContext
from openeo_gfmap.backend import cdse_connection
from openeo_gfmap.fetching.s2 import build_sentinel2_l2a_extractor
from openeo_gfmap.manager.job_manager import GFMAPJobManager
from openeo_gfmap.manager.job_splitters import split_job_s2grid
from openeo_gfmap.preprocessing import linear_interpolation, median_compositing
Expand Down Expand Up @@ -146,7 +144,7 @@ def create_datacube(
backend = Backend(row.backend_name)
backend_context = BackendContext(backend)

# Select some bands to download (chosen at random at this point)
# TODO: Adjust this to the desired bands to download
bands_to_download = [
"S2-L2A-B04",
"S2-L2A-B08",
Expand All @@ -166,24 +164,12 @@ def create_datacube(
apply_mask_flag=True,
)

cube = 2.5 * (cube.band('S2-L2A-B08') - cube.band('S2-L2A-B04')) / \
(cube.band('S2-L2A-B08') + 2.4 * cube.band('S2-L2A-B04') + 1)
cube = cube.add_dimension("bands", 'S2-L2A-EVI', "bands")

# Create monthly median composites
cube = median_compositing(cube=cube, period="month")

# Perform linear interpolation
cube = linear_interpolation(cube)
# # Map the time dimension to the bands dimension
# nsteps = 20
# cube = cube.apply_dimension(dimension='t',
# target_dimension='bands',
# process=lambda d: array_create(data=d),
# )

# tstep_labels = [f'S2-L2A-EVI_t{i}' for i in range(0,nsteps)]
# cube = cube.rename_labels('bands', tstep_labels)


# Finally, create a vector cube based on the Point geometries
cube = cube.aggregate_spatial(geometries=spatial_extent, reducer="mean")

Expand Down
5 changes: 3 additions & 2 deletions src/worldcereal/openeo/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ def worldcereal_preprocessed_inputs_gfmap(
],
fetch_type=FetchType.TILE,
filter_tile=False,
additional_masks=False,
apply_mask=True,
distance_to_cloud_flag=True,
additional_masks_flag=False,
apply_mask_flag=True,
)

s2_data = median_compositing(s2_data, period="month")
Expand Down

0 comments on commit dcb95e9

Please sign in to comment.