Please see the code below. I have noticed some odd results in NDVI results and square roots of data that has units of "%" or a Universal Unit.
1.) For division, when a result should be unitless, the unit of percent is retained. This leads to an unexpected magnitude.
2.) I can't explain what is happening with the Universal Unit, it does not make much sense to me. Please see code below and if you have questions about the problem, we can discuss that. There seems to be a division by 100 when using he square root function and I don't understand why.
3.) The results seem as expected if the unit is forced to None before calculation. In a whatType(data), the unit is reported as null.
Code: Select all
parmsList=dict(
#accounting = ('YOU',9999), #accounting information required
#if ADDE dataset is not registered
#in ADDE Manager
server='dcarchivex.ssec.wisc.edu',
dataset='GREX',
descriptor='FD',
band=1,
day='2016277',
time=('16:04', '16:09'),
position='ALL'
)
dateTimes=listADDEImageTimes(**parmsList)
if (len(dateTimes) >= 1):
#panel=buildWindow(height=900,width=900)[0]
for dateTime in dateTimes[::2]:
index=1
parms=dict(
#accounting = ('YOU',9999), #accounting information required
#if ADDE dataset is not registered
#in ADDE Manager
server=parmsList['server'],
dataset=parmsList['dataset'],
descriptor='FD',
day=dateTime['day'],
time=dateTime['time'],
unit='ALB',
location=(0.1,-98.4),
coordinateSystem=LATLON,
place=ULEFT,
mag=(1,1)
)
rdata=loadADDEImage(band=2, size=(8,8), **parms)
gdata=loadADDEImage(band=3, size=(4,4), **parms)
g_ds=getDomainSet(gdata)
rdata=resample(rdata,g_ds)
testSubtraction=sub(gdata,rdata)
testAddition=sub(gdata,-rdata)
normalizedField=testSubtraction/testAddition
print (gdata.getRangeUnits()[0][0])
print 'Green Band Min/Max: {}/{} {}\n'.format(getMinMax(gdata)[0], getMinMax(gdata)[1], '%')
sqrt_gdata=sqrt(gdata)
print 'Sqrt of Green Band Min/Max requires unit to make sense {}/{} {}\n'.format(getMinMax(sqrt_gdata)[0], getMinMax(sqrt_gdata)[1],'%')
print 'The NDVI unit does not make sense, because the result should be unitless. If this result is unitless, then the magnitude is incorrect.'
print 'NDVI Min/Max should be between -1/1 but: {}/{} {}\n'.format(getMinMax(normalizedField)[0],getMinMax(normalizedField)[1] , '%')
newRed=noUnit(rdata)
newGreen=noUnit(gdata)
testSubtraction=sub(newGreen,newRed)
testAddition=sub(newGreen,-newRed)
normalizedField=testSubtraction/testAddition
print whatType(newGreen)
print 'Green Band Min/Max: {}/{} {}'.format(getMinMax(newGreen)[0], getMinMax(newGreen)[1], '1')
sqrt_rdata=sqrt(newRed)
print 'If the unit is removed, sqrt should be 1.11/2.21, correct? Try using noUnit'
print 'Sqrt of Green Band Min/Max divides by 100 (not the numbers expected)? {}/{}'.format(getMinMax(sqrt_gdata)[0], getMinMax(sqrt_gdata)[1],'1')
print 'NDVI Min/Max should be between -1/1 and this seems to be okay: {}/{} {}'.format(getMinMax(normalizedField)[0],getMinMax(normalizedField)[1] , '1')
print 'Try making the unit None'
noneUnitRed=newUnit(rdata,'Band2_ALB',None)
noneUnitGreen=newUnit(gdata,'Band3_ALB',None)
testSubtraction=sub(noneUnitGreen,noneUnitRed)
testAddition=sub(noneUnitGreen,-noneUnitRed)
normalizedField=testSubtraction/testAddition
print whatType(noneUnitGreen)
print 'Green Band Min/Max: {}/{} {}'.format(getMinMax(noneUnitGreen)[0], getMinMax(noneUnitGreen)[1], 'Null')
sqrt_rdata=sqrt(noneUnitRed)
print 'If the unit is removed, sqrt should be 1.11/2.21, correct? Try using noUnit'
print 'Sqrt of Green Band Min/Max divides by 100? {}/{}'.format(getMinMax(sqrt_gdata)[0], getMinMax(sqrt_gdata)[1],'Null')
print 'NDVI Min/Max should be between -1/1 and this seems to be okay: {}/{} {}'.format(getMinMax(normalizedField)[0],getMinMax(normalizedField)[1] , 'Null')
Thanks,
Joleen