Esempio n. 1
0
def Flood():
    for y in xrange(2002, 2005):
        lists = [[path+str(y) + "/flood_thr.%d%03d.tif" % (y, m) for m in xrange(91, 335)]]
        array = np.array(lists)
        images = array.reshape(array.shape[0] * array.shape[1])
        n = 0
        array = []
        for j in images:
            if os.path.exists(j) is True:
                image = GImage(j)
                flood = image.Band2Array(1)
                if n ==0 :
                    flood = np.where(flood == fill, 0 , flood)
                    for k in xrange(len(flood)):
                        array.append(flood[k])
                else:
                    array = np.where(flood == fill, add(array,0) , add(array, flood))
                n += 1
        print n
        #tif_opath1= tifpath+str(y)+".totalevi.tif"
        #image.WriteArrayAsImage(tif_opath1, array)
        #array = array*8
        tif_opath= path+str(y)+".flood_K_dur.tif"
        image.WriteArrayAsImage(tif_opath, array)
        print y
Esempio n. 2
0
 def CalcLSWI (self, NIR, SWIR, Blue, fill):
     Blue [Blue >= 0.27] = fill
     Swir_lower=numpy.where(Blue == fill, fill , add(NIR, SWIR))
     Swir_upper=numpy.where(Blue == fill, fill , subtract(NIR, SWIR))
     Swir_lower=numpy.where(Swir_lower ==0 , fill, Swir_lower)
     LSWI=numpy.where(Swir_lower==fill, fill ,Swir_upper/Swir_lower)
     return LSWI
Esempio n. 3
0
 def CalcNDVI ( self , NIR , Red, fill):
     Ndvi_lower = numpy.where (NIR == fill, fill , add (NIR , Red))
     Ndvi_upper = numpy.where (NIR == fill, fill ,subtract (NIR , Red))
     #Mask = Numpy.Greater (Ndvi_lower, 0)
     Ndvi_lower = numpy.where (Ndvi_lower == 0 , fill , Ndvi_lower)
     NDVI = numpy.where (Ndvi_lower == fill , fill , Ndvi_upper/Ndvi_lower)
     return NDVI
Esempio n. 4
0
def _lerp(a, b, t, out=None):
    """ Linearly interpolate from a to b by a factor of t """
    diff_b_a = subtract(b, a)
    # asanyarray is a stop-gap until gh-13105
    lerp_interpolation = asanyarray(add(a, diff_b_a * t, out=out))
    subtract(b, diff_b_a * (1 - t), out=lerp_interpolation, where=t >= 0.5)
    if lerp_interpolation.ndim == 0 and out is None:
        lerp_interpolation = lerp_interpolation[()]  # unpack 0d arrays
    return lerp_interpolation
Esempio n. 5
0
    def CalcMLSWI ( self , NIR , SWIR, fill):
        mlswi_lower = numpy.where (NIR == fill, fill , add (NIR , SWIR))
        mlswi_upper = numpy.where (NIR == fill, fill ,subtract (NIR , SWIR))
        #Mask = Numpy.Greater (Ndvi_lower, 0)
        mlswi_lower = numpy.where (mlswi_lower == 0 , fill , mlswi_lower)
        lower = (1-mlswi_lower)
        lower = numpy.where (lower == 0 , fill , lower)
        mlswi = numpy.where (mlswi_lower == fill , fill , (1-mlswi_upper)/lower)
        #mlswi1= numpy.where (((mlswi>= 0.75) & (mlswi <= 1.0)), 1, 0)
        #MLSWI = numpy.where (NIR == fill , fill , mlswi1 )

        return mlswi
Esempio n. 6
0

fill = -999
def Flood():
    for y in xrange(2000, 2015):
        lists = [[path + "A%d%03d.flood.tif" % (y, m) for m in xrange(001, 362, 8)]]
        array = np.array(lists)
        images = array.reshape(array.shape[0] * array.shape[1])
        n = 0
        array = []
        for j in images:
            if os.path.exists(j) is True:
                image = GImage(j)
                flood = image.Band2Array(1)
                if n ==0 :
                    flood = np.where(flood == fill, 0 , flood)
                    for k in xrange(len(flood)):
                        array.append(flood[k])
                else:
                    array = np.where(flood == fill, add(array,0) , add(array, flood))
                n += 1
        print n
        #tif_opath1= tifpath+str(y)+".totalevi.tif"
        #image.WriteArrayAsImage(tif_opath1, array)
        array = array*8
        tif_opath= path+str(y)+".flood.tif"
        image.WriteArrayAsImage(tif_opath, array)
        print y
Flood()

Esempio n. 7
0
def _var(a,
         axis=None,
         dtype=None,
         out=None,
         ddof=0,
         keepdims=False,
         *,
         where=True):
    arr = asanyarray(a)

    rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where)
    # Make this warning show up on top.
    if ddof >= rcount if where is True else umr_any(ddof >= rcount, axis=None):
        warnings.warn("Degrees of freedom <= 0 for slice",
                      RuntimeWarning,
                      stacklevel=2)

    # Cast bool, unsigned int, and int to float64 by default
    if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
        dtype = mu.dtype("f8")

    # Compute the mean.
    # Note that if dtype is not of inexact type then arraymean will
    # not be either.
    arrmean = umr_sum(arr, axis, dtype, keepdims=True, where=where)
    # The shape of rcount has to match arrmean to not change the shape of out
    # in broadcasting. Otherwise, it cannot be stored back to arrmean.
    if rcount.ndim == 0:
        # fast-path for default case when where is True
        div = rcount
    else:
        # matching rcount to arrmean when where is specified as array
        div = rcount.reshape(arrmean.shape)
    if isinstance(arrmean, mu.ndarray):
        arrmean = um.true_divide(arrmean,
                                 div,
                                 out=arrmean,
                                 casting="unsafe",
                                 subok=False)
    else:
        arrmean = arrmean.dtype.type(arrmean / rcount)

    # Compute sum of squared deviations from mean
    # Note that x may not be inexact and that we need it to be an array,
    # not a scalar.
    x = asanyarray(arr - arrmean)

    if issubclass(arr.dtype.type, (nt.floating, nt.integer)):
        x = um.multiply(x, x, out=x)
    # Fast-paths for built-in complex types
    elif x.dtype in _complex_to_float:
        xv = x.view(dtype=(_complex_to_float[x.dtype], (2, )))
        um.multiply(xv, xv, out=xv)
        x = um.add(xv[..., 0], xv[..., 1], out=x.real).real
    # Most general case; includes handling object arrays containing imaginary
    # numbers and complex types with non-native byteorder
    else:
        x = um.multiply(x, um.conjugate(x), out=x).real

    ret = umr_sum(x, axis, dtype, out, keepdims=keepdims, where=where)

    # Compute degrees of freedom and make sure it is not negative.
    rcount = um.maximum(rcount - ddof, 0)

    # divide by degrees of freedom
    if isinstance(ret, mu.ndarray):
        ret = um.true_divide(ret,
                             rcount,
                             out=ret,
                             casting="unsafe",
                             subok=False)
    elif hasattr(ret, "dtype"):
        ret = ret.dtype.type(ret / rcount)
    else:
        ret = ret / rcount

    return ret
Esempio n. 8
0

fill = -999
def EVI():
    for y in xrange(2000, 2011):
        lists = [[tifpath + "A%d%03d.US.evi.tif" % (y, m) for m in xrange(001, 362, 8)]]
        array = np.array(lists)
        images = array.reshape(array.shape[0] * array.shape[1])
        n = 0
        array = []
        for j in images:
            if os.path.exists(j) is True:
                image = GImage(j)
                EVI = image.Band2Array(1)
                if n ==0 :
                    EVI = np.where(EVI == fill, 0 , EVI)
                    for k in xrange(len(EVI)):
                        array.append(EVI[k])
                else:
                    array = np.where(EVI == fill, add(array,0) , add(array, EVI))
                n += 1
        print n
        #tif_opath1= tifpath+str(y)+".totalevi.tif"
        #image.WriteArrayAsImage(tif_opath1, array)
        array = array/n
        tif_opath= tifpath+str(y)+".US.evi.tif"
        image.WriteArrayAsImage(tif_opath, array)
        print y
EVI()

Esempio n. 9
0
def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    arr = asanyarray(a)

    rcount = _count_reduce_items(arr, axis)
    # Make this warning show up on top.
    if ddof >= rcount:
        warnings.warn("Degrees of freedom <= 0 for slice",
                      RuntimeWarning,
                      stacklevel=2)

    # Cast bool, unsigned int, and int to float64 by default
    if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
        dtype = mu.dtype('f8')

    # Compute the mean.
    # Note that if dtype is not of inexact type then arraymean will
    # not be either.
    arrmean = umr_sum(arr, axis, dtype, keepdims=True)
    if isinstance(arrmean, mu.ndarray):
        arrmean = um.true_divide(arrmean,
                                 rcount,
                                 out=arrmean,
                                 casting='unsafe',
                                 subok=False)
    else:
        arrmean = arrmean.dtype.type(arrmean / rcount)

    # Compute sum of squared deviations from mean
    # Note that x may not be inexact and that we need it to be an array,
    # not a scalar.
    x = asanyarray(arr - arrmean)

    if issubclass(arr.dtype.type, (nt.floating, nt.integer)):
        x = um.multiply(x, x, out=x)
    # Fast-paths for built-in complex types
    elif x.dtype in _complex_to_float:
        xv = x.view(dtype=(_complex_to_float[x.dtype], (2, )))
        um.multiply(xv, xv, out=xv)
        x = um.add(xv[..., 0], xv[..., 1], out=x.real).real
    # Most general case; includes handling object arrays containing imaginary
    # numbers and complex types with non-native byteorder
    else:
        x = um.multiply(x, um.conjugate(x), out=x).real

    ret = umr_sum(x, axis, dtype, out, keepdims)

    # Compute degrees of freedom and make sure it is not negative.
    rcount = max([rcount - ddof, 0])

    # divide by degrees of freedom
    if isinstance(ret, mu.ndarray):
        ret = um.true_divide(ret,
                             rcount,
                             out=ret,
                             casting='unsafe',
                             subok=False)
    elif hasattr(ret, 'dtype'):
        ret = ret.dtype.type(ret / rcount)
    else:
        ret = ret / rcount

    return ret
Esempio n. 10
0
File: image.py Progetto: Fazi99/Lab
 def CalcNDVI(self, NIR, Red):
     ndvi_lower = add(NIR, Red)
     ndvi_upper = subtract(NIR, Red)
     NDVI = numpy.where(ndvi_lower == 0, 0.0, ndvi_upper/ndvi_lower)
     return NDVI