Omaha #4719: Optimize use of numpy.where in GFE viz code.

Change-Id: I032e4e45e48dfc8dc191b83bcfc38583d5057aaa

Former-commit-id: 85ef6c2a7daaa2a186a58a0b5d8080a490792d35
This commit is contained in:
David Gillingham 2015-08-13 14:37:06 -05:00
parent efa3058a3c
commit 8724737db3
41 changed files with 308 additions and 331 deletions

View file

@ -29,7 +29,7 @@ class MyNAM12Forecaster(NAM12Forecaster):
def calcSnowAmt(self, T, QPF):
m2 = less_equal(T, 32)
snowamt = where(m2, 10.0 * QPF, 0)
snowamt = where(m2, 10.0 * QPF, float32(0))
return snowamt
def calcRH(self, rh_FHAG2):

View file

@ -78,7 +78,7 @@ class NAM12Forecaster(Forecaster):
exp(val), p)
# interpolate the temperature at true elevation
tval1 = self.linear(gh_c[i], gh_c[i-1], t_c[i], t_c[i-1], topo)
tmb = where(logical_and(equal(tmb, -1), greater(gh_c[i], topo)),
tmb = where(logical_and(equal(tmb, -1), higher),
tval1, tmb)
# interpolate the temperature at model elevation
tval2 = self.linear(gh_c[i], gh_c[i-1], t_c[i], t_c[i-1], stopo)
@ -176,20 +176,19 @@ class NAM12Forecaster(Forecaster):
## of QPF < 0.2 raise the PoP if it's very humid.
##--------------------------------------------------------------------------
def calcPoP(self, gh_c, rh_c, QPF, topo):
rhavg = where(less(gh_c, topo), -1, rh_c)
rhavg = where(greater(gh_c, topo + (5000 * 12 * 2.54) / 100),
-1, rhavg)
count = where(not_equal(rhavg, -1), 1, 0)
rhavg = where(equal(rhavg, -1), 0, rhavg)
count = add.reduce(count, 0)
rhavg = where(less(gh_c, topo), float32(-1), rh_c)
rhavg[greater(gh_c, topo + (5000 * 0.3048))] = -1
count = not_equal(rhavg, -1)
rhavg[equal(rhavg, -1)] = 0
count = add.reduce(count, 0, dtype=float32)
rhavg = add.reduce(rhavg, 0)
## add this much based on humidity only
dpop = where(count, rhavg / (count + .001), 0) - 70.0
dpop = where(less(dpop, -30), -30, dpop)
dpop[less(dpop, -30)] = -30
## calculate the base PoP
pop = where(less(QPF, 0.02), QPF * 1000, QPF * 350 + 13)
pop = pop + dpop # add the adjustment based on humidity
pop = clip(pop, 0, 100) # clip to 100%
pop += dpop # add the adjustment based on humidity
pop.clip(0, 100, pop) # clip to 100%
return pop
##--------------------------------------------------------------------------
@ -283,16 +282,18 @@ class NAM12Forecaster(Forecaster):
m1 = less(T, 9)
m2 = greater_equal(T, 30)
snowr = T * -0.5 + 22.5
snowr = where(m1, 20, snowr)
snowr = where(m2, 0, snowr)
snowr[m1] = 20
snowr[m2] = 0
# calc. snow amount based on the QPF and the ratio
snowamt = where(less_equal(FzLevel - 1000, topo * 3.28),
snowr * QPF, 0)
snowamt = self.empty()
fzLevelMask = less_equal(FzLevel - 1000, topo / 0.3048)
snowamt[fzLevelMask] = snowr[fzLevelMask] * QPF[fzLevelMask]
# Only make snow at points where the weather is snow
snowmask = logical_or(equal(Wx[0], 1), equal(Wx[0], 3))
snowmask = logical_or(snowmask, logical_or(equal(Wx[0], 7),
equal(Wx[0], 9)))
snowamt = where(snowmask, snowamt, 0)
snowamt[logical_not(snowmask)] = 0
return snowamt
##--------------------------------------------------------------------------
@ -315,7 +316,7 @@ class NAM12Forecaster(Forecaster):
tmp = self.ptemp(t_c[i], p) # calculate the pot. temp
pt = pt + [tmp] # add to the list
pt = array(pt)
pt = where(mask, pt, 0)
pt[mask] = 0
avg = add.accumulate(pt, 0)
count = add.accumulate(mask, 0)
mh = self._minus
@ -353,18 +354,18 @@ class NAM12Forecaster(Forecaster):
# find the points that are above the 3000 foot level
mask = greater_equal(gh_c, fatopo)
# initialize the grids into which the value are stored
famag = self._minus
fadir = self._minus
famag = self.newGrid(-1)
fadir = self.newGrid(-1)
# start at the bottom and store the first point we find that's
# above the topo + 3000 feet level.
for i in xrange(wind_c[0].shape[0]):
# Interpolate (maybe)
famag = where(equal(famag, -1),
where(mask[i], wm[i], famag), famag)
fadir = where(equal(fadir, -1),
where(mask[i], wd[i], fadir), fadir)
fadir = clip(fadir, 0, 359.5) # clip the value to 0, 360
famag = famag * 1.94 # convert to knots
magMask = logical_and(equal(famag, -1), mask[i])
dirMask = logical_and(equal(fadir, -1), mask[i])
famag[magMask] = wm[i][magMask]
fadir[dirMask] = wd[i][dirMask]
fadir.clip(0, 359.5, fadir) # clip the value to 0, 360
famag *= 1.94 # convert to knots
return (famag, fadir) # return the tuple of grids
##--------------------------------------------------------------------------
@ -380,18 +381,18 @@ class NAM12Forecaster(Forecaster):
mask = logical_and(greater_equal(gh_c, topo),
less_equal(gh_c, nmh + topo))
# set the points outside the layer to zero
u = where(mask, u, 0)
v = where(mask, v, 0)
u[logical_not(mask)] = 0
v[logical_not(mask)] = 0
mask = add.reduce(mask) # add up the number of set points vert.
mmask = mask + 0.00001
# calculate the average value in the mixed layerlayer
u = where(mask, add.reduce(u) / mmask, 0)
v = where(mask, add.reduce(v) / mmask, 0)
u = where(mask, add.reduce(u) / mmask, float32(0))
v = where(mask, add.reduce(v) / mmask, float32(0))
# convert u, v to mag, dir
tmag, tdir = self._getMD(u, v)
tdir = clip(tdir, 0, 359.5)
tmag = tmag * 1.94 # convert to knots
tmag = clip(tmag, 0, 125) # clip speed to 125 knots
tdir.clip(0, 359.5, tdir)
tmag *= 1.94 # convert to knots
tmag.clip(0, 125, tmag) # clip speed to 125 knots
return (tmag, tdir)
@ -433,7 +434,7 @@ class NAM12Forecaster(Forecaster):
a3 = where(logical_and(equal(aindex, 2), topomask),
a3 + a11, a3)
topomask = logical_and(topomask, cross)
aindex = where(topomask, aindex + 1, aindex)
aindex[topomask] += 1
a1 = where(logical_and(equal(aindex, 0), topomask),
a1 + a22, a1)
a2 = where(logical_and(equal(aindex, 1), topomask),
@ -452,51 +453,48 @@ class NAM12Forecaster(Forecaster):
"Chc:ZR:-:<NoVis>:", 'Chc:IP:-:<NoVis>:',
'Chc:ZR:-:<NoVis>:^Chc:IP:-:<NoVis>:']
wx = self._empty
wx = self.empty(int8)
# Case d (snow)
snowmask = equal(aindex, 0)
wx = where(logical_and(snowmask, greater(a1, 0)), 2, wx)
wx = where(logical_and(snowmask, less_equal(a1, 0)), 1, wx)
wx[logical_and(snowmask, greater(a1, 0))] = 2
wx[logical_and(snowmask, less_equal(a1, 0))] = 1
# Case c (rain / snow / rainSnowMix)
srmask = equal(aindex, 1)
wx = where(logical_and(srmask, less(a1, 5.6)), 1, wx)
wx = where(logical_and(srmask, greater(a1, 13.2)), 2, wx)
wx = where(logical_and(srmask,
logical_and(greater_equal(a1, 5.6),
less(a1, 13.2))), 3, wx)
wx[logical_and(srmask, less(a1, 5.6))] = 1
wx[logical_and(srmask, greater(a1, 13.2))] = 2
wx[logical_and(srmask,
logical_and(greater_equal(a1, 5.6),
less(a1, 13.2)))] = 3
# Case a (Freezing Rain / Ice Pellets)
ipmask = equal(aindex, 2)
ipm = greater(a1, a2 * 0.66 + 66)
wx = where(logical_and(ipmask, ipm), 5, wx)
wx[logical_and(ipmask, ipm)] = 5
zrm = less(a1, a2 * 0.66 + 46)
wx = where(logical_and(ipmask, zrm), 4, wx)
wx[logical_and(ipmask, zrm)] = 4
zrm = logical_not(zrm)
ipm = logical_not(ipm)
wx = where(logical_and(ipmask, logical_and(zrm, ipm)), 6, wx)
wx[logical_and(ipmask, logical_and(zrm, ipm))] = 6
# Case b (Ice pellets / rain)
cmask = greater_equal(aindex, 3)
ipmask = logical_and(less(a3, 2), cmask)
wx = where(logical_and(ipmask, less(a1, 5.6)), 1, wx)
wx = where(logical_and(ipmask, greater(a1, 13.2)), 2, wx)
wx = where(logical_and(ipmask, logical_and(greater_equal(a1, 5.6),
less_equal(a1, 13.2))),
3, wx)
wx[logical_and(ipmask, less(a1, 5.6))] = 1
wx[logical_and(ipmask, greater(a1, 13.2))] = 2
wx[logical_and(ipmask, logical_and(greater_equal(a1, 5.6),
less_equal(a1, 13.2)))] = 3
ipmask = logical_and(greater_equal(a3, 2), cmask)
wx = where(logical_and(ipmask, greater(a1, 66 + 0.66 * a2)), 5, wx)
wx = where(logical_and(ipmask, less(a1, 46 + 0.66 * a2)), 4, wx)
wx = where(logical_and(ipmask,
logical_and(greater_equal(a1, 46 + 0.66 * a2),
less_equal(a1, 66 + 0.66 * a2))),
6, wx)
wx[logical_and(ipmask, greater(a1, 66 + 0.66 * a2))] = 5
wx[logical_and(ipmask, less(a1, 46 + 0.66 * a2))] = 4
wx[logical_and(ipmask, logical_and(greater_equal(a1, 46 + 0.66 * a2),
less_equal(a1, 66 + 0.66 * a2)))] = 6
# Make showers (scattered/Chc)
convecMask = greater(cp_SFC / (tp_SFC + .001), 0.5)
wx = where(logical_and(not_equal(wx, 0), convecMask), wx + 6, wx)
wx[logical_and(not_equal(wx, 0), convecMask)] += 6
# Thunder
for i in xrange(len(key)):
@ -505,10 +503,10 @@ class NAM12Forecaster(Forecaster):
tcov = "Sct"
key.append(key[i] + "^" + tcov
+ ":T:<NoInten>:<NoVis>:")
wx = where(less_equal(bli_BL0180, -3), wx + 13, wx)
wx[less_equal(bli_BL0180, -3)] += 13
# No wx where no qpf
wx = where(less(QPF, 0.01), 0, wx)
wx[less(QPF, 0.01)] = 0
return(wx, key)
##--------------------------------------------------------------------------
@ -523,7 +521,7 @@ class NAM12Forecaster(Forecaster):
m4 = logical_and(greater(QPF, 0.1), less(QPF, 0.3))
# assign 0 to the dry grid point, 100 to the wet grid points,
# and a ramping function to all point in between
cwr = where(m1, 0, where(m2, 100,
cwr = where(m1, float32(0), where(m2, float32(100),
where(m3, 444.4 * (QPF - 0.01) + 10,
where(m4, 250 * (QPF - 0.1) + 50,
QPF))))
@ -534,21 +532,18 @@ class NAM12Forecaster(Forecaster):
## and 3-D relative humidity.
##--------------------------------------------------------------------------
def calcLAL(self, bli_BL0180, tp_SFC, cp_SFC, rh_c, rh_FHAG2):
lal = self._empty + 1
lal = ones_like(self._empty)
# Add one to lal if we have 0.5 mm of precip.
lal = where(logical_and(logical_and(greater(tp_SFC, 0),
greater(cp_SFC, 0)),
greater(tp_SFC / cp_SFC, 0.5)), lal + 1, lal)
lal[logical_and(greater(cp_SFC, 0), greater(tp_SFC / cp_SFC, 0.5))] += 1
# make an average rh field
midrh = add.reduce(rh_c[6:9], 0) / 3
# Add one to lal if mid-level rh high and low level rh low
lal = where(logical_and(greater(midrh, 70), less(rh_FHAG2, 30)),
lal + 1, lal)
lal[logical_and(greater(midrh, 70), less(rh_FHAG2, 30))] += 1
# Add on to lal if lifted index is <-3 and another if <-5
lal = where(less(bli_BL0180, -3), lal + 1, lal)
lal = where(less(bli_BL0180, -5), lal + 1, lal)
lal[less(bli_BL0180, -3)] += 1
lal[less(bli_BL0180, -5)] += 1
return lal

View file

@ -35,8 +35,8 @@ class GWWForecaster(Forecaster):
return clip(grid, 0, 100)
def calcWind(self, wind_SFC):
mag = where(greater(wind_SFC[0], 50), 0, wind_SFC[0]*1.94)
dir = where(greater(wind_SFC[0], 50), 0, wind_SFC[1])
mag = where(greater(wind_SFC[0], 50), float32(0), wind_SFC[0]*1.94)
dir = where(greater(wind_SFC[0], 50), float32(0), wind_SFC[1])
dir = clip(dir, 0, 359.5)
return (mag, dir)

View file

@ -177,7 +177,7 @@ class ISmartScript(SmartScript.SmartScript):
editMask = logical_and(equal(byteGrid, oldIndex), mask)
# poke in the new values
byteGrid = where(editMask, newIndex, byteGrid)
byteGrid[editMask] = newIndex
self.createGrid("Fcst", weName, "DISCRETE", (byteGrid, hazKey),
tr, discreteOverlap=1, discreteAuxDataLength=4)

View file

@ -530,7 +530,7 @@ class ITool (ISmartScript.ISmartScript):
for gridEntry in createGrids:
if len(gridEntry) == 7:
model, elementName, elementType, startHour, endHour, value, editAreas = gridEntry
defValue = None
defValue = 0
elif len(gridEntry) == 8:
model, elementName, elementType, startHour, endHour, value, editAreas, defValue = gridEntry
else:
@ -548,11 +548,10 @@ class ITool (ISmartScript.ISmartScript):
if createdGrids.has_key(key):
grid = createdGrids[key]
else:
grid = numpy.zeros_like(self._empty)
if defValue is not None:
grid = numpy.where(grid == 0, defValue, defValue)
grid = self.newGrid(defValue)
if editAreas == "all":
mask = self._empty + 1
mask = self.newGrid(True, bool)
else:
mask = self._makeMask(editAreas)
#self.output("mask "+`size(mask)`, self._outFile)
@ -562,7 +561,7 @@ class ITool (ISmartScript.ISmartScript):
#self._addHazard(elementName, timeRange, value, mask)
value = self.getIndex(value, hazKeys)
#self.output("setting value "+value+" "+hazKeys, self._outFile)
grid = numpy.where(mask, value, grid)
grid[mask] = value
grid = grid.astype('int8')
elementType = self.getDataType(elementName)
self.createGrid(model, elementName, elementType, (grid, hazKeys), timeRange)
@ -571,17 +570,18 @@ class ITool (ISmartScript.ISmartScript):
value = "<NoCov>:<NoWx>:<NoInten>:<NoVis>:"
value = self.getIndex(value, wxKeys)
#self.output("setting value "+value+" "+wxKeys, self._outFile)
grid = numpy.where(mask, value, grid)
grid[mask] = value
grid = grid.astype('int8')
elementType = self.getDataType(elementName)
self.createGrid(model, elementName, elementType, (grid, wxKeys), timeRange)
elif elementType == "VECTOR":
grid = numpy.where(mask, value[0], grid)
grid[mask] = value[0]
dirGrid = numpy.zeros_like(self._empty)
dirGrid = numpy.where(mask, self.textToDir(value[1]), dirGrid)
dirGrid[mask] = self.textToDir(value[1])
elementType = self.getDataType(elementName)
self.createGrid(model, elementName, elementType, (grid, dirGrid), timeRange)
else:
grid = numpy.where(mask, value, grid)
grid[mask] = value
elementType = self.getDataType(elementName)
self.createGrid(model, elementName, elementType, grid, timeRange)
# Save the grid in the createdGridDict

View file

@ -5751,7 +5751,7 @@ class Procedure (SmartScript.SmartScript):
histoData=add.reduce(d1,-1)
self.VU.logMsg("done with histoData reduce")
#hitCount=add.reduce(where(d1,verif,0),-1)
a=where(d1,verif,0)
a=where(d1,verif,float32(0))
hitCount=add.reduce(a,-1)
self.VU.logMsg("done with hitCount reduce")
histoData[-2]+=histoData[-1]

View file

@ -302,7 +302,7 @@ class Procedure (SmartScript.SmartScript):
# in the training period...start cutting back correction amount
# until getting back to zero regressed amount at (2*fuzz)% beyond.
#
multiplier=self._empty+1.0
multiplier=self.newGrid(1)
fuzzGrid=maximum((maxFcst-minFcst)*fuzz,0.01) # dont have zero
max1=maxFcst+fuzzGrid
multiplier=where(greater(inputGrid,max1),1.0-((inputGrid-max1)/fuzzGrid),multiplier)
@ -315,8 +315,8 @@ class Procedure (SmartScript.SmartScript):
del maxFcst
del fuzzGrid
if self.VU.getDebug>=1:
count=add.reduce(add.reduce(less(multiplier,0.98)))
count2=add.reduce(add.reduce(less(multiplier,0.02)))
count=count_nonzero(less(multiplier,0.98))
count2=count_nonzero(less(multiplier,0.02))
if count>0:
self.VU.logMsg(" %d fcst points are outliers and regression was reduced"%count,1)
if count2>0:
@ -359,8 +359,8 @@ class Procedure (SmartScript.SmartScript):
if maxtgrid is not None:
maxoftgrid=self.getGrids(mutableModel,"T","SFC",newtr,mode="Max",noDataError=0,cache=0)
if maxoftgrid is not None:
maxt=where(greater(maxoftgrid,maxtgrid),maxoftgrid,maxtgrid)
changed=add.reduce(add.reduce(greater(maxt,maxtgrid)))
maxt=maximum(maxoftgrid,maxtgrid)
changed=count_nonzero(greater(maxt,maxtgrid))
if changed>0:
fhr=int((newtr.startTime().unixTime()-modeltime)/3600.0)
self.VU.logMsg("Had to update MaxT at %d-hrs to match hourly T grids at %d points"%(fhr,changed))
@ -377,8 +377,8 @@ class Procedure (SmartScript.SmartScript):
if mintgrid is not None:
minoftgrid=self.getGrids(mutableModel,"T","SFC",newtr,mode="Min",noDataError=0,cache=0)
if minoftgrid is not None:
mint=where(less(minoftgrid,mintgrid),minoftgrid,mintgrid)
changed=add.reduce(add.reduce(less(mint,mintgrid)))
mint=minimum(minoftgrid,mintgrid)
changed=count_nonzero(less(mint,mintgrid))
if changed>0:
fhr=int((newtr.startTime().unixTime()-modeltime)/3600.0)
self.VU.logMsg("Had to update MinT at %d-hrs to match hourly T grids at %d points"%(fhr,changed))
@ -395,8 +395,8 @@ class Procedure (SmartScript.SmartScript):
if maxrhgrid is not None:
maxofrhgrid=self.getGrids(mutableModel,"RH","SFC",newtr,mode="Max",noDataError=0,cache=0)
if maxofrhgrid is not None:
maxrh=where(greater(maxofrhgrid,maxrhgrid),maxofrhgrid,maxrhgrid)
changed=add.reduce(add.reduce(greater(maxrh,maxrhgrid)))
maxrh=maximum(maxofrhgrid,maxrhgrid)
changed=count_nonzero(greater(maxrh,maxrhgrid))
if changed>0:
fhr=int((newtr.startTime().unixTime()-modeltime)/3600.0)
self.VU.logMsg("Had to update MaxRH at %d-hrs to match hourly RH grids at %d points"%(fhr,changed))
@ -413,8 +413,8 @@ class Procedure (SmartScript.SmartScript):
if minrhgrid is not None:
minofrhgrid=self.getGrids(mutableModel,"RH","SFC",newtr,mode="Min",noDataError=0,cache=0)
if minofrhgrid is not None:
minrh=where(less(minofrhgrid,minrhgrid),minofrhgrid,minrhgrid)
changed=add.reduce(add.reduce(less(minrh,minrhgrid)))
minrh=minimum(minofrhgrid,minrhgrid)
changed=count_nonzero(less(minrh,minrhgrid))
if changed>0:
fhr=int((newtr.startTime().unixTime()-modeltime)/3600.0)
self.VU.logMsg("Had to update MinRH at %d-hrs to match hourly RH grids at %d points"%(fhr,changed))

View file

@ -453,7 +453,7 @@ class Procedure (SmartScript.SmartScript):
#
# Calculate the variance in that grid
#
obsgrid=where(self.eaMask,ravel(ogrid),0)
obsgrid=where(self.eaMask,ravel(ogrid),float32(0))
obsgrid2=obsgrid*obsgrid
std=sqrt(float(add.reduce(obsgrid2))/self.numpoints-((float(add.reduce(obsgrid))/self.numpoints)**2))
stds[key]=std
@ -471,7 +471,7 @@ class Procedure (SmartScript.SmartScript):
records=obsCases[prevkey]
pgrid=self.VU.getVerGrids(self.obsModel,pbasetime,parm,pstime,petime,recList=records)
if pgrid is not None:
prevgrid=where(self.eaMask,ravel(pgrid),0)
prevgrid=where(self.eaMask,ravel(pgrid),float32(0))
chggrid=obsgrid-prevgrid
chgs[key]=add.reduce(chggrid)/self.numpoints
abschgs[key]=add.reduce(abs(chggrid))/self.numpoints
@ -483,7 +483,7 @@ class Procedure (SmartScript.SmartScript):
anomstr=" "
cgrid=self.getClimoGrid(parm,pyea,pmon,pday)
if cgrid is not None:
climgrid=where(self.eaMask,ravel(cgrid),0)
climgrid=where(self.eaMask,ravel(cgrid),float32(0))
anomgrid=obsgrid-climgrid
anom[key]=add.reduce(anomgrid)/self.numpoints
absanom[key]=add.reduce(abs(anomgrid))/self.numpoints

View file

@ -71,7 +71,7 @@ class Procedure (SmartScript.SmartScript):
# convert to feet
topoGridC = topoGrid * 3.281
topoGridC[less(topoGridC,0.0)] = 0.0
#topoGrid = where(greater(topoGrid,200.0),200.0,topoGrid)
#topoGrid[greater(topoGrid,200.0)] = 200.0
return topoGridC
@ -91,7 +91,7 @@ class Procedure (SmartScript.SmartScript):
# convert to feet
topoGridC = topoGrid * 3.281
topoGridC[less(topoGridC,-50.0)] = 0.0
#topoGrid = where(greater(topoGrid,200.0),200.0,topoGrid)
#topoGrid[greater(topoGrid,200.0)] = 200.0
return topoGridC
@ -111,7 +111,7 @@ class Procedure (SmartScript.SmartScript):
# convert to feet
topoGridC = topoGrid * 3.281
topoGridC[less(topoGridC,-50.0)] = 0.0
#topoGrid = where(greater(topoGrid,200.0),200.0,topoGrid)
#topoGrid[greater(topoGrid,200.0)] = 200.0
return topoGridC
@ -132,7 +132,7 @@ class Procedure (SmartScript.SmartScript):
# convert to feet
topoGridC = topoGrid * 3.281
topoGridC[less(topoGridC,-50.0)] = 0.0
#topoGrid = where(greater(topoGrid,200.0),200.0,topoGrid)
#topoGrid[greater(topoGrid,200.0)] = 200.0
return topoGridC
@ -152,7 +152,7 @@ class Procedure (SmartScript.SmartScript):
# convert to feet
topoGridC = topoGrid * 3.281
topoGridC[less(topoGridC,-50.0)] = 0.0
#topoGrid = where(greater(topoGrid,200.0),200.0,topoGrid)
#topoGrid[greater(topoGrid,200.0)] = 200.0
return topoGridC
@ -172,7 +172,7 @@ class Procedure (SmartScript.SmartScript):
# convert to feet
topoGridC = topoGrid * 3.281
topoGridC[less(topoGridC,-50.0)] = 0.0
#topoGrid = where(greater(topoGrid,200.0),200.0,topoGrid)
#topoGrid[greater(topoGrid,200.0)] = 200.0
return topoGridC

View file

@ -901,13 +901,13 @@ class Procedure (SmartScript.SmartScript):
ringMask = logical_and(less(mag, upper), greater(mag, lower))
avgGrid = where(ringMask, backMag, 0.0)
avgGrid = where(ringMask, backMag, float32(0.0))
# a nearly calm grid means no blending required
if lower < 1.0:
return windGrid
wtGrid = where(greater(mag, upper), 1.0, 0.0)
wtGrid = greater(mag, upper).astype(float32)
ringMask = logical_and(less(mag, upper), greater(mag, lower))
wtGrid = where(ringMask, (mag - lower) / (upper - lower), wtGrid)
wtGrid[less(mag, lower)]= 0.0
@ -1107,12 +1107,12 @@ class Procedure (SmartScript.SmartScript):
else: # outside RMW
grid = where(mask, inSpeed * power((inRadius / distanceGrid), exponent),
grid)
grid = clip(grid, 0.0, 200.0)
grid.clip(0.0, 200.0, grid)
dirGrid = self.makeDirectionGrid(latGrid, lonGrid, center[0], center[1])
# clip values between zero and maxWind
grid = clip(grid, 0.0, maxWind)
grid.clip(0.0, maxWind, grid)
# apply the wind reduction over land
fraction = 1.0 - (self.lessOverLand / 100.0)
grid = self.decreaseWindOverLand(grid, fraction, self.elevation)

View file

@ -504,7 +504,7 @@ class Procedure (SmartScript.SmartScript):
# the values of consistMask where self.cwaMask is one and
# I want the "good result", which is zero, where
# self.cwaMask is zero.
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
# The ravel and sometrue methods are from Numeric.
if sometrue(ravel(consistMask)):
# The ravel method reduces the rank of the array by one.
@ -609,7 +609,7 @@ class Procedure (SmartScript.SmartScript):
# up the memory they use.
del (sMask, swMask, ipMask)
# The where method is from Numeric
wxMask = where(snowMask, 0, 1)
wxMask = logical_not(snowMask)
# "Truth" table for the logical comparison follows
# SnowAmt6hr >= 0.1, 1; SnowAmt6hr < 0.1, 0
# Wx has S, SW, or IP, 0; Wx doesn't have S, SW, or IP, 1
@ -621,7 +621,7 @@ class Procedure (SmartScript.SmartScript):
# The logical_and, where, sometrue, and ravel methods are all
# from Numeric.
consistMask = logical_and(nonZeroMask, wxMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
# Update inconsistGrid to be the current state of the
# inconsistencies.
inconsistGrid = logical_and(inconsistGrid, consistMask)
@ -724,7 +724,7 @@ class Procedure (SmartScript.SmartScript):
# The logical_and, where, sometrue, and ravel methods are all
# from Numeric.
consistMask = logical_and(qpfNonZeroMask, popZeroMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
if sometrue(ravel(consistMask)):
# The good result is if the logical_and returns zeros
# for every grid point, that is "none true". So, if
@ -832,7 +832,7 @@ class Procedure (SmartScript.SmartScript):
del (rMask, rwMask, lMask, zlMask, zrMask)
precipMask = logical_or(snowMask, rainMask)
del (snowMask, rainMask)
wxMask = where(precipMask, 0, 1)
wxMask = logical_not(snowMask)
# QPF6hr >= 0.01, 1; QPF6hr < 0.01, 0
# Wx has precip, 0; Wx doesn't have precip, 1
# QPF6hr >= 0.01 (1) and Wx has (0) = 0 (Good result)
@ -843,7 +843,7 @@ class Procedure (SmartScript.SmartScript):
# The logical_and, where, sometrue, and ravel methods are all
# from Numeric.
consistMask = logical_and(qpfNonZeroMask, wxMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
# Update the inconsistGrid to the current state of the
# inconsistencies.
inconsistGrid = logical_and(inconsistGrid, consistMask)
@ -1000,7 +1000,7 @@ class Procedure (SmartScript.SmartScript):
# The logical_and, where, sometrue, and ravel methods are all
# from Numeric.
consistMask = logical_and(pop50Mask, qpfMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
# Update the inconsistentGrid with the state of the
# inconsistencies.
inconsistGrid = logical_and(inconsistGrid, consistMask)

View file

@ -51,10 +51,7 @@ class Procedure (SmartScript.SmartScript):
if len(gridList) < 1:
return None
gridMax = zeros(gridList[0].shape) - 100000.0 # a large negative number
for grid in gridList:
gridMax = where(grid > gridMax, grid, gridMax)
gridMax = maximum.reduce(gridList)
return gridMax
def intGrid(self, gridList):

View file

@ -378,7 +378,7 @@ The SnowAmt/QPF Check skipped the time range.''' % gridTR
# the values of consistMask where self.cwaMask is one and
# I want the "good result", which is zero, where
# self.cwaMask is zero.
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
# ravel and sometrue are from Numeric.
if not sometrue(ravel(consistMask)):
# This is the good result, even though it may not be
@ -512,7 +512,7 @@ The SnowAmt/Wx Check skipped the time range.''' % gridTR
ipMask = self.wxMask(wxGrid, ':IP:')
snowMask = logical_or(logical_or(sMask, swMask), ipMask)
del (sMask, swMask, ipMask)
wxMask = where(snowMask, 0, 1)
wxMask = logical_not(snowMask)
# "Truth" table for the logical comparison follows
# SnowAmt >= 0.1, 1; SnowAmt < 0.1, 0
# Wx has S, SW, or IP, 0; Wx doesn't have S, SW, or IP, 1
@ -522,7 +522,7 @@ The SnowAmt/Wx Check skipped the time range.''' % gridTR
# SnowAmt < 0.1 (0) and Wx doesn't have (1) = 0 (Good result)
#
consistMask = logical_and(nonZeroMask, wxMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
consistMaskList.append(consistMask)
if not sometrue(ravel(consistMask)):
# There were no inconsistencies with this Wx grid. Since only
@ -585,7 +585,7 @@ The SnowAmt/Wx Check skipped the time range.''' % gridTR
ipMask = self.wxMask(wxGrid, ':IP:')
snowMask = logical_or(logical_or(sMask, swMask), ipMask)
del (sMask, swMask, ipMask)
wxMask = where(snowMask, 0, 1)
wxMask = logical_not(snowMask)
# "Truth" table for the logical comparison follows
# SnowAmt >= 0.1, 1; SnowAmt < 0.1, 0
# Wx has S, SW, or IP, 0; Wx doesn't have S, SW, or IP, 1
@ -596,7 +596,7 @@ The SnowAmt/Wx Check skipped the time range.''' % gridTR
#
# All Wx grids overlapping the SnowAmt grid must be consistent.
consistMask = logical_and(nonZeroMask, wxMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
if sometrue(ravel(consistMask)):
# I'll highlight the SnowAmt grids and Wx grids in
# gridTR as I did with QPF. However, I'll make
@ -706,7 +706,7 @@ The QPF/PoP Check skipped the time range.''' % gridTR
# PoP != 0 (0) and QPF > 0 (1) => 0 (Good result)
# PoP = 0 (1) and QPF > 0 (1) => 1 (Bad result)
consistMask = logical_and(qpfNonZeroMask, popZeroMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
if sometrue(ravel(consistMask)):
# The good result is if the logical_and returns zeros
# for every grid point, that is "none true". So, if
@ -741,7 +741,7 @@ The QPF/PoP Check skipped the time range.''' % gridTR
# PoP <= 50 (0) and QPF = 0 (1) => 0 (Good result)
consistMask2 = logical_and(qpfZeroMask, popGreater50Mask)
consistMask2 = where(self.cwaMask, consistMask2, 0)
consistMask2[logical_not(self.cwaMask)] = 0
if sometrue(ravel(consistMask2)):
# The good result is if the logical_and returns zeros
# for every grid point, that is "none true". So, if
@ -848,7 +848,7 @@ The QPF/Wx Check skipped the time range.''' % gridTR
del (rMask, rwMask, lMask, zlMask, zrMask)
precipMask = logical_or(snowMask, rainMask)
del (snowMask, rainMask)
wxMask = where(precipMask, 0, 1)
wxMask = logical_not(precipMask)
# QPF >= 0.01, 1; QPF < 0.01, 0
# Wx has precip, 0; Wx doesn't have precip, 1
# QPF >= 0.01 (1) and Wx has (0) = 0 (Good result)
@ -856,7 +856,7 @@ The QPF/Wx Check skipped the time range.''' % gridTR
# QPF < 0.01 (0) and Wx has (0) = 0 (Good result)
# QPF < 0.01 (0) and Wx doesn't have (1) = 0 (Good result)
consistMask = logical_and(qpfNonZeroMask, wxMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
consistMaskList.append(consistMask)
if not sometrue(ravel(consistMask)):
# There were no inconsistencies with this Wx grid. Since only
@ -931,7 +931,7 @@ The QPF/Wx Check skipped the time range.''' % gridTR
del (rMask, rwMask, lMask, zlMask, zrMask)
precipMask = logical_or(snowMask, rainMask)
del (snowMask, rainMask)
wxMask = where(precipMask, 0, 1)
wxMask = logical_not(precipMask)
# QPF >= 0.01, 1; QPF < 0.01, 0
# Wx has precip, 0; Wx doesn't have precip, 1
# QPF >= 0.01 (1) and Wx has (0) = 0 (Good result)
@ -941,7 +941,7 @@ The QPF/Wx Check skipped the time range.''' % gridTR
#
# All Wx grids overlapping the SnowAmt grid must be consistent.
consistMask = logical_and(qpfNonZeroMask, wxMask)
consistMask = where(self.cwaMask, consistMask, 0)
consistMask[logical_not(self.cwaMask)] = 0
if sometrue(ravel(consistMask)):
wxGridTR = wxInfoList[wxIndex].gridTime()
tempGridStartTime = wxGridTR.startTime().unixTime()

View file

@ -491,7 +491,7 @@ class Procedure (SmartScript.SmartScript):
#print "Getting FFG Grid Now: "
ffgGrid = self.getRFCFlashFloodGrid(productList,varDict)
#print "GOT FFG Grid"
ffgGrid = where(less(ffgGrid, 0.0), 0.0, ffgGrid)
ffgGrid[less(ffgGrid, 0.0)] = 0.0
# get the ERP grids and stuff them in six hour time blocks to match
# the cummulative QPF grids will create later
@ -515,9 +515,9 @@ class Procedure (SmartScript.SmartScript):
str(tr), "S")
continue
tempffgGrid = where(equal(ffgGrid, 0.0), 1000.0, ffgGrid)
tempffgGrid = where(equal(ffgGrid, 0.0), float32(1000.0), ffgGrid)
ratioGrid = qpfGrid / tempffgGrid
ratioGrid = where(equal(ffgGrid, 0.0), 0.0, ratioGrid)
ratioGrid[equal(ffgGrid, 0.0)] = 0.0
self.createGrid("Fcst", "ERP", "SCALAR", erpGrid, tr,
minAllowedValue = -1, maxAllowedValue=100,
precision=2)
@ -528,7 +528,7 @@ class Procedure (SmartScript.SmartScript):
ratioGrid, tr, precision=2,
minAllowedValue = 0, maxAllowedValue=1000)
floodThreat = zeros(self.getTopo().shape)
floodThreat = self.empty()
for e in range(len(erps) - 1):
for r in range(len(ratios) - 1):
@ -542,7 +542,7 @@ class Procedure (SmartScript.SmartScript):
less(erpGrid, eMax))
mask = logical_and(ratioMask, erpMask)
keyIndex = self.getIndex(threatMatrix[r][e], threatKeys)
floodThreat = where(mask, keyIndex, floodThreat)
floodThreat[mask] = keyIndex
self.createGrid("Fcst", "FloodThreat", "DISCRETE",
(floodThreat, threatKeys), tr,
@ -551,7 +551,7 @@ class Procedure (SmartScript.SmartScript):
discreteAuxDataLength=2,
defaultColorTable="gHLS_new")
maxFloodThreat = where(floodThreat > maxFloodThreat, floodThreat, maxFloodThreat)
maxFloodThreat = maximum(floodThreat, maxFloodThreat)
# make a 6 hour TimeRange
# startTime = trList[0].startTime()

View file

@ -1547,7 +1547,7 @@ class Procedure (SmartScript.SmartScript):
# clip values between zero and the maximum allowable wind speed
maxWind = self.getMaxAllowableWind(maxWind)
grid = clip(grid, 0.0, maxWind)
grid.clip(0.0, maxWind, grid)
# apply the wind reduction over land
fraction = 1.0 - (self.lessOverLand / 100.0)
grid = self.decreaseWindOverLand(grid, fraction, self.elevation, timeRange)

View file

@ -105,13 +105,7 @@ class Procedure (SmartScript.SmartScript):
mask1 = topoGrid < min
mask2 = topoGrid > max
topoGrid[mask1] = -80
topoGrid[mask2] = self.getTopo()[mask2]
# mask1 = topoVal< min
# mask2 = topoVal> max
# topoGrid = np.where(mask1,-80.0,topoVal)
# topoGrid = np.where(mask2,self.getTopo(),topoVal)
topoGrid[mask2] = self.getTopo()[mask2]
return topoGrid
def makeNewTimeRange(self, hours):
@ -171,7 +165,7 @@ class Procedure (SmartScript.SmartScript):
surgeVal = grid.copy()
mask = surgeVal > -100
grid = np.where(mask,surgeVal*3.28, -80.0)
grid = np.where(mask,surgeVal*3.28, np.float32(-80.0))
return grid # convert meters to feet
@ -211,7 +205,7 @@ class Procedure (SmartScript.SmartScript):
if smoothThreatGrid is "Yes":
phishGrid = np.where(np.greater(phishGrid, 0.0), self.smoothGrid(phishGrid,3), phishGrid)
grid = np.where(phishGrid>-100,phishGrid*3.28, -80.0)
grid = np.where(phishGrid>-100,phishGrid*3.28, np.float32(-80.0))
self.createGrid("Fcst", "InundationTiming", "SCALAR", grid, tr6, precision=1)
return
@ -241,7 +235,7 @@ class Procedure (SmartScript.SmartScript):
#maxGrid = where(greater(maxGrid,-100.0), maxGrid*3.28, maxGrid)
conversionGrid = grid.copy()
mask = conversionGrid>-0.40
grid = np.where(mask, conversionGrid*3.28, -80.0)
grid = np.where(mask, conversionGrid*3.28, np.float32(-80.0))
#return maxGrid # convert meters to feet
return grid
@ -271,7 +265,7 @@ class Procedure (SmartScript.SmartScript):
#maxGrid = where(greater(maxGrid,-100.0),maxGrid*3.28, maxGrid)
conversionGrid = grid.copy()
mask = conversionGrid>0.0
grid = np.where(mask,conversionGrid *3.28, -80.0)
grid = np.where(mask,conversionGrid *3.28, np.float32(-80.0))
#return maxGrid # convert meters to feet
return grid
@ -301,7 +295,7 @@ class Procedure (SmartScript.SmartScript):
#maxGrid = where(greater(maxGrid,-100.0),maxGrid*3.28, maxGrid)
conversionGrid = grid.copy()
mask = conversionGrid>-3.09
grid = np.where(mask, conversionGrid*3.28, -80.0)
grid = np.where(mask, conversionGrid*3.28, np.float32(-80.0))
#return maxGrid # convert meters to feet
return grid
@ -330,7 +324,7 @@ class Procedure (SmartScript.SmartScript):
#maxGrid = where(greater(maxGrid,-100.0),maxGrid*3.28, maxGrid)
conversionGrid=grid.copy()
mask = conversionGrid>-2.20
grid = np.where(mask, conversionGrid*3.28, -80.0)
grid = np.where(mask, conversionGrid*3.28, np.float32(-80.0))
#return maxGrid # convert meters to feet
return grid
@ -360,7 +354,7 @@ class Procedure (SmartScript.SmartScript):
#maxGrid = where(greater(maxGrid,-100.0),maxGrid*3.28, maxGrid)
conversionGrid = grid.copy()
mask = conversionGrid>-3.40
grid = np.where(mask, conversionGrid*3.28, -80.0)
grid = np.where(mask, conversionGrid*3.28, np.float32(-80.0))
#return maxGrid # convert meters to feet
return grid
@ -400,7 +394,7 @@ class Procedure (SmartScript.SmartScript):
sg[target] = np.where(np.greater(grid[src],-80.0),sg[target] + grid[src],sg[target])
count[target] = np.where(np.greater(grid[src],-80.0),count[target] + gridOfOnes[src],count[target])
return np.where(np.greater(count,0.0), sg / count, -80.0)
return np.where(np.greater(count,0.0), sg / count, np.float32(-80.0))
# Copies the specified weather elements in elementList into the Fcst database.
@ -537,13 +531,13 @@ class Procedure (SmartScript.SmartScript):
surgePctGridNAVD = np.where(np.greater(surgePctGridNAVD, -10.0), self.smoothGrid(surgePctGridNAVD,3), surgePctGridNAVD)
mask1 = np.logical_and(np.greater(msltonavd, -80.0),np.greater(surgePctGridNAVD,-80.0))
surgePctGridMSL= np.where(mask1, surgePctGridNAVD - msltonavd, -80.0) # MSL Grid
surgePctGridMSL= np.where(mask1, surgePctGridNAVD - msltonavd, np.float32(-80.0)) # MSL Grid
surgePctGridMLLW = np.where(np.greater(navdtomllw,-80.0) & np.greater(surgePctGridNAVD,-80.0), \
surgePctGridNAVD + navdtomllw, -80.0)# MLLW Grid
surgePctGridNAVD + navdtomllw, np.float32(-80.0)) # MLLW Grid
surgePctGridMHHW = np.where(np.greater(navdtomhhw,-80.0) & np.greater(surgePctGridNAVD,-80.0), \
surgePctGridNAVD + navdtomhhw, -80.0)# MHHW Grid
surgePctGridNAVD + navdtomhhw, np.float32(-80.0)) # MHHW Grid
surgeDiffMLLWMHHW = np.where(np.greater(surgePctGridMLLW,-80.0) & np.greater(surgePctGridMHHW, -80.0), \
surgePctGridMLLW-surgePctGridMHHW, -80.0)# Diff Grid Between MLLW and MHHW
surgePctGridMLLW-surgePctGridMHHW, np.float32(-80.0)) # Diff Grid Between MLLW and MHHW
self.makePhishGrid(pctStr, "FHAG0", smoothThreatGrid)
@ -665,8 +659,7 @@ class Procedure (SmartScript.SmartScript):
#print "THRESHOLD FOR KEY IS: ", key, threshDict[key]
thresh = threshDict[key]
keyIndex = self.getIndex(key, threatKeys)
coastalThreat = np.where(ssea & np.greater_equal(surgePctGrid, thresh), keyIndex,
coastalThreat)
coastalThreat[ssea & np.greater_equal(surgePctGrid, thresh)] = keyIndex
# create the CoastalThreat Grid
self.createGrid("Fcst", threatWEName, "DISCRETE",

View file

@ -225,7 +225,7 @@ class Procedure (SmartScript.SmartScript):
# increment the category. This code assumes that the categories are
# defined in increaing order of severity.
tornadoThreat = where(mask, tornadoThreat + 1, tornadoThreat)
tornadoThreat[mask] += 1
return tornadoThreat
@ -258,11 +258,11 @@ class Procedure (SmartScript.SmartScript):
#print "THRESH IS: ", thresh
keyIndex = self.getIndex(threshDict[key], threatKeys)
# make a temp grid where the thresholds are exceeded
tempGrid = where(greater_equal(D2DGrid, thresh), keyIndex, 0)
tempGrid = where(greater_equal(D2DGrid, thresh), int32(keyIndex), int32(0))
# calculate areas where this temp grid exceeds the threatGrid
mask = greater(tempGrid, tornadoThreat)
# update the threatGrid for these areas only
tornadoThreat = where(mask, keyIndex, tornadoThreat)
tornadoThreat[mask] = keyIndex
return tornadoThreat

View file

@ -313,7 +313,7 @@ class Procedure (SmartScript.SmartScript):
# See if the storm os outside the GFE domain. If it is, just update
# the adjustedWindMax and the stormMaxWindValue
if xPos is None or yPos is None:
adjustedWindMax = where(greater(ws, adjustedWindMax), ws, adjustedWindMax)
adjustedWindMax = maximum(ws, adjustedWindMax)
gridWindMax = max(ws.flat) # max value over the whole grid
stormMaxWindValue = max(gridWindMax, stormMaxWindValue) # update the overall max
continue
@ -495,7 +495,7 @@ class Procedure (SmartScript.SmartScript):
extremeIndex = self.getIndex("Extreme", keys)
# initialize the threat grid
threatGrid = self._empty # a grid of zeros
threatGrid = self.empty() # a grid of zeros
# Attempt to get the grid from the server.
@ -517,11 +517,11 @@ class Procedure (SmartScript.SmartScript):
if allWind:
threatGrid = where(windMax < windDict["Elevated"], 0, threatGrid)
threatGrid = where(windMax >= windDict["Elevated"], lowIndex, threatGrid)
threatGrid = where(windMax >= windDict["Mod"], modIndex, threatGrid)
threatGrid = where(windMax >= windDict["High1"], highIndex, threatGrid)
threatGrid = where(windMax >= windDict["Extreme"], extremeIndex, threatGrid)
threatGrid[windMax < windDict["Elevated"]] = 0
threatGrid[windMax >= windDict["Elevated"]] = lowIndex
threatGrid[windMax >= windDict["Mod"]] = modIndex
threatGrid[windMax >= windDict["High1"]] = highIndex
threatGrid[windMax >= windDict["Extreme"]] = extremeIndex
else:
@ -533,37 +533,37 @@ class Procedure (SmartScript.SmartScript):
#self.createGrid("Fcst", "Prob50", "SCALAR", prob50Grid, timeRange)
#self.createGrid("Fcst", "Prob64", "SCALAR", prob64Grid, timeRange)
#print "MAXWIND IS: ", maxWindValue
threatGrid = zeros(prob64Grid.shape)
threatGrid = where(prob34Grid < t34TS1, 0, threatGrid)
threatGrid = where(prob34Grid >= t34TS1, lowIndex, threatGrid)
threatGrid = where(prob50Grid >= t50TS2, modIndex, threatGrid)
threatGrid = where(prob64Grid >= t64Cat1, highIndex, threatGrid)
threatGrid = zeros_like(prob64Grid)
threatGrid[prob34Grid < t34TS1] = 0
threatGrid[prob34Grid >= t34TS1] = lowIndex
threatGrid[prob50Grid >= t50TS2] = modIndex
threatGrid[prob64Grid >= t64Cat1] = highIndex
if maxWindValue >= windDict['High2']:
threatGrid = where(prob64Grid >= t64Cat3, extremeIndex, threatGrid)
threatGrid[prob64Grid >= t64Cat3] = extremeIndex
if maxWindValue >= windDict['Extreme']:
threatGrid = where(prob64Grid >= t64Cat2, extremeIndex, threatGrid)
threatGrid[prob64Grid >= t64Cat2] = extremeIndex
# Upgrade windThreat based on windMax grid
##
# upgrade None to Elevated
windMask = (windMax >= windDict['Elevated']) & (windMax < windDict['Mod'])
threatMask = threatGrid < lowIndex
threatGrid = where(windMask & threatMask, lowIndex, threatGrid)
threatGrid[windMask & threatMask] = lowIndex
# upgrade Elevated to Med
windMask = (windMax >= windDict['Mod']) & (windMax < windDict['High1'])
threatMask = threatGrid < modIndex
threatGrid = where(windMask & threatMask, modIndex, threatGrid)
threatGrid[windMask & threatMask] = modIndex
# upgrade Med to High
windMask = (windMax >= windDict['High1']) & (windMax < windDict['Extreme'])
threatMask = threatGrid < highIndex
threatGrid = where(windMask & threatMask, highIndex, threatGrid)
threatGrid[windMask & threatMask] = highIndex
# upgrade High to Extreme
windMask = windMax >= windDict['Extreme']
threatMask = threatGrid < extremeIndex
threatGrid = where(windMask & threatMask, extremeIndex, threatGrid)
threatGrid[windMask & threatMask] = extremeIndex
# Remove previous version of grid.
dbTimes = self.makeDBTimeRange()

View file

@ -359,7 +359,7 @@ class Procedure (SmartScript.SmartScript):
zoneArea = self.getEditArea(each[0])
zoneMask = self.encodeEditArea(zoneArea)
mask = logical_or(mask, zoneMask)
grid = where(mask, watchIndex, grid)
grid[mask] = watchIndex
#remove any existing grid

View file

@ -103,9 +103,9 @@ class Tool (SmartScript.SmartScript):
else:
editAreaMask=ea
topoMask=editAreaMask*Topo
topoMaskMin=where(equal(topoMask,0),100000,topoMask)
maxtopo=maximum.reduce(maximum.reduce(topoMask))
mintopo=minimum.reduce(minimum.reduce(topoMaskMin))
topoMaskMin = where(equal(topoMask, 0), float32(100000), topoMask)
maxtopo = amax(topoMask)
mintopo = amin(topoMaskMin)
topodiff=(maxtopo-mintopo)+0.0001
if (elev=="Mountain"):
elevgrid=editAreaMask*((Topo-mintopo)/topodiff)

View file

@ -72,15 +72,11 @@ class Tool (SmartScript.SmartScript):
d = [0.0110, -0.0742, -0.0488, 0.0103, 0.2960, -0.1368, -0.0074, -0.0218, -0.0027]
# Initialize the coeficient grids
aGrid = empty_like(tGrid)
aGrid.fill(a[-1]) #last value in list
bGrid = empty_like(tGrid)
bGrid.fill(b[-1])
cGrid = empty_like(tGrid)
cGrid.fill(c[-1])
dGrid = empty_like(tGrid)
dGrid.fill(d[-1])
tDiff = zeros(tGrid.shape,dtype=float32)
aGrid = self.newGrid(a[-1])
bGrid = self.newGrid(b[-1])
cGrid = self.newGrid(c[-1])
dGrid = self.newGrid(d[-1])
tDiff = self.empty()
# define grids of coefficients based on tGrid
for i in xrange(len(tThresh) - 1):
@ -98,8 +94,8 @@ class Tool (SmartScript.SmartScript):
+ dGrid * pow(tDiff, 3)
# Clip the snowRatio grid to 10.0 where tGrid is outside limits
#baseRatio = where(greater(tGrid, 1.0), 0.0, baseRatio)
#baseRatio = where(less(tGrid, tThresh[0]), 10.0, baseRatio)
#baseRatio[greater(tGrid, 1.0)] = 0.0
#baseRatio[less(tGrid, tThresh[0])] = 10.0
return baseRatio
@ -182,7 +178,7 @@ class Tool (SmartScript.SmartScript):
# adjust snowRatio based on lapseRate
#lr = -(tCube[i+1] - tCube[i])
#lrAdj = where(greater_equal(lr,6.5), 1.0 + ((lr - lrMin) / (lrMax - lrMin)) * lrMaxAdj, 1.0)
#lrAdj = where(greater_equal(lr,6.5), 1.0 + ((lr - lrMin) / (lrMax - lrMin)) * lrMaxAdj, float32(1.0))
#layerSR[i] = layerSR[i] * lrAdj
# Calc avg pressure vertical velocity, scale based on RH and sum
@ -211,10 +207,10 @@ class Tool (SmartScript.SmartScript):
# This is basically Baumgardt - Top Down Approach - No ice No dice!
#mask = logical_and(less(tCube, 265.15), greater_equal(rhCube, 50.0))
#mask = sum(mask) # reduce to single level by adding bits verically
#totalSnowRatio = where(equal(mask, 0), 0.0, totalSnowRatio)
#totalSnowRatio[equal(mask, 0)] = 0.0
#
thicknessSnowRatio = zeros(gridShape,dtype=float32)
thicknessSnowRatio = self.empty()
myThickness = varDict["Thickness"]
if myThickness == "850-700":
@ -238,7 +234,7 @@ class Tool (SmartScript.SmartScript):
mask = any(less_equal(tCube, 272.65), axis = 0)
mask = sum(mask) # reduce to single level by adding bits vertically
# if mask == 0, nowhere in the column is temp < 0.5C
totalSnowRatio = where(mask, totalSnowRatio, 0.0)
totalSnowRatio[logical_not(mask)] = 0.0
#Calculate Snowfall - taper to zero from 31 to 34 F.
snowfall = QPF * totalSnowRatio
snowfall = where(greater(T, 31.0), pow(35.0 - T,2)/16.0 * snowfall , snowfall)

View file

@ -364,28 +364,23 @@ class Tool (SmartScript.SmartScript):
#print attstring
# Initialize the Wx values and keys
wxValues = array(PoP.shape, int8)
wxValues = empty_like(PoP, int8)
keys = []
if qualifiertype == "Prob":
wxValues = where(less(PoP, SChc_min_PoP_threshold), self.getByteValue("", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less(PoP, 24.5), self.getByteValue("SChc", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less(PoP, 54.5), self.getByteValue("Chc", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less(PoP, 74.5),self.getByteValue("Lkly", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less_equal(PoP, 100),self.getByteValue("Def", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
self.getByteValue("", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov))))))
wxValues[less_equal(PoP, 100)] = self.getByteValue("Def", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, 74.5)] = self.getByteValue("Lkly", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, 54.5)] = self.getByteValue("Chc", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, 24.5)] = self.getByteValue("SChc", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, SChc_min_PoP_threshold)] = self.getByteValue("", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
if qualifiertype == "Cov":
wxValues[less_equal(PoP, 100)] = self.getByteValue("Wide", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, 74.5)] = self.getByteValue("Num", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, 54.5)] = self.getByteValue("Sct", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, 24.5)] = self.getByteValue("Iso", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues[less(PoP, SChc_min_PoP_threshold)] = self.getByteValue("", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov)
wxValues = where(less(PoP, SChc_min_PoP_threshold), self.getByteValue("", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less(PoP, 24.5), self.getByteValue("Iso", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less(PoP, 54.5), self.getByteValue("Sct", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less(PoP, 74.5),self.getByteValue("Num", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
where(less_equal(PoP, 100),self.getByteValue("Wide", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov), \
self.getByteValue("", type, intensity, thunder, attstring, keys, alt_probcov, alt_catpop_probcov, alt_thunder_probcov))))))
wxValues = wxValues.astype(int8)
print "keys = ", keys
return (wxValues, keys)

View file

@ -89,10 +89,10 @@ class Tool (SmartScript.SmartScript):
mainAddMask = logical_and(greater_equal(PoP, 5), less(Sky, PoP + self._factor))
Sky = where(logical_and(less(PoP, 5), less_equal(Sky, PoP * self._lofactor)), PoP * self._lofactor,
where(logical_and(mainAddMask, less_equal(PoP, self._breathingRoom)), PoP + self._factor,
where(greater(PoP, self._breathingRoom), 100, Sky)))
where(greater(PoP, self._breathingRoom), float32(100), Sky)))
elif self._operator == "multiply":
Sky = where(logical_and(less(Sky, PoP * self._factor), less_equal(PoP * self._factor, 100)), PoP * self._factor,
where(logical_and(less(Sky, PoP * self._factor), greater(PoP * self._factor, 100)), 100, Sky))
where(logical_and(less(Sky, PoP * self._factor), greater(PoP * self._factor, 100)), float32(100), Sky))
else:
lowSkyMask = less(Sky, self._SkyLimit)
Sky = where(logical_and(lowSkyMask, greater_equal(PoP, self._PoPLimit)), self._SkyLimit,

View file

@ -327,7 +327,7 @@ class Tool (SmartScript.SmartScript):
# Average over the first (y) dimension - making the 'mid' grid
#
mask=clip(mask,0,1)
gridmin1=where(mask,gridmin,0)
gridmin1=where(mask,gridmin,float32(0))
mid=grid*0.0
midd=grid*0.0
c=cumsum(gridmin1,0)

View file

@ -329,7 +329,7 @@ class Tool (SmartScript.SmartScript):
# Average over the first (y) dimension - making the 'mid' grid
#
mask=clip(mask,0,1)
gridmin1=where(mask,gridmin,0)
gridmin1=where(mask,gridmin,float32(0))
mid=grid*0.0
midd=grid*0.0
c=cumsum(gridmin1,0)

View file

@ -327,7 +327,7 @@ class Tool (SmartScript.SmartScript):
# Average over the first (y) dimension - making the 'mid' grid
#
mask=clip(mask,0,1)
gridmin1=where(mask,gridmin,0)
gridmin1=where(mask,gridmin,float32(0))
mid=grid*0.0
midd=grid*0.0
c=cumsum(gridmin1,0)

View file

@ -65,7 +65,7 @@ class Tool (SmartScript.SmartScript):
downMask = logical_and(rhLessThan13, T80to112)
# make array that is T where conditions are true and 100, otherwise
adjustT = where(downMask, T, 80.0)
adjustT = where(downMask, T, float32(80.0))
HeatIndex = where(downMask, HeatIndex - (((13.0 - RH) / 4.0) * \
sqrt((17.0 - abs(adjustT - 95.0)) / 17)),
HeatIndex)

View file

@ -70,9 +70,9 @@ class Tool (SmartScript.SmartScript):
# the min/max in the edit area
#
minval=variableElement_GridInfo.getMinValue()
minvalgrid=(editAreaMask*0.0)+minval
minvalgrid=self.newGrid(minval)
maxval=variableElement_GridInfo.getMaxValue()
maxvalgrid=(editAreaMask*0.0)+maxval
maxvalgrid=self.newGrid(maxval)
#
# setup valgrid with the grid that will be
# limited (i.e. for vectors the speed)
@ -86,8 +86,8 @@ class Tool (SmartScript.SmartScript):
# area set to the max value for this element - so that the
# min will be found accurately. Conversely for maxs.
#
mincheck=where(greater(editAreaMask,0.5),valgrid,maxvalgrid)
maxcheck=where(greater(editAreaMask,0.5),valgrid,minvalgrid)
mincheck=where(editAreaMask,valgrid,maxvalgrid)
maxcheck=where(editAreaMask,valgrid,minvalgrid)
#
# Find the current max/min in the edit area
#

View file

@ -208,8 +208,8 @@ class Tool (SmartScript.SmartScript):
if (self.guiInfo['vectedit']==1):
newspd=speed
newdir=direc+zval
newdir=where(greater(newdir,360),subtract(newdir,360),newdir)
newdir=where(less(newdir,0),add(newdir,360),newdir)
newdir[greater(newdir, 360)] -= 360
newdir[less(newdir ,0)] += 360
elif (self.guiInfo['vectedit']==0):
newspd=clip(speed+zval,absmin,absmax)
newdir=direc
@ -218,8 +218,8 @@ class Tool (SmartScript.SmartScript):
zval=self.OA.Serp(self.ylist,self.xloclist,self.yloclist,self.hloclist,
self.elevfactor,Topo)
newdir=direc+zval
newdir=where(greater(newdir,360),subtract(newdir,360),newdir)
newdir=where(less(newdir,0),add(newdir,360),newdir)
newdir[greater(newdir, 360)] -= 360
newdir[less(newdir ,0)] += 360
return (newspd,newdir)
#---------------------------------------------------------------------------
@ -623,7 +623,7 @@ class Tool (SmartScript.SmartScript):
# Average over the first (y) dimension - making the 'mid' grid
#
mask=clip(mask,0,1)
gridmin1=where(mask,gridmin,0)
gridmin1=where(mask,gridmin,float32(0))
mid=grid*0.0
midd=grid*0.0
c=cumsum(gridmin1,0)

View file

@ -184,19 +184,19 @@ class Tool (SmartScript.SmartScript):
bits,iscgrid=isc
if ((WEname=="MaxT")or(WEname=="PoP")):
sum=where(bits,maximum(iscgrid,sum),sum)
cnt=where(bits,1,cnt)
cnt[bits] = 1
elif (WEname=="MinT"):
sum=where(bits,minimum(iscgrid,sum),sum)
cnt=where(bits,1,cnt)
cnt[bits] = 1
else:
sum=where(bits,sum+iscgrid,sum)
cnt=where(bits,cnt+1,cnt)
cnt[bits] += 1
if wxType==2: # VECTOR
bits,mag,dir=isc
(u,v)=self.MagDirToUV(mag,dir)
sum[0]=where(bits,sum[0]+u,sum[0])
sum[1]=where(bits,sum[1]+v,sum[1])
cnt=where(bits,cnt+1,cnt)
cnt[bits] += 1
#
# now calculate average/max/min, etc.
# (count is always 1 for max/min)
@ -209,7 +209,7 @@ class Tool (SmartScript.SmartScript):
sum[1]=where(equal(cnt,0),v,sum[1])
else:
sum=where(equal(cnt,0),variableElement,sum)
cnt=where(equal(cnt,0),1,cnt)
cnt[equal(cnt,0)] = 1
new=sum/cnt
if (wxType==2):
(mag,dir)=self.UVToMagDir(new[0],new[1])

View file

@ -47,18 +47,18 @@ class Tool (SmartScript.SmartScript):
## SnowRatio = 7
## else:
## SnowRatio = SnowRatioDict[int(T)]
SnowRatio = zeros(T.shape)
SnowRatio = where(less(T, 9), 20,
where(greater_equal(T, 30), 7,
self.linear(9,29,18,8,T)))
SnowRatio = self.linear(9,29,18,8,T).astype(float32)
SnowRatio[less(T, 9)] = 20
SnowRatio[greater_equal(T, 30)] = 7
## # Determine new value
## if (FzLevel-1000) <= Topo:
## SnowAmt = SnowRatio * QPF
## else:
## SnowAmt = 0
SnowAmt = zeros(T.shape)
SnowAmt = where(less_equal(FzLevel-1000, Topo), SnowRatio*QPF,0)
SnowAmt = self.empty()
fzLevelMask = less_equal(FzLevel-1000, Topo)
SnowAmt[fzLevelMask] = SnowRatio[fzLevelMask] * QPF[fzLevelMask]
# Return the new value
return SnowAmt

View file

@ -2066,7 +2066,7 @@ class BOIVerifyUtility(SmartScript.SmartScript):
else:
cyc=cycle*HOURSECS
rem=remainder(self.fncBtime,DAYSECS).astype(int)
rightCycle=where(equal(rem,cyc),1,rightCycle)
rightCycle[equal(rem,cyc)] = 1
#
# get list of forecast records with right forecast hours
#
@ -3265,7 +3265,7 @@ class BOIVerifyUtility(SmartScript.SmartScript):
for cycle in cycleList:
cyc=cycle*HOURSECS
rem=remainder(self.fncBtime,DAYSECS).astype('i')
rightCycle=where(equal(rem,cyc),1,rightCycle)
rightCycle[equal(rem,cyc)] = 1
#
# get logical array of records with right forecast hours
#
@ -3309,15 +3309,15 @@ class BOIVerifyUtility(SmartScript.SmartScript):
ctype=type(cycles)
if ((ctype is types.TupleType)or(ctype is types.ListType)):
for cycle in cycles:
if type(cycle) is types.StringType:
cycleList.append(int(cycle))
else:
cycleList.append(cycle)
if type(cycle) is types.StringType:
cycleList.append(int(cycle))
else:
cycleList.append(cycle)
else:
if type(cycles) is types.StringType:
cycleList.append(int(cycles))
else:
cycleList.append(cycles)
if type(cycles) is types.StringType:
cycleList.append(int(cycles))
else:
cycleList.append(cycles)
if (-1 in cycleList):
rightCycle=ones(self.sncBtime.shape)
else:
@ -3325,7 +3325,7 @@ class BOIVerifyUtility(SmartScript.SmartScript):
for cycle in cycleList:
cyc=cycle*HOURSECS
rem=remainder(self.sncBtime,DAYSECS).astype('i')
rightCycle=where(equal(rem,cyc),1,rightCycle)
rightCycle[equal(rem,cyc)] = 1
#
# get logical array of records with right forecast hours
#
@ -3575,9 +3575,9 @@ class BOIVerifyUtility(SmartScript.SmartScript):
# been done...so don't do that...
#
if vectorErr==0:
err=where(eaGrid,fcstGrid-obsGrid,0)
err=where(eaGrid,fcstGrid-obsGrid,float32(0))
else:
err=where(eaGrid,err,0)
err=where(eaGrid,err,float32(0))
#
# Now all the stat calculations
#
@ -3650,10 +3650,10 @@ class BOIVerifyUtility(SmartScript.SmartScript):
#
notFcst=logical_not(fcstOccur)
notObs=logical_not(obsOccur)
hits=add.reduce(add.reduce(where(eaGrid,logical_and(fcstOccur,obsOccur),0)))
miss=add.reduce(add.reduce(where(eaGrid,logical_and(notFcst,obsOccur) ,0)))
falr=add.reduce(add.reduce(where(eaGrid,logical_and(fcstOccur,notObs) ,0)))
corn=add.reduce(add.reduce(where(eaGrid,logical_and(notFcst,notObs) ,0)))
hits=count_nonzero(logical_and(eaGrid,logical_and(fcstOccur,obsOccur)))
miss=count_nonzero(logical_and(eaGrid,logical_and(notFcst,obsOccur)))
falr=count_nonzero(logical_and(eaGrid,logical_and(fcstOccur,notObs)))
corn=count_nonzero(logical_and(eaGrid,logical_and(notFcst,notObs)))
total=hits+miss+falr+corn
if abs(float(total)-fnum)>0.5:
self.logMsg("Number in binary histogram not the same as number of points")
@ -3770,98 +3770,98 @@ class BOIVerifyUtility(SmartScript.SmartScript):
return corn/1.0
if statID in ["fc","afc"]:
nofcst=less(total,1)
total=where(nofcst,1,total)
total[nofcst] = 1
score=(hits+corn)/total
score=where(nofcst,1.0,score)
score[nofcst] = 1.0
return score
if statID in ["freqo",]:
nofcst=less(total,1)
total=where(nofcst,1,total)
total[nofcst] = 1
score=(hits+miss)/total
score=where(nofcst,0.0,score)
score[nofcst] = 0.0
return score
if statID in ["freqf",]:
nofcst=less(total,1)
total=where(nofcst,1,total)
total[nofcst] = 1
score=(hits+falr)/total
score=where(nofcst,0.0,score)
score[nofcst] = 0.0
return score
if statID in ["freqbias","afreqbias"]:
denom=hits+miss
nofcst=less(denom,1)
denom=where(nofcst,1,denom)
denom[nofcst] = 1
score=(hits+falr)/denom
score=where(nofcst,1.0,score)
score[nofcst] = 1.0
return score
if statID in ["pod","apod"]:
denom=hits+miss
nofcst=less(denom,1)
denom=where(nofcst,1,denom)
denom[nofcst] = 1
score=hits/denom
score=where(nofcst,1.0,score)
score[nofcst] = 1.0
return score
if statID in ["far","afar"]:
denom=falr+hits
nofcst=less(denom,1)
denom==where(nofcst,1,denom)
denom[nofcst] = 1
score=falr/denom
score=where(nofcst,0.0,score)
score[nofcst] = 0.0
return score
if statID in ["pofd","apofd"]:
denom=falr+corn
nofcst=less(denom,1)
denom=where(nofcst,1,denom)
denom[nofcst] = 1
score=falr/denom
score=where(nofcst,0.0,score)
score[nofcst] = 0.0
return score
if statID in ["ts","ats"]:
denom=hits+miss+falr
nofcst=less(denom,1)
denom=where(nofcst,1,denom)
denom[nofcst] = 1
score=hits/denom
score=where(nofcst,1.0,score)
score[nofcst] = 1.0
return score
if statID in ["ets","aets"]:
total=where(less(total,1),1,total)
total[less(total,1)] = 1
hitsrand=((hits+miss)*(hits+falr))/total
denom=hits+miss+falr-hitsrand
nofcst=logical_and(greater(denom,-0.1),less(denom,0.1))
denom=where(nofcst,1,denom)
denom[nofcst] = 1
score=(hits-hitsrand)/denom
score=where(nofcst,1.0,score)
score[nofcst] = 1.0
return score
if statID in ["hk","ahk"]:
#pofd
denom=falr+corn
nofcst=less(denom,1)
denom=where(nofcst,1,denom)
denom[nofcst] = 1
pofd=falr/denom
pofd=where(nofcst,0.0,pofd)
pofd[nofcst] = 0.0
#pod
denom=hits+miss
nofcst=less(denom,1)
denom=where(nofcst,1,denom)
denom[nofcst] = 1
pod=hits/denom
pod=where(nofcst,1.0,pod)
pod[nofcst] = 1.0
score=pod-pofd
return score
if statID in ["hss","ahss"]:
total=where(less(total,1),1,total)
total[less(total,1)] = 1
ecrand=(((hits+miss)*(hits+falr))+((corn+miss)*(corn+falr)))/total
denom=total-ecrand
nofcst=logical_and(greater(denom,-0.1),less(denom,0.1))
denom=where(nofcst,1,denom)
denom[nofcst] = 1
score=(hits+corn-ecrand)/denom
score=where(nofcst,1.0,score)
score[nofcst] = 1.0
return score
if statID in ["oddsratio","aoddsratio"]:
no1=logical_or(less(hits,0.5),less(corn,0.5))
no2=logical_or(less(falr,0.5),less(miss,0.5))
nofcst=logical_or(no1,no2)
denom=falr*miss
denom=where(less(denom,1),1,denom)
denom[less(denom,1)] = 1
score=(hits*corn)/denom
score=where(nofcst,200.0,score)
score[nofcst] = 200.0
return score
#==================================================================
# getVerStatScales - Main routine to get a calculate a statistic
@ -4029,9 +4029,9 @@ class BOIVerifyUtility(SmartScript.SmartScript):
# been done...so don't do that...
#
if vectorErr==0:
err=where(eaGrid,fcstGrid-obsGrid,0)
err=where(eaGrid,fcstGrid-obsGrid,float32(0))
else:
err=where(eaGrid,err,0)
err=where(eaGrid,err,float32(0))
#
# Now all the stat calculations
#
@ -4099,10 +4099,10 @@ class BOIVerifyUtility(SmartScript.SmartScript):
#
notFcst=logical_not(fcstOccur)
notObs=logical_not(obsOccur)
hits=add.reduce(add.reduce(where(eaGrid,logical_and(fcstOccur,obsOccur),0)))
miss=add.reduce(add.reduce(where(eaGrid,logical_and(notFcst,obsOccur) ,0)))
falr=add.reduce(add.reduce(where(eaGrid,logical_and(fcstOccur,notObs) ,0)))
corn=add.reduce(add.reduce(where(eaGrid,logical_and(notFcst,notObs) ,0)))
hits=count_nonzero(logical_and(eaGrid,logical_and(fcstOccur,obsOccur)))
miss=count_nonzero(logical_and(eaGrid,logical_and(notFcst,obsOccur)))
falr=count_nonzero(logical_and(eaGrid,logical_and(fcstOccur,notObs)))
corn=count_nonzero(logical_and(eaGrid,logical_and(notFcst,notObs)))
total=hits+miss+falr+corn
if abs(float(total)-fnum)>0.5:
self.logMsg("Number in binary histogram not the same as number of points")
@ -4928,7 +4928,7 @@ class BOIVerifyUtility(SmartScript.SmartScript):
# Average over the first (y) dimension - making the 'mid' grid
#
mask=clip(mask,0,1)
gridmin1=where(mask,gridmin,0)
gridmin1=where(mask,gridmin,float32(0))
mid=grid*0.0
midd=grid*0.0
c=cumsum(gridmin1,0)
@ -5009,7 +5009,7 @@ class BOIVerifyUtility(SmartScript.SmartScript):
grid1=grid
else:
mask=clip(mask,0,1)
grid1=where(mask,grid,0)
grid1=where(mask,grid,float32(0))
#
# Average over the first (y) dimension - making the 'mid' grid
#

View file

@ -328,7 +328,7 @@ class ISC_Utility(SmartScript.SmartScript):
if (landea is not None):
landGrid=self.encodeEditArea(landea)
if landGrid is None:
landGrid=self.getTopo() * 0.0
landGrid = self.empty(numpy.bool)
eanames=self.editAreaList()
for eaname in eanames:
if ((len(eaname)==7)and(eaname[0:4]=="ISC_")):
@ -337,7 +337,7 @@ class ISC_Utility(SmartScript.SmartScript):
ea=self.getEditArea(name)
if ea is not None:
grid=self.encodeEditArea(ea)
landGrid=numpy.where(grid,1,landGrid)
landGrid |= grid
return landGrid
#========================================================================
# _getThresholdInfo - return thresholdInfo structure for the
@ -921,7 +921,7 @@ class ISC_Utility(SmartScript.SmartScript):
sum=self._empty
if GridType.VECTOR.equals(wxType):
sumv=self._empty
cnt=self._empty
cnt = self.empty()
#
# foreach time range...get the ISC composite for
# that hour
@ -936,22 +936,22 @@ class ISC_Utility(SmartScript.SmartScript):
if GridType.SCALAR.equals(wxType):
bits,isc=comp
#isc=self.getGrids("ISC",parmName,"SFC",tr)
if ((parmName=="MaxT")or(parmName=="PoP")):
if parmName in ["MaxT", "PoP"]:
sum=numpy.where(bits,numpy.maximum(isc,sum),sum)
cnt=numpy.where(bits,1,cnt)
elif (parmName=="MinT"):
cnt[bits] = 1
elif parmName=="MinT":
sum=numpy.where(bits,numpy.minimum(isc,sum),sum)
cnt=numpy.where(bits,1,cnt)
cnt[bits] = 1
else:
sum=numpy.where(bits,sum+isc,sum)
cnt=numpy.where(bits,cnt+1,cnt)
cnt[bits] += 1
if GridType.VECTOR.equals(wxType):
bits,mag,direc = comp
#(mag,direc)=self.getGrids("ISC",parmName,"SFC",tr)
(u,v)=self.MagDirToUV(mag,direc)
sum=numpy.where(bits,sum+u,sum)
sumv=numpy.where(bits,sumv+v,sumv)
cnt=numpy.where(bits,cnt+1,cnt)
cnt[bits] += 1
if GridType.WEATHER.equals(wxType):
bits = comp
bits,keys,strings=comp
@ -963,14 +963,14 @@ class ISC_Utility(SmartScript.SmartScript):
noISC=numpy.less(cnt,0.5)
bits=numpy.greater(cnt,0.5)
if GridType.SCALAR.equals(wxType) or GridType.VECTOR.equals(wxType):
cnt=numpy.where(numpy.less(cnt,1),1,cnt)
cnt[numpy.less(cnt, 1)] = 1
if GridType.VECTOR.equals(wxType):
sum=numpy.where(noISC,minlimit,sum/cnt)
sumv=numpy.where(noISC,minlimit,sumv/cnt)
(mag,direc)=self.UVToMagDir(sum,sumv)
(baseMag,baseDir)=baseGrid
mag=numpy.where(noISC,baseMag,mag)
direc=numpy.where(noISC,baseDir,direc)
mag[noISC] = baseMag
direc[noISC] = baseDir
return bits,mag,direc
else:
sum=numpy.where(noISC,baseGrid,sum/cnt)
@ -1085,7 +1085,7 @@ class ISC_Utility(SmartScript.SmartScript):
# just like other calcuations
#
def _checkViolate(self, bits, criteria, areamask, discGrid, threshold):
violate=self._empty
violate = self.empty(bool)
for i in range(4): # range(8) to consider diagonal neighbors
#
# make sure data exists for both points
@ -1108,7 +1108,7 @@ class ISC_Utility(SmartScript.SmartScript):
#
mask=logical_and(logical_and(logical_and(exist,meetcrit),onborder),less(self._topodiff[i],self.MAXTOPODIFF))
#
violate=where(logical_and(mask,greater(abs(discGrid),threshold)),1,violate)
violate[logical_and(mask, greater(abs(discGrid), threshold))] = True
return violate

View file

@ -543,7 +543,7 @@ class ObjAnal(SmartScript.SmartScript):
#
#
nearzero=np.logical_and(np.less(zarr,0.001),np.greater(zarr,-0.001))
zarr=np.where(nearzero,0.001,zarr).astype(np.float32)
zarr[nearzero] = 0.001
del nearzero
zw=zarr*self.SerpWsum
del zarr
@ -615,7 +615,7 @@ class ObjAnal(SmartScript.SmartScript):
zarr=np.array(zlist,np.float32)
#
nearzero=np.logical_and(np.less(zarr,0.001),np.greater(zarr,-0.001))
zarr=np.where(nearzero,0.001,zarr)
zarr[nearzero] = 0.001
newsize=(numpts,self.ymax,self.xmax)
@ -625,7 +625,7 @@ class ObjAnal(SmartScript.SmartScript):
self.logtime("Getting distances",3)
for k in range(numpts):
dist=self.getDistance(xarr[k],yarr[k],harr[k],scaledtopo,newlandMask)
dist=np.where(np.less(dist,0.000001),0.000001,dist)
dist[np.less(dist,0.000001)] = 0.000001
dsquared[k]=(dist*dist).astype(np.float32)
dists[k]=dist.astype(np.float32)
self.logtime("Done getting distances",3)
@ -643,13 +643,13 @@ class ObjAnal(SmartScript.SmartScript):
if self.DSquaredDist>0:
dd=self.DSquaredDist/self.gridres
finalDist=np.where(np.greater(dd,finalDist),dd,finalDist)
w=np.where(np.greater(dists[k],finalDist),0.0,w)
w[np.greater(dists[k],finalDist)] = 0.0
elif self.DSquaredDist>0:
w=np.where(np.greater(dists[k],self.DSquaredDist/self.gridres),0.0,w)
w[np.greater(dists[k],self.DSquaredDist/self.gridres)] = 0.0
totweight=totweight+w
totsum=totsum+(zarr[k]*w)
totweight=np.where(np.less(totweight,1.0e-200),1.0,totweight)
totweight[np.less(totweight,1.0e-200)] = 1.0
chg=totsum/totweight
self.logtime("Done with Distance Squared calculations",2)
return chg
@ -744,7 +744,7 @@ class ObjAnal(SmartScript.SmartScript):
# Barnes weight is e taken to the negative xx power -
# but make sure it isn't huge - which would return a zero weight
#
xx=np.where(np.greater(xx,200.0),200.0,xx)
xx[np.greater(xx,200.0)] = 200.0
w=(np.exp(xx*-1.0)).astype(np.float32)
totweights=totweights+w
#
@ -756,7 +756,7 @@ class ObjAnal(SmartScript.SmartScript):
# Calculate weighted average. Sum of (weights * values) divided by
# the sum of weights (make sure sum of weights is non-zero)
#
totweights=np.where(np.less(totweights,1.0e-200),1.0e-200,totweights)
totweights[np.less(totweights,1.0e-200)] = 1.0e-200
chg=totsum/totweights
#
# Barnes PASS 2
@ -773,7 +773,7 @@ class ObjAnal(SmartScript.SmartScript):
# Barnes weight is e taken to the negative xx power -
# but make sure it isn't huge - which would return a zero weight
#
xx=np.where(np.greater(xx,200.0),200.0,xx)
xx[np.greater(xx,200.0)] = 200.0
w=(np.exp(xx*-1.0)).astype(np.float32)
totweights=totweights+w
#
@ -788,7 +788,7 @@ class ObjAnal(SmartScript.SmartScript):
# Calculate weighted average. Sum of (weights * values) divided by
# the sum of weights (make sure sum of weights is non-zero)
#
totweights=np.where(np.less(totweights,1.0e-200),1.0e-200,totweights)
totweights[np.less(totweights,1.0e-200)] = 1.0e-200
chg2=totsum/totweights
#
# Add the adjustment from PASS 2 to PASS 1
@ -970,7 +970,7 @@ class ObjAnal(SmartScript.SmartScript):
# that way maximum value in each column will be the one where
# distance is less or equal to mostremote distance
#
dloc=np.where(np.greater(dsums,mostremote),0,dsums)
dloc=np.where(np.greater(dsums,mostremote),np.float32(0),dsums)
#
# get total distance up to the point where it is less than mostremote
#

View file

@ -1387,7 +1387,7 @@ class SmartScript(BaseTool.BaseTool):
if combinedKey not in headKeys:
headKeys.append(combinedKey)
index = self.getIndex(combinedKey, headKeys)
headValues = where(overlap, index, headValues)
headValues[overlap] = index
# return the new headlines grid
return (headValues, headKeys)

View file

@ -41,12 +41,12 @@ class Tool (SmartScript.SmartScript):
# Assign Wx based on PoP
# Separate Wx into components
wxValues = Wx[0]
wxValues = Wx[0].copy()
keys = Wx[1]
wxValues = where( less(PoP, 20), self.getIndex("<NoCov>:<NoWx>:<NoInten>:<NoVis>:",keys), wxValues)
wxValues = where(logical_and( greater_equal(PoP, 20), less(PoP, 35)), self.getIndex("Chc:R:-:<NoVis>:" ,keys), wxValues)
wxValues = where(logical_and( greater_equal(PoP, 35), less(PoP, 55)), self.getIndex("Sct:RW:m:<NoVis>:" ,keys), wxValues)
wxValues = where(greater_equal(PoP, 55), self.getIndex("Wide:R:+:<NoVis>:" ,keys), wxValues)
wxValues[less(PoP, 20)] = self.getIndex("<NoCov>:<NoWx>:<NoInten>:<NoVis>:",keys)
wxValues[logical_and(greater_equal(PoP, 20), less(PoP, 35))] = self.getIndex("Chc:R:-:<NoVis>:" ,keys)
wxValues[logical_and(greater_equal(PoP, 35), less(PoP, 55))] = self.getIndex("Sct:RW:m:<NoVis>:" ,keys)
wxValues[greater_equal(PoP, 55)] = self.getIndex("Wide:R:+:<NoVis>:" ,keys)
return (wxValues, keys)

View file

@ -40,12 +40,12 @@ class Tool (SmartScript.SmartScript):
def execute(self, PoP, Wx):
# Assign PoP based on Wx
PoP = where(self.wxMask(Wx, "<NoCov>:"), 0, PoP)
PoP[self.wxMask(Wx, "<NoCov>:")] = 0
# Here we need to require a regular expression to avoid confusion between "Chc" and "SChc" and "Sct" and "WSct"
PoP = where(self.wxMask(Wx, "^Chc:", 1), 25, PoP)
PoP = where(self.wxMask(Wx, "^Sct:", 1), 55, PoP)
PoP[self.wxMask(Wx, "^Chc:", 1)] = 25
PoP[self.wxMask(Wx, "^Sct:", 1)] = 55
PoP = where(self.wxMask(Wx, "Wide:"), 80, PoP)
PoP[self.wxMask(Wx, "Wide:")] = 80
return PoP

View file

@ -48,6 +48,6 @@ class Tool (SmartScript.SmartScript):
SnowAmt = where(less(T, 20), QPF * 18,
where(less(T, 25), QPF * 14,
QPF * 10))
SnowAmt = where(less(Topo, elevation), 0, QPF)
SnowAmt = where(less(Topo, elevation), float32(0), QPF)
# Return the new value
return SnowAmt

View file

@ -103,9 +103,10 @@ class Tool (SmartScript.SmartScript):
mixingHt = where(readyToSet, newMh, mixingHt)
lastTuple = (ghCube[i], thetaCube[i])
mixingHt = where(equal(mixingHt,-1), 0.0, mixingHt)
mixingHt = mixingHt * 3.2808
mixingHt = where(equal(mixingHt, 0.0), 0.0, mixingHt-Topo)
mixingHt[equal(mixingHt,-1)] = 0.0
mixingHt *= 3.2808
mask = not_equal(mixingHt, 0.0)
mixingHt[mask] -= Topo[mask]
#print "MixingHT:", mixingHt[90,80], "pres:", sfcPres[90,80],
#print sfcTheta[90,80], Topo[90,80]

View file

@ -73,7 +73,7 @@ class Tool (SmartScript.SmartScript):
## var2 = varDict["Variable name2"]
# Determine new value
Wetflag = where(greater(QPF, 0.10), 1, 0)
Wetflag = greater(QPF, 0.10).astype(float32)
# Return the new value
return Wetflag

View file

@ -57,7 +57,7 @@ class VCParm:
return MinT_ISC[0][1]
#max value for this parm
maxV = self.getWEInfo()[0][4]
rval = where(MinT_ISC[0][2], MinT_ISC[0][1], maxV)
rval = where(MinT_ISC[0][2], MinT_ISC[0][1], float32(maxV))
for i in MinT_ISC:
rval = where(i[2], minimum(i[1], rval), rval)
return rval