Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

439
Views
Translating JavaScript into R: secondary sentinel products

I'm trying to translate the following JavaScript into R but having problems:

/*
Author of the script: Carlos Bentes
*/

// Normalized Difference Vegetation Index
var ndvi = (B08-B04)/(B08+B04);

// Threshold for vegetation
var veg_th = 0.4;

// Simple RGB
var R = 2.5*B04;
var G = 2.5*B03;
var B = 2.5*B02;

// Transform to Black and White
var Y = 0.2*R + 0.7*G + 0.1*B;
var pixel = [Y, Y, Y];

// Change vegetation color
if(ndvi >= veg_th)
  pixel = [0.1*Y, 1.8*Y, 0.1*Y];

return pixel;

This is the Green City Index which is part of the repository of custom scripts that can be used with Sentinel-Hub services.

Specifically I'm having issues with:

var pixel = [Y, Y, Y];

And

if(ndvi >= veg_th)
  pixel = [0.1*Y, 1.8*Y, 0.1*Y];

return pixel;

I think var pixel = [Y, Y, Y]; is the same as pixel <- c(Y, Y, Y)? Which means in the if statement I'd have:

if(ndvi >= veg_th){ 
   pixel <- c(0.1*Y, 1.8*Y, 0.1*Y) 
   return(pixel)
}

But I'm getting an error:

Error in if (ndvi >= veg_th) { : argument is not interpretable as logical

Some notes about the parts I do understand for those not familiar with sentinel:

  • B04 and B08 are raster bands from Sentinel so
  • ndvi is a raster as well (normalized difference vegetation index)
  • veg_th is a value set as a threshold for interpreting results of ndvi
  • R, G, and B are making a color composite from the sentinel rasters
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!