pull/746/head
Piero Toffanin 2019-11-19 12:51:17 -05:00
rodzic 1c590e6bd4
commit bc67dc9a51
3 zmienionych plików z 49 dodań i 12 usunięć

Wyświetl plik

@ -1,25 +1,44 @@
# Algos from https://github.com/dirceup/tiled-vegetation-indices/blob/master/app/lib/vegetation_index.rb
import re
from functools import lru_cache
# Functions can use all of the supported functions and operators from
# https://numexpr.readthedocs.io/en/latest/user_guide.html#supported-operators
algos = {
'vari': {
'VARI': {
'bands': 'RGB',
'expr': '(G-R)/(G+R-B)'
'expr': '(G - R) / (G + R - B)',
'help': 'Visual Atmospheric Resistance Index shows the areas of vegetation.'
},
'NDVI': {
'bands': 'RGN',
'expr': '(N - R) / (N + R)',
'help': 'Normalized Difference Vegetation Index shows the amount of green vegetation.'
},
'BAI': {
'bands': 'RGN',
'expr': '1.0 / (((0.1 - R) ** 2) + ((0.06 - N) ** 2))',
'help': 'Burn Area Index hightlights burned land in the red to near-infrared spectrum.'
},
'GLI': {
'bands': 'RGB',
'expr': '((G * 2) - R - B) / ((G * 2) + R + B)',
'help': 'Green Leaf Index shows greens leaves and stems.'
},
'GNDVI':{
'bands': 'RGN',
'expr': '(N - G) / (N + G)',
'help': 'Green Normalized Difference Vegetation Index is similar to NDVI, but measures the green spectrum instead of red.'
},
'TEST': {
'_TESTRB': {
'bands': 'RGB',
'expr': 'B+R'
}
}
band_map = {
'RGB': (0, 1, 2),
'BGR': (2, 1, 0),
}
#@lru_cache(max_size=20)
def lookup_formula(algo, band_order = 'RGB'):
if algo is None:
return None
@ -38,4 +57,4 @@ def lookup_formula(algo, band_order = 'RGB'):
b = matches.group(1)
return 'b' + str(input_bands.index(algo_bands.index(b)) + 1)
return re.sub("([A-Z]+?[a-z]*)", repl, algos[algo]['expr'])
return re.sub("([A-Z]+?[a-z]*)", repl, re.sub("\s+", "", algos[algo]['expr']))

Wyświetl plik

@ -94,7 +94,7 @@ class Map extends React.Component {
const { url, meta, type } = tile;
let metaUrl = url + "metadata";
if (type == "plant") metaUrl += "?formula=vari&bands=RGB&rescale=0.02,0.1&color_map=rdylgn";
if (type == "plant") metaUrl += "?formula=GLI&bands=RGB&rescale=-1,1&color_map=rdylgn";
if (type == "dsm") metaUrl += "?rescale=156%2C165&hillshade=3&color_map=jet_r";
console.log(type, metaUrl);

Wyświetl plik

@ -0,0 +1,18 @@
from django.test import TestCase
from app.api.formulas import lookup_formula
class TestFormulas(TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_formulas(self):
# Original
self.assertTrue(lookup_formula("_TESTRB", "RGB") == "b3+b1")
# Swap bands
self.assertTrue(lookup_formula("_TESTRB", "BGR") == "b1+b3")
self.assertTrue(lookup_formula("_TESTRB", "NRB") == "b2+b3")