Resampling a datacube on a user-defined regular grid

Dear OpenEO forum,

I am struggling to get my datacube sampled on my target sampling grid, e. g. something defined by a CRS, the coordinate of the upper-left pixel (either center or upper-left corner of this pixel), spacing between pixels and number of pixels in both direction.

According to the documentation, resample_cube_spatial(*target*, *method='near'* ) can do that but I would need to create a dummy datacube with the correct sampling grid to be used as the target parameter.

On the other end, resample_spatial(*resolution*, *projection=None*, *method='near'*, *align='upper-left'* ) allows to resample to another spatial resolution but gives no control over the sampling grid, which I believe is computed from the input datacube.

This is a very important capability when working with two different sensors. I am currently working with Sentinel-2 (10m) and Landsat series (30m), and I do not want OpenEO to resample everything to 10m (which I can do with resample_spatial). I want both series to retain their native resolution, but I want them sampled so that they footprints match exactly, meaning that the upper-left corner of their upper-left pixels and lower right corner of their lower-right pixels align. I can only do that by resampling both of them to user defined phased sampling grid, hence this question.

What I would need is an extended version of the resample_spatial method:

resample_spatial(upper_left_pixel_center_coords, resolution, grid_size, projection=None, method=‘near’)
Where:

  • upper_left_pixel_center_coords is the coordinates of the center of the upper-left pixel
  • grid_size is the number of pixels in each spatial dimension

If the backend relies on Gdal, I am pretty sure this is only a matter of extending the API.

Many thanks for your help,

Regards,

Julien

Hi Julien,
I can mostly confirm your detailed analysis. There are indeed cases where you want to align to a certain grid while keeping other parameters.
We have some rules in place that work well for a number of cases, but sometimes you just want to tell the backend to align to a certain grid. Perhaps my colleagues @m.mohr , @michele.claus or @lukas.weidenholzer also have some thoughts on this.

I did try out your first suggestion based on resample_cube_spatial, which actually should work, but the output did not have the alignment I expected, so I’m going to investigate further and perhaps log an issue.

 s2 = con.load_collection(
      "SENTINEL2_L2A",
      spatial_extent={
          "west": 429770, "east": 433955, "south": 4666780, "north": 4672295,
          "crs": 32631,
      },
      temporal_extent=["2023-06-01", "2023-06-10"],
      bands=["B04"],
  )

  cube = con.load_collection(
      "LANDSAT8-9_L2",
      spatial_extent={
          "west": 429771, "east": 433957, "south": 4666781, "north": 4672293,
          "crs": 32631,
      },
      temporal_extent=["2023-06-01", "2023-06-10"],
      bands=["B04"],
  )
  cube.resample_cube_spatial(s2.resample_spatial(resolution=30)).download("landsat2.nc")