how to indentify infinite values in array

Post any questions, ideas, or topics related to Jython and Python scripting.
User avatar
Posts: 939
Joined: Mon Nov 15, 2010 5:57 pm

Re: how to indentify infinite values in array

Post by bobc »

Hi Joleen -

I'm having some trouble replicating your problem from your 02/10 post below:
This range of this ndvi should be -1 to 1. However, you see that the range is off by an order of magnitude. However, if the image is displayed and the data values are probed, it looks like the data values in the display are correct.

Here's the script I'm running:

Code: Select all

    time=('16:04', '16:09'),


if (len(dateTimes) >= 1):

    for dateTime in dateTimes[::2]:
       rdata=loadADDEImage(band=2, size=(8,8), **parms)
       gdata=loadADDEImage(band=3, size=(4,4), **parms)
       bdata=loadADDEImage(band=4, size=(2,2), **parms)
       rUnit=whatType(rdata).toString().rstrip().splitlines()[-1].split('Unit: ',1)[1]
       gUnit=whatType(gdata).toString().rstrip().splitlines()[-1].split('Unit: ',1)[1]
       bUnit=whatType(bdata).toString().rstrip().splitlines()[-1].split('Unit: ',1)[1]

       ndviDenom = sub(gdata,-rdata)
       ndviNumer = sub(gdata,rdata)
       ndviData = ndviNumer/ndviDenom

ndviLayer = activeDisplay().createLayer('Image Display',ndviData)
gridLayer = activeDisplay().createLayer('Grid Table', ndviData)

  • I changed nIRfield/nIRdata to 'gfield/gdata'.
  • I hadn't used the bluefield/bluedata earlier on so I added them to this script, though I'm not actually using them in the NDVI calculation.

Once I'm done the script, the enhancement range in the Main Display goes from -1 to 0.13, which matches the Grid Table output. I also ran 'describe(ndviData)' which had these same min/max values. I'm wondering if you are doing something extra in your script than I am, which looks to be possible since you are working with the bfield/bdata objects in the bit of code from your last post.

Thanks -
User avatar
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: how to indentify infinite values in array

Post by joleenf »

Hi Bob,

It will take me a bit to get back to this. We are opting to go with another routine to achieve similar results. However, when I get a chance, I will try to recreate the problem on my machine. I never saw this problem with DOE-4 test data, which is what you are running in the script below. In fact, the day/time you were running, provided very nice results for me. I saw this problem with checkout data from GOES-16 and in some AHI sample files from Ray.

I will get back to you on a day/time combo fro G16.

User avatar
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: how to indentify infinite values in array

Post by joleenf »

Hi Bob,

I apologize, I could not get back far enough in my history to find the GOES16 data that was giving me problems. However, I think you have solved this issue for me and there are a few things to note in summary:

1.) If I am controlling a function, such as NDVI, I should mask the denominator before dividing (makes sense, should have done that first).

2.) If I don't have full control over the function, I can still use the formula which is creating infinite values, and if I want to mask the infinite values to missing, I can divide the result by the abs_data(result) to create a mask of missing and 1.


**abs_data should be used so that it does no conflict with Jython built-in.

3.) Be careful when using rescale. As noted in the documentation:

f - the FieldImpl or FlatField
inlo - the input low-range value
inhi - the input high-range value
outlo - the output low-range value
outhi - the output high range value Values of the original field will be linearly scaled from "inlo:inhi" to "outlo:outhi" Values < inlo will be set to outlo; values > inhi set to outhi If input FieldImpl is a sequence, then all items in sequence are done

This means that -infinity is set to outlo, and infinity is set to outhi.

Also in rescale, outlo must be less than outhi. Otherwise, all values are set to zero...


Code: Select all

import java.lang.Float


a=field([infinity, neg_infinity, 1, 0, 2])

strA='\n'.join('Original Field: {}'.format(k) for i,k in enumerate(a.getValues()))

print strA


strb='\n'.join('Rescale Field -1,1 to 0,10: {}'.format(k) for i,k in enumerate(b.getValues()))

print strb


strc='\n'.join('Rescale Field -1,1 to 10,0: {}'.format(k) for i,k in enumerate(c.getValues()))

print strc


strd='\n'.join('Rescale Field 1,-1 to 0,10: {}'.format(k) for i,k in enumerate(d.getValues()))

print 'Reverse inlo, inhi to flip low and hi in output field'
print strd


stre='\n'.join('Rescale Field 1,-1 to 10,0: {}'.format(k) for i,k in enumerate(e.getValues()))

print stre

Post Reply