#fig = plt.figure(3)
    #fig3 = fig.add_subplot(111)
    #fig3.set_title('SM SMAP')
    #fig3.imshow(bandSM, cmap=cm.gray, interpolation='none')
    #

    ### a la imagen SM de SMAP se le cambia la resolucion mediante el match
    ### se puede interpolar segun los metodos Nearest, Bilinear o Cubic

    nRow, nCol = bandGPM.shape

    type = "Nearest"
    #type = "Bilinear"
    data_src = src_ds_SM
    data_match = src_ds_GPM
    match = functions.matchData(data_src, data_match, type, nRow, nCol)
    band_match = match.ReadAsArray()
    #print band_match.shape
    ### band_match = bandSM

    #print "Tamanio band match: "+str(band_match.shape)

    #fig = plt.figure(10)
    #fig10 = fig.add_subplot(111)
    #fig10.set_title('SM SMAP matched with GPM')
    #fig10.imshow(band_match, cmap=cm.gray,interpolation='none')

    nComp = 5

    ### se aplica PCA a la imagen con resolucion fina
    pcaGPM = PCA(nComp)
示例#2
0
def calculateETMaps():

    dir = "..."
    path = "/.../"+dir+"/.../"

    fechas= []
    fechas.append("2016_05_15")
    fechas.append("2016_05_07")
    fechas.append("2016_06_16")
    fechas.append("2016_07_10")

    pathOut = "/.../"+dir+"/.../CreatedMaps/"
    Ta = []
    HR = []
    PP = []
    sigma0 = []

    for i in range(0,len(fechas)):
    #for i in range(0,1):
        print(fechas[i])


        ### ET modis
        fileETModis = "/media/"+dir+"/TOURO Mobile/ET/"+fechas[i]+"/MYD16A2/MYD16A2_reprojected.data/ET_500m.img"        
        src_ds_ETModis, bandETModis, GeoTETModis, ProjectETModis = functions.openFileHDF(fileETModis, 1)
        
        ### SMAP resolucion 36km
        fileSM = "/media/"+dir+"/TOURO Mobile/ET/SM_36km/"+fechas[i]+"/SM.dat" 
        src_ds_SM, bandSM, GeoTSM, ProjectSM = functions.openFileHDF(fileSM, 1)
        print("tamanio SM SMAP:" + str(bandSM.shape))

        ### observed variables
        fileRn = "/media/"+dir+"/TOURO Mobile/ET/"+fechas[i]+"/RN/mapa_RN.asc"
        src_ds_Rn, bandRn, GeoTRn, ProjectRn = functions.openFileHDF(fileRn, 1)
        

        fileG = "/media/"+dir+"/TOURO Mobile/ET/"+fechas[i]+"/G/mapa_G.asc"
        src_ds_G, bandG, GeoTG, ProjectG = functions.openFileHDF(fileG, 1)        
        
        fileDelta = "/media/"+dir+"/TOURO Mobile/ET/"+fechas[i]+"/Delta/mapa_delta.asc"
        src_ds_Delta, bandDelta, GeoTDelta, ProjectDelta = functions.openFileHDF(fileDelta, 1)

        #### real ET observed
        fileETObs = "/media/"+dir+"/TOURO Mobile/ET/"+fechas[i]+"/ETobs/mapa_ETobs.asc"
        src_ds_ETObs, bandETObs, GeoTETObs, ProjectETObs = functions.openFileHDF(fileDelta, 1)

        nameFileET = "mapa_ET_"+str(fechas[i])

        ### se cambian las resoluciones de todas las imagenes a la de la sar
        type = "Nearest"
#        type = "Bilinear"
        nRow, nCol = bandSM.shape


#        fig, ax = plt.subplots()
#        ax.imshow(bandSM, interpolation='None',cmap=cm.gray)


        data_src = src_ds_ETObs
        data_match = src_ds_SM
        match = functions.matchData(data_src, data_match, type, nRow, nCol)
        band_matchETObs = match.ReadAsArray()
#        fig, ax = plt.subplots()
#        ax.imshow(bandETObs*1000, interpolation='None',cmap=cm.gray)

       data_src = src_ds_ETModis
       data_match = src_ds_SM
       match = functions.matchData(data_src, data_match, type, nRow, nCol)
       band_matchET = match.ReadAsArray()
#        fig, ax = plt.subplots()
#        ax.imshow(band_matchET, interpolation='None',cmap=cm.gray)


        data_src = src_ds_Rn
        data_match = src_ds_SM
        match = functions.matchData(data_src, data_match, type, nRow, nCol)
        band_matchRn = match.ReadAsArray()
#        fig, ax = plt.subplots()
#        ax.imshow(band_matchRn, interpolation='None',cmap=cm.gray)

        data_src = src_ds_G
        data_match = src_ds_SM
        match = functions.matchData(data_src, data_match, type, nRow, nCol)
        band_matchG = match.ReadAsArray()
#        fig, ax = plt.subplots()
#        ax.imshow(band_matchG, interpolation='None',cmap=cm.gray)

        data_src = src_ds_Delta
        data_match = src_ds_SM
        match = functions.matchData(data_src, data_match, type, nRow, nCol)
        band_matchDelta = match.ReadAsArray()
#        fig, ax = plt.subplots()
#        ax.imshow(band_matchDelta, interpolation='None',cmap=cm.gray)


        ################################################################################
        ######## here goes the equation to calculate the ET       
        ################################################################################

#        fig, ax = plt.subplots()
#        ax.imshow(mapET, interpolation='None',cmap=cm.gray)
#        plt.show()


        ##my_cmap = cm.Blues
        ##my_cmap.set_under('k', alpha=0)
        ##my_cmap1 = cm.Greens
        ##my_cmap1.set_under('k', alpha=0)
        ##my_cmap2 = cm.OrRd
        ##my_cmap2.set_under('k', alpha=0)
        #my_cmap3 = cm.Oranges
        my_cmap3 = cm.terrain
        my_cmap3.set_under('k', alpha=0)

        transform = GeoTSM
        xmin,xmax,ymin,ymax=transform[0],transform[0]+transform[1]*src_ds_SM.RasterXSize,transform[3]+transform[5]*src_ds_SM.RasterYSize,transform[3]
        #print xmin
        #print xmax

        path = "/.../ET_modelado_36km/"
        nameFileET = "ET_modelado_"+str(fechas[i])
        ### mapas ET modelados
        fig, ax = plt.subplots()
        mapET = (mapET-np.min(mapET)) /(np.max(mapET)-np.min(mapET))
        ### guarda mapa        
        functions.createHDFfile(path, nameFileET, 'ENVI', mapET, nCol, nRow, GeoTSM, ProjectSM)        

        
        im1 = ax.imshow(mapET, interpolation='none', cmap=plt.get_cmap('gray'), extent=[xmin,xmax,ymin,ymax], clim=(0, 1))
        ax.xaxis.tick_top()
        divider = make_axes_locatable(ax)
        cax = divider.append_axes('bottom', size="5%", pad=0.05)
        cb = plt.colorbar(im1, cax=cax, orientation="horizontal")
        cb.set_label('Evapotranspiration (W/m^2)')
        print ("ET modelado:")
        print ("Max:" + str(np.max(mapET)))
        print ("Min:" + str(np.min(mapET)))
        print ("Std:" + str(np.std(mapET)))                
               
        ### mapas ET observado interpolado
        fig, ax = plt.subplots()
        band_matchETObs = band_matchETObs*1000
        band_matchETObs = (band_matchETObs- np.min(band_matchETObs)) /(np.max(band_matchETObs)-np.min(band_matchETObs))
        im0 = ax.imshow(band_matchETObs, cmap=plt.get_cmap('gray'), extent=[xmin,xmax,ymin,ymax], interpolation='none', clim=(0, 1))
        ax.xaxis.tick_top()
        divider = make_axes_locatable(ax)
        cax = divider.append_axes('bottom', size="5%", pad=0.05)
        cb = plt.colorbar(im0, cax=cax, orientation="horizontal")
        cb.set_label('Evapotranspiration (W/m^2)')
        #cb.set_clim(vmin=5, vmax=50)

        print ("ET observado:")
        print ("Max:" + str(np.max(band_matchETObs)))
        print ("Min:" + str(np.min(band_matchETObs)))
        print ("Std:" + str(np.std(band_matchETObs)))

        print("Error entre ET modelado y observado")

        mse_noise= mean_squared_error(y_true = band_matchETObs , y_pred = mapET)
        mse_noise = np.sqrt(mse_noise)
        #mse_noise= compare_mse(bandET_modis, bandET_modeled)        
        ssim_noise = ssim(band_matchETObs.flatten(), mapET.flatten())
        
        print("SSIM:" +str(ssim_noise))
        print("RMSE:" + str(mse_noise))


        fig, ax = plt.subplots()
        errorModelado = np.sqrt((mapET - band_matchETObs)**2)
        im0 = ax.imshow(errorModelado, cmap=plt.cm.jet, extent=[xmin,xmax,ymin,ymax], interpolation='none', clim=(0, 1))
        ax.xaxis.tick_top()
        divider = make_axes_locatable(ax)
        cax = divider.append_axes('bottom', size="5%", pad=0.05)
        cb = plt.colorbar(im0, cax=cax, orientation="horizontal")
        cb.set_label('Error')
        #cb.set_clim(vmin=5, vmax=50)
        plt.show()
示例#3
0
path = "/.../MODIS/2015-06-26/"
nameFile = "NDVI_reprojectado_recortado"
src_ds_Modis, bandModis, GeoTModis, Project = functions.openFileHDF2(
    path, nameFile, 1)
print bandModis.shape

#fig = plt.figure(10)
#fig1 = fig.add_subplot(111)
#fig1.imshow(bandModis[:512,:512], cmap=cm.gray)

### a la imagen modis se le cambia la resolucion mediante el match
### se puede interpolar segun los metodos Nearest, Bilinear o Cubic

data_src = src_ds_Modis
data_match = src_ds_L8
match = functions.matchData(data_src, data_match, "Bilinear")
#match = functions.matchData(data_src, data_match, "Nearest")
#match = functions.matchData(data_src, data_match, "Cubic")
band_match = match.ReadAsArray()
#modis = band_match

#bandL8 = bandL8[:2048,:2048]
#modis = band_match[:2048,:2048]

bandL8 = bandL8[:512, :512]
modis = band_match[:512, :512]

X = bandL8
mu = np.mean(X, axis=0)

nComp = 200
示例#4
0
def calculateMaps(MLRmodel, MARSmodel, MLPmodel, etapa):
    print(
        "-------------------------------------------------------------------")
    print("Calculate SM maps")
    #def calculateMaps(MLRmodel, MLPmodel, etapa):
    #dir = "ggarcia"
    dir = "gag"

    fechaSentinel = []
    fechaNDVI = []
    fechaLandsat8 = []
    fechaSMAP = []
    fechaMYD = []

    if (etapa == "etapa1"):
        path = "/media/" + dir + "/Datos/Trabajos/Trabajo_Sentinel_NDVI_CONAE/Modelo/mapasCreados/Etapa1/"
        print(etapa)
        fechaSentinel.append("2015-06-29")
        fechaLandsat8.append("2015-06-18")
        fechaSMAP.append("2015-06-30")
        fechaSentinel.append("2015-10-03")
        fechaLandsat8.append("2015-10-08")
        fechaSMAP.append("2015-10-04")
        fechaSentinel.append("2015-12-28")
        fechaLandsat8.append("2015-12-27")
        fechaSMAP.append("2015-12-28")
        fechaSentinel.append("2016-03-19")
        fechaLandsat8.append("2016-03-16")
        fechaSMAP.append("2016-03-12")

        Ta = []
        HR = []
        PP = []
        sigma0 = []

        for i in range(0, len(fechaSentinel)):

            print(
                "-----------------------------------------------------------")
            print(fechaSentinel[i])
            print(
                "-----------------------------------------------------------")

            fileTa = "/media/" + dir + "/Datos/Trabajos/Trabajo_Sentinel_NDVI_CONAE/Datos INTA/" + fechaSentinel[
                i] + "/T_aire.asc"
            src_ds_Ta, bandTa, GeoTTa, ProjectTa = functions.openFileHDF(
                fileTa, 1)

            filePP = "/media/" + dir + "/Datos/Trabajos/Trabajo_Sentinel_NDVI_CONAE/Datos INTA/" + fechaSentinel[
                i] + "/PP.asc"
            src_ds_PP, bandPP, GeoTPP, ProjectPP = functions.openFileHDF(
                filePP, 1)

            fileHR = "/media/" + dir + "/Datos/Trabajos/Trabajo_Sentinel_NDVI_CONAE/Datos INTA/" + fechaSentinel[
                i] + "/HR.asc"
            src_ds_HR, bandHR, GeoTHR, ProjectHR = functions.openFileHDF(
                fileHR, 1)

            fileNDVI = "/media/" + dir + "/Datos/Trabajos/Trabajo_Sentinel_NDVI_CONAE/Landsat8/" + fechaLandsat8[
                i] + "/NDVI_recortado"
            src_ds_NDVI, bandNDVI, GeoTNDVI, ProjectNDVI = functions.openFileHDF(
                fileNDVI, 1)

            #            ##### smap a 10 km
            #            fileSMAP = "/media/"+dir+"/TOURO Mobile/Trabajo_Sentinel_NDVI_CONAE/SMAP/SMAP-10km/"+fechaSMAP[i]+"/soil_moisture.img"
            #            print(fileSMAP)
            #            src_ds_SMAP, bandSMAP, GeoTSMAP, ProjectSMAP = functions.openFileHDF(fileSMAP, 1)

            ##### CONAE interpolado
            #            CONAE_HS = "/home/gag/Escritorio/inter_HS_29_06_2015.asc"
            #            src_ds_CONAE_HS, bandCONAE_HS, GeoTCONAE_HS, ProjectCONAE_HS = functions.openFileHDF(CONAE_HS, 1)

            #fileSar ="/media/"+dir+"/TOURO Mobile/Trabajo_Sentinel_NDVI_CONAE/Sentinel/"+fechaSentinel[i]+".SAFE/subset.data/recorte_30mx30m.img"
            #fileSar ="/media/"+dir+"/TOURO Mobile/Trabajo_Sentinel_NDVI_CONAE/Sentinel-Otras/"+fechaSentinel[i]+".SAFE/subset.data/recorte_30mx30m.img"
            fileSar = "/media/" + dir + "/TOURO Mobile/Sentinel_30m_1km/" + fechaSentinel[
                i] + "/subset_30m_mapa.data/Sigma0_VV_db.img"

            nameFileMLR = "mapa_MLR_30m_" + str(fechaSentinel[i])
            nameFileMARS = "mapa_MARS_30m_" + str(fechaSentinel[i])
            nameFileMLP = "mapa_MLP_30m_" + str(fechaSentinel[i])

            src_ds_Sar, bandSar, GeoTSar, ProjectSar = functions.openFileHDF(
                fileSar, 1)
            print(ProjectSar)

            fileMascara = "/media/" + dir + "/Datos/Trabajos/Trabajo_Sentinel_NDVI_CONAE/Landsat8/2015-06-18/mascaraciudadyalgomas_reprojected/subset_1_of_Band_Math__b1_5.data/Band_Math__b1_5.img"
            src_ds_Mas, bandMas, GeoTMas, ProjectMas = functions.openFileHDF(
                fileMascara, 1)

            ### se cambian las resoluciones de todas las imagenes a la de la sar
            #type = "Nearest"
            type = "Bilinear"
            nRow, nCol = bandSar.shape

            data_src = src_ds_Mas
            data_match = src_ds_Sar
            match = functions.matchData(data_src, data_match, type, nRow, nCol)
            band_matchCity = match.ReadAsArray()

            data_src = src_ds_Ta
            data_match = src_ds_Sar
            match = functions.matchData(data_src, data_match, type, nRow, nCol)
            band_matchTa = match.ReadAsArray()

            print(
                "------------------------------------------------------------")
            print("Max Ta: " + str(np.max(band_matchTa)))
            print("Min Ta: " + str(np.min(band_matchTa)))

            #fig, ax = plt.subplots()
            #ax.imshow(band_matchTa, interpolation='None',cmap=cm.gray)
            #plt.show()

            data_src = src_ds_PP
            data_match = src_ds_Sar
            match = functions.matchData(data_src, data_match, type, nRow, nCol)
            band_matchPP = match.ReadAsArray()

            print("Max PP: " + str(np.max(band_matchPP)))
            print("Min PP: " + str(np.min(band_matchPP)))

            #fig, ax = plt.subplots()
            #ax.imshow(band_matchPP, interpolation='None',cmap=cm.gray)
            #plt.show()

            data_src = src_ds_HR
            data_match = src_ds_Sar
            match = functions.matchData(data_src, data_match, type, nRow, nCol)
            band_matchHR = match.ReadAsArray()

            print("Max HR: " + str(np.max(band_matchHR)))
            print("Min HR: " + str(np.min(band_matchHR)))

            #HR = pd.DataFrame({'HR':band_matchHR.flatten()})
            #fig, ax = plt.subplots()
            #sns.distplot(HR)

            #print "------------------------------------------------------------"
            #fig, ax = plt.subplots()
            #ax.imshow(band_matchHR, interpolation='None',cmap=cm.gray)

            data_src = src_ds_NDVI
            data_match = src_ds_Sar
            match = functions.matchData(data_src, data_match, type, nRow, nCol)
            band_matchNDVI = match.ReadAsArray()

            #            fig, ax = plt.subplots()
            #            ax.imshow(band_matchNDVI, interpolation='None',cmap=cm.gray)
            #            plt.show()
            #

            type = "Nearest"
            #            data_src = src_ds_SMAP
            #            data_match = src_ds_Sar
            #            match = functions.matchData(data_src, data_match, type, nRow, nCol)
            #            band_matchSMAP = match.ReadAsArray()

            #            data_src = src_ds_CONAE_HS
            #            data_match = src_ds_Sar
            #            match = functions.matchData(data_src, data_match, type, nRow, nCol)
            #            band_matchCONAE_HS = match.ReadAsArray()

            ### se filtra la imagen SAR
            #print "Se filtran las zonas con NDVI mayores a 0.51 y con NDVI menores a 0"
            sarEnmask, maskNDVI = applyNDVIfilter(bandSar, band_matchNDVI,
                                                  etapa)

            #            rSar, cSar = maskNDVI.shape
            #            maskNDVI2 = np.zeros((rSar, cSar))
            #            for i in range(0, rSar):
            #                for j in range(0, cSar):
            #                    if (maskNDVI[i, j] == 0 ): maskNDVI2[i,j] = 1

            filtWater, maskWater = applyWaterfilter(bandSar, band_matchNDVI)

            ### histograma de Sigma0 despues de filtrar
            #Ss = pd.DataFrame({'Sigma0':sarEnmask.flatten()})
            #fig, ax = plt.subplots()
            #sns.distplot(Ss)

            #            sarEnmask, maskCity = applyCityfilter(sarEnmask,L8maskCity)
            #            sarEnmask, maskSAR = applyBackfilter(sarEnmask)

            sarEnmask[sarEnmask < -18] = -0
            sarEnmask[sarEnmask > -4] = -4

            print("Max Sigma0: " + str(np.max(sarEnmask)))
            print("Min Sigma0: " + str(np.min(sarEnmask)))
            print(
                "------------------------------------------------------------")

            #            fig, ax = plt.subplots()
            #            ax.imshow(sarEnmask, interpolation='None',cmap=cm.gray)
            #
            #            fig, ax = plt.subplots()
            #            ax.imshow(maskNDVI, interpolation='None',cmap=cm.gray)
            #            plt.show()

            sarEnmask1 = np.copy(sarEnmask)
            sarEnmask2 = np.copy(sarEnmask)
            sarEnmask3 = np.copy(sarEnmask)

            r, c = bandSar.shape

            #            OldRange = (np.max(band_matchPP)  - np.min(band_matchPP))
            #            NewRange = (1 + 1)
            #            newPP = (((band_matchPP - np.min(band_matchPP)) * NewRange) / OldRange) -1
            #
            #            OldRange = (np.max(sarEnmask1)  - np.min(sarEnmask1))
            #            NewRange = (1 + 1)
            #            sarEnmask1 = (((sarEnmask1 - np.min(sarEnmask1)) * NewRange) / OldRange) -1

            ### se normalizan las variables entre 0 y 1
            sarEnmask_22 = normalizadoSAR(sarEnmask1)
            PP_Norm = normalizadoPP(band_matchPP)
            Ta_Norm = normalizadoTa(band_matchTa)
            HR_Norm = normalizadoHR(band_matchHR)

            print("Max sarEnmask_22 norm:" + str(np.max(sarEnmask_22)))
            print("Min sarEnmask_22 norm:" + str(np.min(sarEnmask_22)))

            print("Max PP norm:" + str(np.max(PP_Norm)))
            print("Min PP norm:" + str(np.min(PP_Norm)))

            print("Max Ta norm:" + str(np.max(Ta_Norm)))
            print("Min Ta norm:" + str(np.min(Ta_Norm)))

            print("Max HR norm:" + str(np.max(HR_Norm)))
            print("Min HR norm:" + str(np.min(HR_Norm)))

            #            fig, ax = plt.subplots()
            #            ax.imshow(PP_Norm, interpolation='None',cmap=cm.gray)
            #
            #            fig, ax = plt.subplots()
            #            ax.imshow(np.log10(Ta_Norm), interpolation='None',cmap=cm.gray)
            #
            #
            #            fig, ax = plt.subplots()
            #            ax.imshow(np.log10(HR_Norm), interpolation='None',cmap=cm.gray)

            #### -------------------MLR method-------------------

            dataMap_MLR = pd.DataFrame({
                'Sigma0': sarEnmask_22.flatten(),
                'T_aire': (np.log10(Ta_Norm)).flatten(),
                'HR': (np.log10(HR_Norm)).flatten(),
                'PP': PP_Norm.flatten()
            })
            dataMap_MLR = dataMap_MLR[['T_aire', 'PP', 'Sigma0', 'HR']]
            #            print(dataMap_MLR.describe())
            #            input()
            dataMap_MLR = dataMap_MLR.fillna(0)
            mapSM_MLR = MLRmodel.predict(dataMap_MLR)
            ## debo invertir la funcion flatten()
            #mapSM_MLR = mapSM_MLR.reshape((r,c))
            mapSM_MLR = np.array(mapSM_MLR).reshape(r, c)
            mapSM_MLR = 10**(mapSM_MLR)
            mapSM_MLR[mapSM_MLR < 0] = 0
            #mapSM_MLR[mapSM_MLR > 60] = 0

            #### los datos para el modelo MLR llevan log
            #            fig, ax = plt.subplots()
            #            plt.hist(mapSM_MLR, bins=10)  # arguments are passed to np.histogram
            #            plt.title("Histogram MLR maps")
            #            plt.show()

            mapSM_MLR = mapSM_MLR * maskNDVI  #*maskCity

            #SM = pd.DataFrame({'SM':mapSM_MLR.flatten()})
            #SM = SM[SM.SM != 0]
            #fig, ax = plt.subplots()
            #sns.distplot(SM)

            #fig, ax = plt.subplots()
            #ax.imshow(mapSM_MLR, interpolation='None',cmap=cm.gray)
            #plt.show()

            #plt.hist(mapSM_MLR)  # arguments are passed to np.histogram
            #plt.title("Histogram with 'auto' bins")
            #plt.show()

            print("MLR")
            print("Max:" + str(np.max(mapSM_MLR[np.nonzero(mapSM_MLR)])))
            print("Min:" + str(np.min(mapSM_MLR[np.nonzero(mapSM_MLR)])))
            print("Mean:" + str(np.mean(mapSM_MLR[np.nonzero(mapSM_MLR)])))
            print("STD:" + str(np.std(mapSM_MLR[np.nonzero(mapSM_MLR)])))

            #fig, ax = plt.subplots()
            #ax.imshow(mapSM_MLR, interpolation='None',cmap=cm.gray)

            #### -------------------MARS method-------------------

            dataMap_MARS = pd.DataFrame({
                'Sigma0': sarEnmask.flatten(),
                'T_aire': band_matchTa.flatten(),
                'HR': band_matchHR.flatten(),
                'PP': band_matchPP.flatten()
            })
            dataMap_MARS = dataMap_MARS[['T_aire', 'PP', 'Sigma0', 'HR']]
            dataMap_MARS = dataMap_MARS.fillna(0)
            mapSM_MARS = MARSmodel.predict(dataMap_MARS)
            ## debo invertir la funcion flatten()
            mapSM_MARS = mapSM_MARS.reshape(r, c)
            mapSM_MARS[mapSM_MARS < 0] = 0

            mapSM_MARS = mapSM_MARS * maskNDVI  #*maskCity

            ####------------------- MLP method -------------------

            #            OldRange = (np.max(band_matchTa)  - np.min(band_matchTa))
            #            NewRange = (1 + 1)
            #            Ta = (((band_matchTa - np.min(band_matchTa)) * NewRange) / OldRange) -1
            #
            #            OldRange = (np.max(band_matchHR)  - np.min(band_matchHR))
            #            NewRange = (1 + 1)
            #            HR = (((band_matchHR - np.min(band_matchHR)) * NewRange) / OldRange) -1
            #
            #            OldRange = (np.max(band_matchPP)  - np.min(band_matchPP))
            #            NewRange = (1 + 1)
            #            PP = (((band_matchPP - np.min(band_matchPP)) * NewRange) / OldRange) -1
            #
            #            OldRange = (np.max(sarEnmask)  - np.min(sarEnmask))
            #            NewRange = (1 + 1)
            #            sar2 = (((sarEnmask - np.min(sarEnmask)) * NewRange) / OldRange) -1

            OldRange = (26.29 - 6.9)
            NewRange = (1 + 1)
            Ta = (((band_matchTa - 6.9) * NewRange) / OldRange) - 1

            OldRange = (83.63 - 17.83)
            NewRange = (1 + 1)
            HR = (((band_matchHR - 17.83) * NewRange) / OldRange) - 1

            OldRange = (22.16 - 0)
            NewRange = (1 + 1)
            PP = (((band_matchPP - 0) * NewRange) / OldRange) - 1

            OldRange = (-4.39 + 17.82)
            NewRange = (1 + 1)
            sar2 = (((sarEnmask + 17.82) * NewRange) / OldRange) - 1

            dataMap_MLP = pd.DataFrame({
                'T_aire': Ta.flatten(),
                'Sigma0': sar2.flatten(),
                'HR': HR.flatten(),
                'PP': PP.flatten()
            })
            dataMap_MLP = dataMap_MLP[['T_aire', 'PP', 'Sigma0', 'HR']]

            #print dataMap_MLP
            ###.describe()
            dataMap_MLP = dataMap_MLP.fillna(0)
            mapSM_MLP = MLPmodel.predict(dataMap_MLP)
            mapSM_MLP = mapSM_MLP.reshape(r, c)
            #print mapSM_MLR.shape
            mapSM_MLP[mapSM_MLP < 0] = 0
            mapSM_MLP = mapSM_MLP * maskNDVI
            #fig, ax = plt.subplots()
            #ax.imshow(mapSM_MLP, interpolation='None',cmap=cm.gray)
            #plt.show()

            my_cmap = cm.Blues
            my_cmap.set_under('k', alpha=0)
            my_cmap1 = cm.Greens
            my_cmap1.set_under('k', alpha=0)
            my_cmap2 = cm.OrRd
            my_cmap2.set_under('k', alpha=0)
            my_cmap3 = cm.Oranges
            my_cmap3.set_under('k', alpha=0)

            transform = GeoTSar
            xmin, xmax, ymin, ymax = transform[0], transform[
                0] + transform[1] * src_ds_Sar.RasterXSize, transform[
                    3] + transform[5] * src_ds_Sar.RasterYSize, transform[3]
            print(xmin)
            print(xmax)

            # plot MLR maps
            ##plt.hist(mapSM_MLR, bins=10)  # arguments are passed to np.histogram
            ##plt.title("Histogram with 'auto' bins")
            ##plt.show()

            fig, ax = plt.subplots()
            #            meridians = [xmin, xmax,5]
            m = Basemap(projection='merc',llcrnrlat=ymin,urcrnrlat=ymax,\
            llcrnrlon=xmin,urcrnrlon=xmax,resolution='c')

            #            m = Basemap(projection='cyl',llcrnrlat=ymin,urcrnrlat=ymax,\
            #            llcrnrlon=xmin,urcrnrlon=xmax,resolution='c')

            #            m.drawcoastlines()
            #            lat = np.arange(xmin, xmax, 5)
            #            print lat
            #            m.drawlsmask(land_color='white',ocean_color='white',lakes=True)
            #
            #            m.drawparallels([-32.90,-32.95,-33.00,-33.05],labels=[1,0,0,0],fontsize=12, linewidth=0.0)
            #
            #            m.drawmeridians([-62.56,-62.48,-62.40,-62.32],labels=[0,0,1,0],fontsize=12, linewidth=0.0)

            #            m.drawmapscale(-62.35, -33.04, 0,0, 10, barstyle='fancy', units='km')
            m.drawmapscale(-62.55, -33.05, 0, 0, 10, fontsize=10, units='km')
            #            m.drawmapboundary(fill_color='aqua')
            #            ax.add_compass(loc=1)

            sarEnmask[sarEnmask != -4] = 0
            #            sarEnmask[sarEnmask == -4] = 1
            img = ax.imshow(sarEnmask,
                            extent=[xmin, xmax, ymin, ymax],
                            cmap=cm.gray,
                            interpolation='none')
            ax.yaxis.set_major_locator(plt.MaxNLocator(5))
            ax.xaxis.set_major_locator(plt.MaxNLocator(5))
            ax.xaxis.tick_top()
            #            m.colorbar(img)

            #            plt.title('Plot gridded data on a map')

            plt.savefig('gridded_data_global_map.png',
                        pad_inches=0.5,
                        bbox_inches='tight')
            ax.grid(False)
            plt.show()

            #im0 = ax.imshow(mapSM_MLR, cmap=my_cmap3)#, vmin=5, vmax=55, extent=[xmin,xmax,ymin,ymax], interpolation='None')
            #maskNDVI2 = ma.masked_where(maskNDVI2 == 0,maskNDVI2)
            #im1 = ax.imshow(maskNDVI2, cmap=my_cmap1)

            #            im0 = ax.imshow(maskNDVI, extent=[xmin,xmax,ymin,ymax],cmap=cm.gray)
            #            im0.tick_labels.set_xformat('hhmm')
            #            im0.tick_labels.set_yformat('hhmm')
            #
            plt.show()

            fig, ax = plt.subplots()

            #im0 = ax.imshow(mapSM_MLR, cmap=my_cmap3)#, vmin=5, vmax=55, extent=[xmin,xmax,ymin,ymax], interpolation='None')
            #maskNDVI2 = ma.masked_where(maskNDVI2 == 0,maskNDVI2)
            #im1 = ax.imshow(maskNDVI2, cmap=my_cmap1)

            im0 = ax.imshow(mapSM_MLR,
                            extent=[xmin, xmax, ymin, ymax],
                            cmap=my_cmap1,
                            clim=(5, 45))

            pp = ma.masked_where(band_matchCity == 0, band_matchCity)
            im = ax.imshow(pp,
                           extent=[xmin, xmax, ymin, ymax],
                           cmap=my_cmap2,
                           interpolation='Bilinear')
            kk = ma.masked_where(filtWater == 0, filtWater)
            im = ax.imshow(kk,
                           extent=[xmin, xmax, ymin, ymax],
                           cmap=my_cmap,
                           interpolation='Bilinear')
            ax.grid(False)
            ax.xaxis.tick_top()
            ax.yaxis.set_major_locator(plt.MaxNLocator(4))
            ax.xaxis.set_major_locator(plt.MaxNLocator(4))

            divider = make_axes_locatable(ax)
            cax = divider.append_axes('bottom', size="5%", pad=0.05)
            cb = plt.colorbar(im0, cax=cax, orientation="horizontal")
            cb.set_label('Volumetric SM (%)')
            #cb.set_clim(vmin=5, vmax=50)

            ### ----------------------------------------------------------------

            # plot MARS maps

            print("MARS")
            print("Max:" + str(np.max(mapSM_MARS[np.nonzero(mapSM_MARS)])))
            print("Min:" + str(np.min(mapSM_MARS[np.nonzero(mapSM_MARS)])))
            print("Mean:" + str(np.mean(mapSM_MARS[np.nonzero(mapSM_MARS)])))
            print("STD:" + str(np.std(mapSM_MARS[np.nonzero(mapSM_MARS)])))

            fig, ax = plt.subplots()
            im0 = ax.imshow(mapSM_MARS,
                            extent=[xmin, xmax, ymin, ymax],
                            cmap=my_cmap1,
                            clim=(5, 45))
            pp = ma.masked_where(band_matchCity == 0, band_matchCity)
            im = ax.imshow(pp,
                           extent=[xmin, xmax, ymin, ymax],
                           cmap=my_cmap2,
                           interpolation='Bilinear')
            kk = ma.masked_where(filtWater == 0, filtWater)
            im = ax.imshow(kk,
                           extent=[xmin, xmax, ymin, ymax],
                           cmap=my_cmap,
                           interpolation='Bilinear')
            ax.grid(False)
            ax.xaxis.tick_top()
            ax.yaxis.set_major_locator(plt.MaxNLocator(4))
            ax.xaxis.set_major_locator(plt.MaxNLocator(4))
            divider = make_axes_locatable(ax)
            cax = divider.append_axes('bottom', size="5%", pad=0.05)
            cb = plt.colorbar(im0, cax=cax, orientation="horizontal")
            cb.set_label('Volumetric SM (%)')
            #cb.set_clim(vmin=5, vmax=50)

            ### ----------------------------------------------------------------

            # plot MLP map
            print("MLP")
            print("Max:" + str(np.max(mapSM_MLP[np.nonzero(mapSM_MLP)])))
            print("Min:" + str(np.min(mapSM_MLP[np.nonzero(mapSM_MLP)])))
            print("Mean:" + str(np.mean(mapSM_MLP[np.nonzero(mapSM_MLP)])))
            print("STD:" + str(np.std(mapSM_MLP[np.nonzero(mapSM_MLP)])))

            fig, ax = plt.subplots()
            im0 = ax.imshow(mapSM_MLP,
                            extent=[xmin, xmax, ymin, ymax],
                            cmap=my_cmap1,
                            clim=(5, 45))
            pp = ma.masked_where(band_matchCity == 0, band_matchCity)
            ax.imshow(pp,
                      extent=[xmin, xmax, ymin, ymax],
                      cmap=my_cmap2,
                      interpolation='Bilinear')
            kk = ma.masked_where(filtWater == 0, filtWater)
            ax.imshow(kk,
                      extent=[xmin, xmax, ymin, ymax],
                      cmap=my_cmap,
                      interpolation='Bilinear')
            ax.grid(False)
            ax.xaxis.tick_top()
            ax.yaxis.set_major_locator(plt.MaxNLocator(4))
            ax.xaxis.set_major_locator(plt.MaxNLocator(4))
            divider = make_axes_locatable(ax)
            cax = divider.append_axes('bottom', size="5%", pad=0.05)
            cb = plt.colorbar(im0, cax=cax, orientation="horizontal")
            cb.set_label('Volumetric SM (%)')
            #cb.set_clim(vmin=5, vmax=50)

            ### ----------------------------------------------------------------

            #            # plot SMAP map
            #
            #            SMAP_SM = band_matchSMAP*100
            #            SMAP_SM = maskNDVI*SMAP_SM
            #
            #            print("SMAP SM")
            #            print("Max:" +str(np.max(SMAP_SM[np.nonzero(SMAP_SM)])))
            #            print("Min:" +str(np.min(SMAP_SM[np.nonzero(SMAP_SM)])))
            #            print("Mean:" +str(np.mean(SMAP_SM[np.nonzero(SMAP_SM)])))
            #            print("STD:" +str(np.std(SMAP_SM[np.nonzero(SMAP_SM)])))
            #
            #
            #            fig4, ax4 = plt.subplots()
            #            im4= ax4.imshow(SMAP_SM, extent=[xmin,xmax,ymin,ymax], cmap=my_cmap1, clim=(5, 45))
            #            pp = ma.masked_where(band_matchCity == 0, band_matchCity)
            #            ax4.imshow(pp, extent=[xmin,xmax,ymin,ymax], cmap=my_cmap2, interpolation='Bilinear')
            #            kk = ma.masked_where(filtWater == 0, filtWater)
            #            ax4.imshow(kk, extent=[xmin,xmax,ymin,ymax], cmap=my_cmap, interpolation='Bilinear')
            #            ax4.grid(False)
            #            ax4.xaxis.tick_top()
            #            ax4.yaxis.set_major_locator(plt.MaxNLocator(4))
            #            ax4.xaxis.set_major_locator(plt.MaxNLocator(4))
            #            divider = make_axes_locatable(ax4)
            #            cax = divider.append_axes('bottom', size="5%", pad=0.05)
            #            cb = plt.colorbar(im4, cax=cax, orientation="horizontal")
            #            cb.set_label('Volumetric SM (%)')

            ### ----------------------------------------------------------------

            #            # plot CONAE_HS interpolado mapa

            #            fig4, ax4 = plt.subplots()
            #            im4= ax4.imshow(band_matchCONAE_HS, extent=[xmin,xmax,ymin,ymax], cmap=my_cmap1, clim=(5, 45))

            plt.show()

            #im1 = ax.imshow(filtWater, cmap=my_cmap)
            #maskNDVI2 = ma.masked_where(filtWater == 0,filtWater)
            #im1 = ax.imshow(maskNDVI2, cmap=my_cmap)
            #im1 = ax.imshow(band_matchCity, cmap=my_cmap2)

            #mapSM_MLP = mapSM_MLP*maskNDVI

            functions.createHDFfile(path, nameFileMLR, 'ENVI', mapSM_MLR, c, r,
                                    GeoTSar, ProjectSar)
            functions.createHDFfile(path, nameFileMARS, 'ENVI', mapSM_MARS, c,
                                    r, GeoTSar, ProjectSar)
            functions.createHDFfile(path, nameFileMLP, 'ENVI', mapSM_MLP, c, r,
                                    GeoTSar, ProjectSar)

    print("FIN")