Ejemplo n.º 1
0
 def testChoose(self):
     ct1 = MV2.TransientVariable([1, 1, 2, 0, 1])
     ctr = MV2.choose(ct1, [numpy.ma.masked, 10, 20, 30, 40])
     self.assertTrue(MV2.allclose(ctr, [10, 10, 20, 100, 10]))
     ctx = MV2.TransientVariable([1, 2, 3, 150, 4])
     cty = -MV2.TransientVariable([1, 2, 3, 150, 4])
     ctr = MV2.choose(MV2.greater(ctx, 100), (ctx, 100))
     self.assertTrue(MV2.allclose(ctr, [1, 2, 3, 100, 4]))
     ctr = MV2.choose(MV2.greater(ctx, 100), (ctx, cty))
     self.assertTrue(MV2.allclose(ctr, [1, 2, 3, -150, 4]))
Ejemplo n.º 2
0
##   all elements masked in a or in weights ignored.
##   weights if given must have a's shape.
##   Denominator is multiplied by 1.0 to prevent truncation for integers.
##   returned governs return of second quantity, the weights.
xav = MV2.average(xones, axis=1)
xav2 = MV2.average(ud)
xav3 = MV2.average(udat)
xav4, wav4 = MV2.average(udat,
                         weights=MV2.ones(udat.shape, numpy.float),
                         returned=1)

## choose(indices, t)
##   Shaped like indices, values t[i] where at indices[i]
##   If t[j] is masked, special treatment to preserve type.
ct1 = MV2.TransientVariable([1, 1, 2, 0, 1])
ctr = MV2.choose(ct1, [numpy.ma.masked, 10, 20, 30, 40])
if not MV2.allclose(ctr, [10, 10, 20, 100, 10]): markError('choose error 1')
ctx = MV2.TransientVariable([1, 2, 3, 150, 4])
cty = -MV2.TransientVariable([1, 2, 3, 150, 4])
ctr = MV2.choose(MV2.greater(ctx, 100), (ctx, 100))
if not MV2.allclose(ctr, [1, 2, 3, 100, 4]): markError('choose error 2')
ctr = MV2.choose(MV2.greater(ctx, 100), (ctx, cty))
if not MV2.allclose(ctr, [1, 2, 3, -150, 4]): markError('choose error 3')

## concatenate(arrays, axis=0, axisid=None, axisattributes=None)
##   Concatenate the arrays along the given axis. Give the extended axis the id and
##   attributes provided - by default, those of the first array.

try:
    xcon = MV2.concatenate((ud, vd))
except:
Ejemplo n.º 3
0
##   Result may equal masked if average cannot be computed.
##   If weights are given, result is sum(a*weights)/sum(weights), with
##   all elements masked in a or in weights ignored.
##   weights if given must have a's shape. 
##   Denominator is multiplied by 1.0 to prevent truncation for integers.
##   returned governs return of second quantity, the weights.
xav = MV2.average(xones, axis=1)
xav2 = MV2.average(ud)
xav3 = MV2.average(udat)
xav4, wav4 = MV2.average(udat, weights=MV2.ones(udat.shape, numpy.float), returned=1)

## choose(indices, t) 
##   Shaped like indices, values t[i] where at indices[i]
##   If t[j] is masked, special treatment to preserve type.
ct1 = MV2.TransientVariable([1,1,2,0,1])
ctr = MV2.choose(ct1, [numpy.ma.masked, 10,20,30,40])
if not MV2.allclose(ctr, [10, 10, 20, 100, 10]): markError('choose error 1')
ctx = MV2.TransientVariable([1,2,3,150,4])
cty = -MV2.TransientVariable([1,2,3,150,4])
ctr = MV2.choose(MV2.greater(ctx,100), (ctx, 100))
if not MV2.allclose(ctr, [1,2,3,100,4]): markError('choose error 2')
ctr = MV2.choose(MV2.greater(ctx,100), (ctx, cty))
if not MV2.allclose(ctr, [1,2,3,-150,4]): markError('choose error 3')

## concatenate(arrays, axis=0, axisid=None, axisattributes=None) 
##   Concatenate the arrays along the given axis. Give the extended axis the id and
##   attributes provided - by default, those of the first array.

try:
    xcon = MV2.concatenate((ud,vd))
except:
pft2010[15, :, :] = c3per2010
pft2010[16, :, :] = c4per2010
pft2010[17, :, :] = c3nfx2010
pft2010[18, :, :] = urban2010

#Adjust Natural vegetation i.e.expand/reduce
#before adjusting make sure not to overlap vegetation on baresoil
totveg2010 = totnveg2010_new + totanth_hurt2010
totveg2010_notOK = MV2.masked_values(totveg2010 - lndf_hurt, 0.).mask
no_nvegmask = MV2.masked_values(totveg2010, 0.).mask
for npft in range(10):
    print 'npft', npft
    pft_n = nveg2010[npft, :, :]
    pft_tmp = MV2.choose(
        totveg2010_notOK,
        (MV2.choose(no_nvegmask,
                    (pft_n * totnveg2010_new /
                     MV2.where(totnveg2010 == 0, 1, totnveg2010), 0.)), pft_n *
         (totnveg2010_new / MV2.where(totnveg2010 == 0, 1, totnveg2010))))
    print 'Reduction/ Expansion of Natural vegetation is done'
    pft2010[npft + 1, :, :] = pft_tmp
    print 'pft_back assignment is done'

#Since we consider rangeland as Natural grassland partition; add here to natural grassland after partitioning c3/c4
c3_range2010 = c3gr2010 * 0.0
c4_range2010 = c4gr2010 * 0.0
c3_range2010 = MV2.where(((rangel2010 != 0) & (pft_biome == 3) |
                          (pft_biome == 4) | (pft_biome == 5)), rangel2010, 0)
c4_range2010 = MV2.where(
    ((rangel2010 != 0) & (pft_biome == 1) | (pft_biome == 2)), rangel2010, 0)
pft2010[9, :, :] = pft2010[9, :, :] + c3_range2010
pft2010[10, :, :] = pft2010[10, :, :] + c4_range2010