script to write to a file the location of a threshold

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
carlospsneto
Posts: 68
Joined: Thu Mar 14, 2013 1:38 pm

script to write to a file the location of a threshold

Post by carlospsneto »

I need some guidance to get the location of a threshold through scripting to finish a fire detection code.

For example: I have a field for detection of hotspots that is derived from some temperatures thresholds of 3 different channels. That field is called:
Hotspot.
Hotspot is a mask that only have values where a fire is probable. How can i write a file( txt or csv) with the location (Lat, Lon) of where the fire is detected using scripting?


Thank you
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: script to write to a file the location of a threshold

Post by joleenf »

Hi,

If the hotspot file is already loaded into the field selector, grab the data object using

Code: Select all

hotSpotData = selectData()

Depending on the data format, there may be other options to load directly into the jython shell, without passing through the field selector, but I usually recommend starting in this manner to verify code is working correctly.

Next, use the getDomainSet and getLatLons methods from JPythonMethods (http://www.ssec.wisc.edu/visad-docs/jav ... thods.html), to extract the latlon information:

Depending on whether the data is an image sequence or a single data grid, the data might need indexing. There are probably more acceptable ways of doing this, but this is how I check:

Code: Select all

if (hotSpotData.isFlatField()):
   myData = hotSpotData
   flatFieldDomainSet = myData.getDomainSet()
else:
   myData = hotSpotData[0]
   flatFieldDomainSet = myData.getDomainSet()

latLons = getLatLons(flatFieldDomainSet)
lats=latLons[0]
lons=latLons[1]


Finally, get the indices where the hotSpotData meets the requirement for a certain fire type. For this example, perhaps a fire is indicated by a value of 3.

Code: Select all

indices = find(myData, '==',3)


Using these indices with the retrieved lats and lons array should provide the desired information. Just a note, this is a user to user instruction. Please verify your results, this is another advantage of beginning testing with selectData(), it is much easier to display the selected field and error check with small grid sizes.

Joleen
User avatar
carlospsneto
Posts: 68
Joined: Thu Mar 14, 2013 1:38 pm

Re: script to write to a file the location of a threshold

Post by carlospsneto »

Hello Joleen,
Thank for take the time to help me.
I'm sorry for the noob question, I'm new at programming especially with arrays. But what do you mean by "Using these indices with the retrieved lats and lons array"?
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: script to write to a file the location of a threshold

Post by joleenf »

Hi,

First, I should have asked about the data format whether or not selectData() is being used to read the data. The code above will work for McIDAS AREA format data or for netCDF/hdf grids. If you have point or text data, the technique to obtain lat/lons and unique values is different.

The indices are number locations within an array of values. For example, an array named myArray has the following values:

myArray=[0,1,8,2,8,5]

In python, the first index is 0. This array has a length of 6. The value 8 is found in myArray at indices 2 and 4. Or

myArray[0] = 0
myArray[1] = 1
myArray[2] = 8
myArray[3] = 2
myArray[4] = 8
myArray[5] = 5

If you are interested in fire locations, are you aware of the following satellite derived fire website:

http://wfabba.ssec.wisc.edu/

In addition to globally derived hotspots, this website also links to a number of fire mapping web pages.

Best wishes,
Joleen
Post Reply