def multimodal_analysis(fileVV): ### se lee la imagen src_ds_VV, bandVV, GeoTVV, ProjectVV = functions.openFileHDF(fileVV, 1) transform = GeoTVV src_ds_VV = src_ds_VV xmin, xmax, ymin, ymax = transform[ 0], transform[0] + transform[1] * src_ds_VV.RasterXSize, transform[ 3] + transform[5] * src_ds_VV.RasterYSize, transform[3] ### se calcula y se plotea el histograma lcNew = bandVV.flatten('C') fig, ax = plt.subplots() y, x, _ = plt.hist(lcNew, 400, [-30, -1], facecolor='gray', density=1) fecha = i[:-5] plt.title(fecha) plt.xlim(-30, -1) plt.ylim(0, 0.3) peaks = functions.find_peaks(y) print("Maximos usando la funcion peaks: ") print(peaks) # ### se calcula los valores en el eje x para los cuales se producen los # ### máximos en el histograma, los cuales pueden ser 2 o 3 x = x[:-1] pico1, minimoLocal, pico2, pico3 = functions.Max1MinLocalMax2(x, y) # #### para cada máximo se escriben los valores en la gráfica ind = np.where(x == pico1)[0] y_i = float(y[ind]) # print(y_i) texto = '(' + str(np.round(pico1, 2)) + ';' + str(np.round(y_i, 2)) + ')' plt.text(pico1 + pico1 / 10, y_i + y_i / 10, texto) ind = np.where(x == pico2)[0] y_i = float(y[ind]) print(y_i) texto = '(' + str(np.round(pico2, 2)) + ';' + str(np.round(y_i, 2)) + ')' plt.text(pico2 + pico2 / 10, y_i + y_i / 10, texto) plt.show() # # ##------------------------------------------------------------------------------ # if(pico2 != pico3): # ind = np.where(x==pico3)[0] # y_i = float(y[ind]) # print(y_i) # texto = '('+ str(np.round(pico3,2))+';'+str(np.round(y_i,2))+')' # plt.text(pico3+pico3/10, y_i+y_i/10, texto) # # expected=(pico1,0.5,0.05,pico2,0.5,0.2,pico3,0.5,0.2) # # params,cov=curve_fit(bimodal, x, y, expected, maxfev=750000) # # sigma=sqrt(diag(cov)) # # plot(x[:-1],bimodal(x[:-1],*params),color='red',lw=1,label='model') # # plt.legend() # # new = pd.DataFrame(data={'params':params},index=bimodal.__code__.co_varnames[1:]) # # print(new) # # mu1 = new.params[0] # # sigma1 = new.params[1] # # mu2 = new.params[3] # # sigma2 = np.abs(new.params[4]) # # mu3 = new.params[6] # # sigma3 = new.params[7] # # # # # fecha = i[:-5] # # fig, ax = plt.subplots() # # # plt.title(fecha) # # # # # # ax.yaxis.set_major_locator(plt.MaxNLocator(4)) # # # ax.xaxis.set_major_locator(plt.MaxNLocator(4)) # # # divider = make_axes_locatable(ax) # # # plt.title(fecha) # # # # # # # # ## distance = nd.distance_transform_edt(bandVV == 0) # # ## result = watershed(distance, bandVV, mask=bandVV, # # ## connectivity=square(3)) # # ## bandVV = result # # # # # #data=concatenate((normal(1,.2,5000),normal(2,.2,2500))) # # #y,x,_=hist(data,100,alpha=.3,label='data') # # # # # #x=(x[1:]+x[:-1])/2 # for len(x)==len(y) # # # # # # # # #expected=(1,.2,250,2,.2,125) # # #params,cov=curve_fit(bimodal,x,y,expected) # # #sigma=sqrt(diag(cov)) # # #plot(x,bimodal(x,*params),color='red',lw=3,label='model') # # #legend() # # #plt.show() # # #new = pd.DataFrame(data={'params':params,'sigma':sigma},index=bimodal.__code__.co_varnames[1:]) # # # # # #print(new) statsV = [] return statsV
fechaSMAP.append("2016-04-13") fechaGPM.append("2016-04-12") fechaSMAP.append("2016-04-24") fechaGPM.append("2016-04-26") fechaSMAP.append("2016-05-20") fechaGPM.append("2016-05-20") for ii in range(0, len(fechaSMAP)): #for ii in range(0,1): #ii = 0 path = "/media/" + dir + "/TOURO Mobile/GPM/" + fechaGPM[ii] + "/" nameFile = "recorte.img" src_ds_GPM, bandGPM, GeoTGPM, ProjectGPM = functions.openFileHDF( path, nameFile, 1) #print bandGPM.shape bandGPM = bandGPM * 0.1 bandGPM = (bandGPM - np.mean(bandGPM)) / (np.max(bandGPM) - np.min(bandGPM)) #fig = plt.figure(1) #fig1 = fig.add_subplot(111) #fig1.set_title('GPM PP') #fig1.imshow(bandGPM, cmap=cm.gray, interpolation='none') # #print "media GPM: "+ str(np.mean(bandGPM)) #print "desvio GPM: "+ str(np.std(bandGPM)) #print "var GPM: "+ str(np.var(bandGPM))
if __name__ == "__main__": #nameFile = "ndvipru.jpg" #nameFile = "ndvireal" #nameFile = "lena.jpg" #path = "/media/ggarcia/TOURO Mobile/Scaling/img/" #src_ds, band, GeoT, Project = functions.openFileHDF(path, nameFile, 1) #path1 = "/media/ggarcia/TOURO Mobile/Trabajo_Sentinel_NDVI_CONAE/Landsat8/L_2015-06-18/" #nameFile1 = "NDVI_recortado" ### se abre la imagen landsat8 #src_ds, band, GeoTL8, ProjectL8 = functions.openFileHDF(path1, nameFile1, 1) path1 = "/media/ggarcia/TOURO Mobile/Trabajo_Sentinel_NDVI_CONAE/Landsat8/L_2015-06-18/" nameFile1 = "NDVI_recortado" ## se abre la imagen landsat8 src_ds, band, GeoT, Project = functions.openFileHDF(path1, nameFile1, 1) band = band[:600, :600] nRow, nCol = band.shape img = np.array(band) img = img / float(np.max(img)) fig0 = plt.figure(1) fig0 = fig0.add_subplot(111) fig0.set_title('imagen original') fig0.imshow(img, cmap=cm.gray) fig1 = plt.figure(8) fig1 = fig1.add_subplot(111) fig1.set_title('hist original Img') bandDownNew = img.flatten('C') y, x, _ = plt.hist(bandDownNew, 256, facecolor='b')
def applyDownscalingN(nTimes, typeFilter, orderFilter, path, nameFileIn): """ Función que realiza la operación de downscaling nVeces Recibe: numero de veces, tipo de filtro, orden del filtro, directorio y nombre del archivo HDF Retorna: imagen HDF """ if (typeFilter == "db"): low, high = functions.filterDaubechies(orderFilter) desp = 0 if (typeFilter == "Symlets"): low, high = functions.filterSymlets(orderFilter) low = low.T high = high.T if (orderFilter == 2): desp = 1 if (orderFilter == 4): desp = 3 if (typeFilter == "Coiflets"): low, high = functions.filterCoiflets(orderFilter) low = low.T high = high.T if (orderFilter == 2): desp = 0 if (orderFilter == 4): desp = -1 if (typeFilter == "Haar"): low, high = functions.filterHaar(orderFilter) desp = 0 low = low.T high = high.T if (typeFilter == "Morlet"): low, high = functions.filterMorlet(orderFilter) desp = 2 low = low.T high = high.T #print len(high) #print high if (typeFilter == "CDF"): low, high = functions.filterCDF(orderFilter) desp = 2 low = low.T high = high.T # this allows GDAL to throw Python Exceptions gdal.UseExceptions() src_ds, band, GeoT, Project = functions.openFileHDF(path, nameFileIn, 1) print "Downscaling" nRow, nCol = band.shape nBand = np.array(band) #nRow, nCol = nBand.shape print nRow, nCol print "Tamaño original: " + str(nRow) + " - " + str(nCol) aprox = nBand * 255.0 maxI = np.max(aprox) minI = np.min(aprox) print "maximo: " + str(maxI) print "minimo: " + str(minI) for i in range(0, nTimes): ### #np.random.seed(i) print "paso n:" + str(i + 1) nRow, nCol = aprox.shape det1 = det2 = det3 = np.zeros((nRow, nCol)) det1 = det2 = det3 = (np.random.rand(nRow, nCol)) * 2.0 - 1.0 #print det1 #det1 = ((np.random.rand(nRow, nCol))*2-1)#*255 ##print det1 #det2 = ((np.random.rand(nRow, nCol))*2-1)#*255 ##print det2 #det3 = ((np.random.rand(nRow, nCol))*2-1)#*255 ##print det3 #### acá debo modificar ### rW2D ### hace un nivel de recontruccion img = downscaling(aprox, det1, det2, det3, high, low, desp) imgNew = np.array(img) nRow, nCol = imgNew.shape aprox = imgNew aprox = aprox / 255.0 text = "_" + "Down_2_" + "_" + str(nCol) + '_' + str(nRow) # se crea un nuevo archivo HDR, con el mismo header pero diferente banda nameFileOut = str(nameFileIn + text + "_" + str(typeFilter) + "_" + str(orderFilter)) # + str("_band_2") nuevo = (GeoT[0], GeoT[1] / (2**float(nTimes)), GeoT[2], GeoT[3], GeoT[4], GeoT[5] / (2**float(nTimes))) #print nuevo GeoT = nuevo print "Tamaño Final: " + str(nRow) + " - " + str(nCol) functions.createHDFfile(path, nameFileOut, 'ENVI', aprox, nCol, nRow, GeoT, Project) src_ds = None
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()
import functions from mpl_toolkits.axes_grid1 import make_axes_locatable from skimage.measure import compare_mse from skimage.measure import compare_ssim as ssim from sklearn.metrics import mean_squared_error fechas = [] fechas.append("2016_05_15") #### Et observada a 36km fileETObs = "/media/gag/Datos/Imagenes_satelitales/ET/COMPARACION/" + fechas[ 0] + "/ETobs/mapa_ETobs36km.asc" src_ds_ETObs, bandETObs, GeoTETObs, ProjectETObs = functions.openFileHDF( fileETObs, 1) #### Et modelada a 36km fileETModelada = "/media/gag/Datos/Imagenes_satelitales/ET/COMPARACION/" + fechas[ 0] + "/ETmodelada/ET_modelado_" + fechas[0] src_ds_ETModelada, bandETModelada, GeoTETModelada, ProjectETModelada = functions.openFileHDF( fileETModelada, 1) transform = GeoTETObs xmin, xmax, ymin, ymax = transform[ 0], transform[0] + transform[1] * src_ds_ETObs.RasterXSize, transform[ 3] + transform[5] * src_ds_ETObs.RasterYSize, transform[3] #print xmin #print xmax fig, ax = plt.subplots()
#print '\npoints list',region_points point = region_points.pop(0) i = point[0] j = point[1] count = count + 1 #find_region(point[0], point[1]) return img_rg if __name__ == "__main__": file = "/home/gag/MyProjects/Image-Segmentation-using-Region-Growing/mapaSantaFe.tif" ### se lee la imagen src_ds, band, GeoT, Project = functions.openFileHDF(file, 1) transform = GeoT xmin, xmax, ymin, ymax = transform[ 0], transform[0] + transform[1] * src_ds.RasterXSize, transform[ 3] + transform[5] * src_ds.RasterYSize, transform[3] ###sub-window sub_win = band[1220:3740, 1190:3850] fig, ax = plt.subplots() im = ax.imshow(band) seed = plt.ginput(1) print('you clicked:', seed)
fechaGPM.append("2016-04-26") fechaSMAP.append("2016-05-20") fechaGPM.append("2016-05-20") for ii in range(0, len(fechaSMAP)): ## se abre la imagen SMAP_SM #path1 = "/media/"+dir+"/TOURO Mobile/Trabajo_Sentinel_NDVI_CONAE/SMAP/SMAP-Cali_val/"+fechaSMAP[ii]+"/recorte/" #nameFile1 = "SM.img" path1 = "/media/gag/TOURO Mobile/Trabajo_Sentinel_NDVI_CONAE/SMAP/SMAP-Cali_val/"+fechaSMAP[ii]+"/subset_reprojected.data/" nameFile1 = "soil_moisture.img" src_ds_SMAP_SM, SMAP_SM, GeoTSMAP_SM, ProjectSMAP_SM = functions.openFileHDF(path1, nameFile1, 1) # #print "geo:"+ str(GeoTSMAP_SM) #print "pro: " + str(ProjectSMAP_SM) # # #print "Tamanio SMAP_SM" #print SMAP_SM.shape ## se abre la imagen de PP acumulada 7 dias de GPM a 11 Km path2 = "/media/"+dir+"/TOURO Mobile/GPM/"+fechaGPM[ii]+"/" nameFile2 = "recorte.img" ## se abre la imagen src_ds_PP, PP, GeoTPP, ProjectPP = functions.openFileHDF(path2, nameFile2, 1) #
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")
path = "/media/gag/Datos/Estancia_Italia_2018/Sentinel-1A-SantaFe/Recorte_dB/" arr = os.listdir(path) ### ordeno la lista arr.sort() print(arr) ##### codigo para mostrar los histogramas superpuestos fig, ax = plt.subplots() for i in arr: print(i) ax.cla() ### initial state fileVV = path + "20150109.data" + "/Sigma0_VV_db.img" src_ds_VV_0, bandVV_0, GeoTVV_0, ProjectVV_0 = functions.openFileHDF( fileVV, 1) transform = GeoTVV_0 src_ds_VV = src_ds_VV_0 xmin, xmax, ymin, ymax = transform[ 0], transform[0] + transform[1] * src_ds_VV.RasterXSize, transform[ 3] + transform[5] * src_ds_VV.RasterYSize, transform[3] ### se agrega fecha del la imagen fecha = i[:-5] plt.title(fecha) lcNew_0 = bandVV_0.flatten('C') y, x, _ = plt.hist(lcNew_0, 500, [-30, -1], facecolor='gray', normed=1, label="20150109")