I am trying to calculate more complex band calculations with S2 and am really struggling. It seems that I cannot express the equation correctly, but am at a loss on how to fix. Thanks kindly for any help.
S2REP= Chlorophyll and N Status
#S2REP = 705 + 35 * ((Red1 + NIR)/2) - Red2 / (Red3 - Red2))
#where: B7 = 783 nm, B6 = 740 nm, B5 = 705 nm, B4 = 665 nm
#S2REP = 705 + 35 * ((Red1 + NIR)/2) - Red2 / (Red3 - Red2))
#For Sentinel-2 the formula is:
705 + 35 * ((B4 + B7)/2) - B5 / (B6 - B5)),
#where: B7 = 783 nm, B6 = 740 nm, B5 = 705 nm, B4 = 665 nm
zs2 = function(data, context) {
B04 ← data[3] # Red
B07 ← data[6]
B05 ← data[4]
B06 <-data[5]
(740 * ((B04+B07)/2)- B05) / (B06-B05)
}
calc_zs2 = p$reduce_dimension(data = data,
dimension = “bands”,
reducer = zs2)
xs2 = p$aggregate_temporal_period(data = calc_zs2, period = “time_range”,
reducer = function(data, context){p$median(data)},
dimension = “t”)
s2repcube = p$save_result(data = xs2, format=“GeoTIFF”)
Hi,
What error do you have? Do you have a job-id to share?
Job-ids look like this: j-24xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Emile
I think that I have a similar problem. My goal is to compute some indices for a whole tile of Sentinel-2. I started by testing the tutorial code with mixed results. This is the code that I used:
library(openeo)
image_repository = connect(host = "https://openeo.dataspace.copernicus.eu/openeo/1.2")
login()
####Tutorial test####
p = processes()
pellworm <- list(west = 8.5464, south = 54.4473, east = 9.0724, north = 54.5685)
t <- c("2021-03-05", "2021-03-15")
cube_s2 <- p$load_collection(
id = "SENTINEL2_L2A",
spatial_extent = pellworm,
temporal_extent = t,
bands=c("B02", "B04", "B08", "SCL")
)
# define an NDVI function
ndvi_function <- function(data, context) {
B04 <- data["B04"] # we can supply an index (1-based in R) ..
B08 <- data["B08"] # or a label
# ndvi <- (B08 - B04) / (B08 + B04) # implement NDVI as formula ..
ndvi <- p$normalized_difference(B08, B04) # or use the openEO "normalized_difference" process
# ndvi <- p$normalized_difference(data[2], data[3]) # or shorten all in one line
return(ndvi)
}
#Test the custom function
# supply the defined function to a reduce_dimension process, set dimension = "bands"
cube_s2_ndvi_function <- p$reduce_dimension(data = cube_s2, reducer = ndvi_function, dimension = "bands")
cube_s2_ndvi_save <- p$save_result(data = cube_s2_ndvi_function, format = "GTiff")
job_function = create_job(graph=cube_s2_ndvi_save,title = "Tutorial_Function")
#Use the OpenEO NDVI function
cube_s2_nvdi_bands <- p$ndvi(data = cube_s2, nir = "B08", red = "B04", target_band = "NDVI")
cube_s2_nvdi_bands_save <- p$save_result(data = cube_s2_nvdi_bands, format = "GTiff")
job_direct = create_job(graph=cube_s2_nvdi_bands_save, title = "Tutorial_Direct")
start_job(job = job_function)
start_job(job = job_direct)
When I use the custom function, the process fails, but when I use the NDVI function from OpenEO, it finishes correctly.
The ID of the first failed test is: j-24111169feb94229a9a7fdf2baf11c14
The ID of the finished test is: j-2411111f90ee4bdcb971154b8320317b
I need to be able to use a custom index function that is different from the normalised difference.
Possible workarounds that seem to work at the moment:
- use synchronous download (instead of batch jobs)
- download in netCDF format (instead of GeoTIFF)