Esempio n. 1
0
def sample_pixel_area_raster(pxlist, rasterpath, dtype, maj):
    pxvals = []
    for i in range(len(pxlist)):
        tmp = extr_TS.extr_raster_pixel_values(rasterpath, 1, pxlist[i][1], pxlist[i][0], dtype)
        pxvals.append(tmp)
    pxvals = np.array(pxvals, dtype=np.float32)
    if maj == True: out_maj = np.argmax(np.bincount(np.array(pxvals,dtype=np.int)))
    pxvals[pxvals == -9999] = np.nan
    pxvals[pxvals == 32767] = np.nan
    out_pxval = np.nanmean(pxvals)
    if out_pxval == np.nan: out_pxval = -9999
    if maj == True:
        return((out_pxval, out_maj))
    else:
        return(out_pxval)
Esempio n. 2
0
def sample_pixel_area_raster(pxlist, rasterpath, dtype, maj):
    pxvals = []
    for i in range(len(pxlist)):
        tmp = extr_TS.extr_raster_pixel_values(rasterpath, 1, pxlist[i][1],
                                               pxlist[i][0], dtype)
        pxvals.append(tmp)
    pxvals = np.array(pxvals, dtype=np.float32)
    if maj == True:
        out_maj = np.argmax(np.bincount(np.array(pxvals, dtype=np.int)))
    pxvals[pxvals == -9999] = np.nan
    pxvals[pxvals == 32767] = np.nan
    out_pxval = np.nanmean(pxvals)
    if out_pxval == np.nan: out_pxval = -9999
    if maj == True:
        return ((out_pxval, out_maj))
    else:
        return (out_pxval)
Esempio n. 3
0
def sample_pixel_area_sig0(lon, lat, pxsize, landcover, asapath, outpath):
    #this function calculates an average sig0 over a certain area by sampling it with 5 random points
    pxlist = []
    #pxlist.append([lon,lat])
    random.seed()
    goodlc = np.array([10,12,13,15,16,17,18,19,20,21,26,27,28,29])

    meanSIG0 = []
    SIG0list = []
    SIG0Nlist = []
    LIAlist = []
    DAYlist = []

    while len(pxlist) <= 10:
        if len(pxlist) == 0:
            rlon = lon
            rlat = lat
        else:
            rlon = random.uniform(lon-(pxsize/3),lon+(pxsize/3))
            rlat = random.uniform(lat-(pxsize/3),lat+(pxsize/3))

        lc = extr_TS.extr_raster_pixel_values(landcover, 1, rlat, rlon, 1)
        if np.any(goodlc == lc):
            tmp = extr_TS.extr_SIG0_LIA_ts(asapath, 'ASAWS', 'SGRT21A01', 'resampled', 75, rlon, rlat)
            tmpSIG0 = tmp[1]
            tmpLIA=tmp[2]
            #normalise SIG0 to a constant incidence angle of 30deg
            mask = np.array((tmpLIA > 2000) & (tmpLIA < 6000) & (tmpSIG0 != -9999)).squeeze()
            slope = stats.linregress(tmpLIA[mask], tmpSIG0[mask])[0]
            # print(slope)
            tmpSIG0norm = tmpSIG0 - (slope*(tmpLIA-3000))
            tmpSIG0norm[np.logical_not(mask)] = -9999
            SIG0list.append(tmp[1])
            SIG0Nlist.append(tmpSIG0norm)
            LIAlist.append(tmp[2])
            DAYlist.append(tmp[0])
            meanSIG0.append(10*math.log10(np.power(10,(np.array(tmpSIG0norm[mask])/10)).mean()))

            pxlist.append([rlon,rlat])

    #find minimum and maximum day
    minDay = min([x for xs in DAYlist for x in xs])
    maxDay = max([x for xs in DAYlist for x in xs])
    ndays = int(maxDay) - int(minDay)
    ndays = ndays + 1

    # create arrays for SIG0 and LIA
    DAYseq = range(int(minDay), int(maxDay)+1)
    SIG0arr = np.zeros((ndays, len(pxlist)+1), dtype=np.float)
    SIG0arr[:,1:] = -9999
    SIG0Narr = np.zeros((ndays, len(pxlist)+1), dtype=np.float)
    SIG0Narr[:,1:] = -9999
    LIAarr = np.zeros((ndays, len(pxlist)+1), dtype=np.float)
    LIAarr[:,1:] = -9999

    for i in range(ndays):
        SIG0arr[i,0] = DAYseq[i]
        SIG0Narr[i,0] = DAYseq[i]
        LIAarr[i,0] = DAYseq[i]

    # fill SIG0 and LIA into array
    for i in range(len(pxlist)):
        for j in range(len(SIG0list[i])):
            SIG0arr[SIG0arr[:,0] == DAYlist[i][j], i+1] = SIG0list[i][j]
            SIG0Narr[SIG0Narr[:,0] == DAYlist[i][j], i+1] = SIG0Nlist[i][j]
            LIAarr[LIAarr[:,0] == DAYlist[i][j], i+1] = LIAlist[i][j]

    # create array with averages
    outSIG0arr = np.zeros((ndays,2))
    outSIG0Narr = np.zeros((ndays,2))
    outLIAarr = np.zeros((ndays,2))

    for i in range(ndays):
        outSIG0arr[i,0] = DAYseq[i]
        outSIG0Narr[i,0] = DAYseq[i]
        outLIAarr[i,0] = DAYseq[i]

    SIG0arr[SIG0arr == -9999] = np.nan
    SIG0Narr[SIG0Narr == -9999] = np.nan
    LIAarr[LIAarr == -9999] = np.nan
    outSIG0arr[:,1] = 10*np.log10(np.nanmean(np.power(10,SIG0arr[:,1:]/10), axis=1))
    outSIG0Narr[:,1] = 10*np.log10(np.nanmean(np.power(10,SIG0Narr[:,1:]/10), axis=1))
    outLIAarr[:,1] = np.nanmean(LIAarr[:,1:], axis=1)
    outSIG0arr[np.isfinite(outSIG0arr) == False] = -9999
    outSIG0Narr[np.isfinite(outSIG0Narr) == False] = -9999
    outLIAarr[np.isfinite(outLIAarr) == False] = -9999

    return (outSIG0arr.astype(np.int), outSIG0Narr.astype(np.int), outLIAarr.astype(np.int), pxlist, np.nanmean(meanSIG0))
Esempio n. 4
0
def sample_pixel_area_sig0(lon, lat, pxsize, landcover, asapath, outpath):
    #this function calculates an average sig0 over a certain area by sampling it with 5 random points
    pxlist = []
    #pxlist.append([lon,lat])
    random.seed()
    goodlc = np.array([10, 12, 13, 15, 16, 17, 18, 19, 20, 21, 26, 27, 28, 29])

    meanSIG0 = []
    SIG0list = []
    SIG0Nlist = []
    LIAlist = []
    DAYlist = []

    while len(pxlist) <= 10:
        if len(pxlist) == 0:
            rlon = lon
            rlat = lat
        else:
            rlon = random.uniform(lon - (pxsize / 3), lon + (pxsize / 3))
            rlat = random.uniform(lat - (pxsize / 3), lat + (pxsize / 3))

        lc = extr_TS.extr_raster_pixel_values(landcover, 1, rlat, rlon, 1)
        if np.any(goodlc == lc):
            tmp = extr_TS.extr_SIG0_LIA_ts(asapath, 'ASAWS', 'SGRT21A01',
                                           'resampled', 75, rlon, rlat)
            tmpSIG0 = tmp[1]
            tmpLIA = tmp[2]
            #normalise SIG0 to a constant incidence angle of 30deg
            mask = np.array((tmpLIA > 2000) & (tmpLIA < 6000)
                            & (tmpSIG0 != -9999)).squeeze()
            slope = stats.linregress(tmpLIA[mask], tmpSIG0[mask])[0]
            # print(slope)
            tmpSIG0norm = tmpSIG0 - (slope * (tmpLIA - 3000))
            tmpSIG0norm[np.logical_not(mask)] = -9999
            SIG0list.append(tmp[1])
            SIG0Nlist.append(tmpSIG0norm)
            LIAlist.append(tmp[2])
            DAYlist.append(tmp[0])
            meanSIG0.append(10 * math.log10(
                np.power(10, (np.array(tmpSIG0norm[mask]) / 10)).mean()))

            pxlist.append([rlon, rlat])

    #find minimum and maximum day
    minDay = min([x for xs in DAYlist for x in xs])
    maxDay = max([x for xs in DAYlist for x in xs])
    ndays = int(maxDay) - int(minDay)
    ndays = ndays + 1

    # create arrays for SIG0 and LIA
    DAYseq = range(int(minDay), int(maxDay) + 1)
    SIG0arr = np.zeros((ndays, len(pxlist) + 1), dtype=np.float)
    SIG0arr[:, 1:] = -9999
    SIG0Narr = np.zeros((ndays, len(pxlist) + 1), dtype=np.float)
    SIG0Narr[:, 1:] = -9999
    LIAarr = np.zeros((ndays, len(pxlist) + 1), dtype=np.float)
    LIAarr[:, 1:] = -9999

    for i in range(ndays):
        SIG0arr[i, 0] = DAYseq[i]
        SIG0Narr[i, 0] = DAYseq[i]
        LIAarr[i, 0] = DAYseq[i]

    # fill SIG0 and LIA into array
    for i in range(len(pxlist)):
        for j in range(len(SIG0list[i])):
            SIG0arr[SIG0arr[:, 0] == DAYlist[i][j], i + 1] = SIG0list[i][j]
            SIG0Narr[SIG0Narr[:, 0] == DAYlist[i][j], i + 1] = SIG0Nlist[i][j]
            LIAarr[LIAarr[:, 0] == DAYlist[i][j], i + 1] = LIAlist[i][j]

    # create array with averages
    outSIG0arr = np.zeros((ndays, 2))
    outSIG0Narr = np.zeros((ndays, 2))
    outLIAarr = np.zeros((ndays, 2))

    for i in range(ndays):
        outSIG0arr[i, 0] = DAYseq[i]
        outSIG0Narr[i, 0] = DAYseq[i]
        outLIAarr[i, 0] = DAYseq[i]

    SIG0arr[SIG0arr == -9999] = np.nan
    SIG0Narr[SIG0Narr == -9999] = np.nan
    LIAarr[LIAarr == -9999] = np.nan
    outSIG0arr[:, 1] = 10 * np.log10(
        np.nanmean(np.power(10, SIG0arr[:, 1:] / 10), axis=1))
    outSIG0Narr[:, 1] = 10 * np.log10(
        np.nanmean(np.power(10, SIG0Narr[:, 1:] / 10), axis=1))
    outLIAarr[:, 1] = np.nanmean(LIAarr[:, 1:], axis=1)
    outSIG0arr[np.isfinite(outSIG0arr) == False] = -9999
    outSIG0Narr[np.isfinite(outSIG0Narr) == False] = -9999
    outLIAarr[np.isfinite(outLIAarr) == False] = -9999

    return (outSIG0arr.astype(np.int), outSIG0Narr.astype(np.int),
            outLIAarr.astype(np.int), pxlist, np.nanmean(meanSIG0))