Re: Image division causes Floating illegal operand [message #48747] |
Fri, 19 May 2006 09:11 |
David Streutker
Messages: 34 Registered: June 2005
|
Member |
|
|
Is your mask made up of zeros and ones? If so, you are dividing by
zero in all of the masked pixels, causing the error. Because you are
already masking the numerator (partA), it's redundant to mask the
denominator (partB). Try using:
partA = (b1*coef[0,1] - b0*coef[0,0])*mask
partB = b1*coef[0,1] + b0*coef[0,0]
Alternatively, you could apply the mask to the NDVI image itself.
|
|
|
Re: Image division causes Floating illegal operand [message #48764 is a reply to message #48747] |
Thu, 18 May 2006 11:13  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Paul Van Delst wrote:
> elsueniero@gmail.com wrote:
>
>> Hello,
>>
>> I am writing a small program to calculate NDVI from MODIS images. I
>> got a mask of the valid pixels (no clouds or water) and two calibration
>> coefficients. The code is
>>
>> partA = (b1*coef[0,1] - b0*coef[0,0])*mask
>> partB = (b1*coef[0,1] + b0*coef[0,0])*mask
>>
>> ndviimg = partA / partB
>
>
> Won't this always be 1.0 ?? :o)
Oops... didn't notice the +/-.
ehem.
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
|
|
|
Re: Image division causes Floating illegal operand [message #48765 is a reply to message #48764] |
Thu, 18 May 2006 11:13  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
elsueniero@gmail.com wrote:
> Hello,
>
> I am writing a small program to calculate NDVI from MODIS images. I
> got a mask of the valid pixels (no clouds or water) and two calibration
> coefficients. The code is
>
> partA = (b1*coef[0,1] - b0*coef[0,0])*mask
> partB = (b1*coef[0,1] + b0*coef[0,0])*mask
>
> ndviimg = partA / partB
Won't this always be 1.0 ?? :o)
>
> ind = Where(Finite(ndviimg, /NAN), count)
> IF count GT 0 THEN ndviimg[ind] = -1000.0
>
> But I allways get an "Program caused arithmetic error: Floating illegal
> operand" even if the resulting image looks good.
> The problem is in the division, because if I comment the line, it won't
> show.
>
> Any ideas how to avoid this?
You can try something like,
partA = (b1*coef[0,1] - b0*coef[0,0])*mask
ndviimg = (b1*coef[0,1] + b0*coef[0,0])*mask
Idx=WHERE(ABS(ndviimg) GT 0.0, Count, $
COMPLEMENT=ZeroIdx, NCOMPLEMENT=ZeroCount)
IF (Count GT 0) THEN ndviimg[Idx] = partA[Idx] / ndviimg[Idx]
IF (ZeroCount GT 0) THEN ndviimg[ZeroIdx] = -1000.0
I think there's a faster way to do this though. Probably using HISTOGRAM. :o)
paulv
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
|
|
|