Take this example of a compound statement, which computes a convective / total precipitation ratio, then creates a boolean grid which is based on total precipitation from 0 to 0.02", and then creates a grid with ProbPrecip values if there is precipitation (precipMask) and the ratio (precipRatio) is less than 10%:
precipRatio = cp_SFC
/ (tp_SFC + 0.0001)
precipMask = logical_and(greater(tp_SFC,
0.0), less(tp_SFC, 0.02*25.4))
grid = where(logical_and(precipMask,
less(precipRatio, 0.1)), ProbPrecip, 0.0)
This same code fragment may be written in the following way. The precipRatio is the calculated cp/tp ratio; precipPositive is a boolean grid where tp > 0; precipLess2 is a boolean grid where tp < 0.02" (which includes zero); precipBetweenZeroAnd2 is a boolean grid where tp > 0 and tp < 0.02"; precipRatioLess10 is a boolean grid where the precipRatio is less than 10%, precipRatioAndLowPrecip is a boolean grid where tp > 0 and less than 0.02", and where the cp/tp ratio is less than 0.1:
precipRatio = cp_SFC
/ (tp_SFC + 0.0001)
precipPositive = greater(tp_SFC,
0.0)
precipLess2 = less(tp_SFC,
0.02*25.4)
precipBetweenZeroAnd2
= logical_and(precipPositive, precipLess2)
precipRatioLess10 =
less(precipRatio, 0.1)
precipRatioAndLowPrecip
= logical_and(precipRatioLess10, precipBetweenZeroAnd2)
grid = where(precipRatioAndLowPrecip,
ProbPrecip, 0.0)
The second fragment, though longer, is composed of simpler statements and is easier to follow and read. Note also, that we have named the variables to reflect the concepts and improve readability.
Here are some other example "print" statements:
print "myVariable =", myVariable
# To print
Python Numeric array information:
print
"Dimensions of array T:", T.shape, "Value of T at point
20, 20: ", T[20][20]