use of if checks in formulas

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
kbedka1
Posts: 428
Joined: Wed Jan 28, 2009 7:27 pm

use of if checks in formulas

Post by kbedka1 »

I want to create/plot a product that would bring in 3 2-D data fields and, and when certain conditions are met in these fields, I want to create a new data field that would have a value of 1 for these pixels. All other pixels that don't meet my conditions would have a 0.

Example

if (a > 400 and b > 25 and c < 230) then
d=1
else
d=0
end

a, b, and c would be 3 2-D data fields that Mc-V should ask me to choose and d would be my output 2-D data field. How would one do this via a Mc-V formula?
User avatar
Rick
Posts: 404
Joined: Fri Jan 16, 2009 8:20 pm

Re: use of if checks in formulas

Post by Rick »

Hi Kris,

You'll have to write a Jython function for this type of logic. There are a lot of library routines for grids that will serve as a starting point. You can search the manual for formulas and then jython.

Rick
User avatar
kbedka1
Posts: 428
Joined: Wed Jan 28, 2009 7:27 pm

Re: use of if checks in formulas

Post by kbedka1 »

I've looked at the User's Guide section you suggested, I wouldn't exactly consider this a good starting point for new formula writers. What I've suggested in my initial post is something that many algorithm developers/researchers will want to do. I poked around a little bit and figured out the syntax for an if statement, but I don't know how to loop through all the points in an image nor do I know how to export the binary 0/1 "d" variable for display. If there are only 2 fields in the if check, one could do a scatterplot and draw boxes around the regions that meet their criteria, but I and others may want to use 3 or more fields. A working template would be very helpful to get myself and the community started on formula writing.
User avatar
Rick
Posts: 404
Joined: Fri Jan 16, 2009 8:20 pm

Re: use of if checks in formulas

Post by Rick »

Hi Kris,

That's a great idea to create a template to get the programmers started (I'll write an inquiry request). In the meantime, I'm going to suggest looking at some of the image filters as example for looping through a dataset.

From the main McIDAS-V window:

Tools->Formulas->Jython Library->System->Image Filter Routines

Take a look at the replace function, it is an example of if/then and looping.

Let me know if that helps.

Rick
Post Reply