Why does the manual pansharpen not work for Landsat 7?

Using the simple pansharpen script for Landsat 8


I adjust for the band order, B04 -> B03, B03 -> B02, B02 -> B01,
B08 remains the same

weight = (B03 + B02 + B01 * 0.4) / 2.4;

if (weight == 0) {
return [0, 0, 0];
ratio = B08/weight * 2.5;
return [B03*ratio, B02*ratio, B01*ratio];

Yet it returns no image.


Landsat 7 is running on a legacy version of Sentinel Hub, where there are different constraints for the Custom script.

If you try this, it should work:

var w = (B03 + B02 + B01 * 0.4) / 2.4;

if (w == 0) {
return [0, 0, 0];
var ratio = B08/w * 2.5;
return [B03*ratio, B02*ratio, B01*ratio];
1 Like

Ah, so basically just the ‘var’ callouts in js. Can we consider this a ‘best practise’ if something doesnt work in the scripts in general, to revert back to the simpler js annotations?

JavaScript is indeed the basic layer of Custom scripts. We use V8 engine to compile this to Java in real-time so there are some limitations related to this, but most of the JavaScript functions are supported.

The “var” part is standard for JavaScript but it seems that in the latest versions “sloppy code” support handles this (better than in the old version).
I updated the FAQ accordingly.

I am not 100% sure but when testing it myself I noticed that word “weight” is also causing some issues in the new script, not sure though why…