Guest User

Untitled

a guest
Jul 8th, 2023
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. // VERSION=3
  2. // QuickFire V1.0.0 by Pierre Markuse (https://twitter.com/Pierre_Markuse)
  3. // Made for use in the Sentinel Hub EO Browser (https://apps.sentinel-hub.com/eo-browser/?)
  4. // CC BY 4.0 International (https://creativecommons.org/licenses/by/4.0/)
  5.  
  6. function setup() {
  7. return {
  8. input: ["B01","B02","B03","B04","B08","B8A","B11","B12","CLP", "dataMask"],
  9. output: { bands: 4 }
  10. };
  11. }
  12.  
  13. function stretch(val, min, max) {return (val - min) / (max - min);}
  14.  
  15. function satEnh(arr, s) {
  16. var avg = arr.reduce((a, b) => a + b, 0) / arr.length;
  17. return arr.map(a => avg * (1 - s) + a * s);
  18. }
  19.  
  20. function layerBlend(lay1, lay2, lay3, op1, op2, op3) {
  21. return lay1.map(function(num, index) {
  22. return (num / 100 * op1 + (lay2[index] / 100 * op2) + (lay3[index] / 100 * op3));
  23. });
  24. }
  25.  
  26. function evaluatePixel(sample) {
  27. const hsThreshold = [2.0, 1.5, 1.25, 1.0];
  28. const hotspot = 1;
  29. const style = 1;
  30. const hsSensitivity = 1.0;
  31. const boost = 1;
  32.  
  33. const cloudAvoidance = 1;
  34. const cloudAvoidanceThreshold = 245;
  35. const avoidanceHelper = 0.8;
  36.  
  37. const offset = -0.000;
  38. const saturation = 1.10;
  39. const brightness = 1.00;
  40. const sMin = 0.01;
  41. const sMax = 0.99;
  42.  
  43. const showBurnscars = 0;
  44. const burnscarThreshold = -0.25;
  45. const burnscarStrength = 0.3;
  46.  
  47. const NDWI = (sample.B03-sample.B08)/(sample.B03+sample.B08);
  48. const NDVI = (sample.B08-sample.B04)/(sample.B08+sample.B04);
  49. const waterHighlight = 0;
  50. const waterBoost = 2.0;
  51. const NDVI_threshold = -0.15;
  52. const NDWI_threshold = 0.15;
  53. const waterHelper = 0.2;
  54.  
  55. const Black = [0, 0, 0];
  56. const NBRindex = (sample.B08-sample.B12) / (sample.B08+sample.B12);
  57. const naturalColorsCC = [Math.sqrt(brightness * sample.B04 + offset), Math.sqrt(brightness * sample.B03 + offset), Math.sqrt(brightness * sample.B02 + offset)];
  58. const naturalColors = [(2.5 * brightness * sample.B04 + offset), (2.5 * brightness * sample.B03 + offset), (2.5 * brightness * sample.B02 + offset)];
  59. const URBAN = [Math.sqrt(brightness * sample.B12 * 1.2 + offset), Math.sqrt(brightness * sample.B11 * 1.4 + offset), Math.sqrt(brightness * sample.B04 + offset)];
  60. const SWIR = [Math.sqrt(brightness * sample.B12 + offset), Math.sqrt(brightness * sample.B8A + offset), Math.sqrt(brightness * sample.B04 + offset)];
  61. const NIRblue = colorBlend(sample.B08, [0, 0.25, 1], [[0/255, 0/255, 0/255],[0/255, 100/255, 175/255],[150/255, 230/255, 255/255]]);
  62. const classicFalse = [sample.B08 * brightness, sample.B04 * brightness, sample.B03 * brightness];
  63. const NIR = [sample.B08 * brightness, sample.B08 * brightness, sample.B08 * brightness];
  64. const atmoPen = [sample.B12 * brightness, sample.B11 * brightness, sample.B08 * brightness];
  65. var enhNaturalColors = [0, 0, 0];
  66. for (let i = 0; i < 3; i += 1) { enhNaturalColors[i] = (brightness * ((naturalColors[i] + naturalColorsCC[i]) / 2) + (URBAN[i] / 10)); }
  67.  
  68. const manualCorrection = [0.00, 0.00, 0.00];
  69.  
  70. var Viz = layerBlend(URBAN, naturalColors, naturalColorsCC, 10, 40, 50); // Choose visualization(s) and opacity here
  71.  
  72. if (waterHighlight) {
  73. if ((NDVI < NDVI_threshold) && (NDWI > NDWI_threshold) && (sample.B04 < waterHelper)) {
  74. Viz[1] = Viz[1] * 1.2 * waterBoost + 0.1;
  75. Viz[2] = Viz[2] * 1.5 * waterBoost + 0.2;
  76. }
  77. }
  78.  
  79. Viz = satEnh(Viz, saturation);
  80. for (let i = 0; i < 3; i += 1) {
  81. Viz[i] = stretch(Viz[i], sMin, sMax);
  82. Viz[i] += manualCorrection[i];
  83. }
  84.  
  85. if (hotspot) {
  86. if ((!cloudAvoidance) || ((sample.CLP<cloudAvoidanceThreshold) && (sample.B02<avoidanceHelper))) {
  87. switch (style) {
  88. case 1:
  89. if ((sample.B12 + sample.B11) > (hsThreshold[0] / hsSensitivity)) return [((boost * 0.50 * sample.B12)+Viz[0]), ((boost * 0.50 * sample.B11)+Viz[1]), Viz[2], sample.dataMask];
  90. if ((sample.B12 + sample.B11) > (hsThreshold[1] / hsSensitivity)) return [((boost * 0.50 * sample.B12)+Viz[0]), ((boost * 0.20 * sample.B11)+Viz[1]), Viz[2], sample.dataMask];
  91. if ((sample.B12 + sample.B11) > (hsThreshold[2] / hsSensitivity)) return [((boost * 0.50 * sample.B12)+Viz[0]), ((boost * 0.10 * sample.B11)+Viz[1]), Viz[2], sample.dataMask];
  92. if ((sample.B12 + sample.B11) > (hsThreshold[3] / hsSensitivity)) return [((boost * 0.50 * sample.B12)+Viz[0]), ((boost * 0.00 * sample.B11)+Viz[1]), Viz[2], sample.dataMask];
  93. break;
  94. case 2:
  95. if ((sample.B12 + sample.B11) > (hsThreshold[3] / hsSensitivity)) return [1, 0, 0, sample.dataMask];
  96. break;
  97. case 3:
  98. if ((sample.B12 + sample.B11) > (hsThreshold[3] / hsSensitivity)) return [1, 1, 0, sample.dataMask];
  99. break;
  100. case 4:
  101. if ((sample.B12 + sample.B11) > (hsThreshold[3] / hsSensitivity)) return [Viz[0] + 0.2, Viz[1] - 0.2, Viz[2] - 0.2, sample.dataMask];
  102. break;
  103. default:
  104. }
  105. }
  106. }
  107.  
  108. if (showBurnscars) {
  109. if (NBRindex<burnscarThreshold) {
  110. Viz[0] = Viz[0] + burnscarStrength;
  111. Viz[1] = Viz[1] + burnscarStrength;
  112. }
  113. }
  114.  
  115. return [Viz[0], Viz[1], Viz[2], sample.dataMask];
  116. }
Advertisement
Add Comment
Please, Sign In to add comment