def mapa_show(data3d, lat, lon): y1, y2, x1, x2 = -25, 0, -52, -34 cor1 = ('#750000', '#ff0000', '#ff8000', '#fcd17d', '#ffff00', '#ffffff', '#00ffff', '#7dd1fa', '#0080ff', '#0000ff', '#000075') # Colors lev1 = (-2., -1.6, -1.3, -0.8, -0.5, 0.5, 0.8, 1.3, 1.6, 2.) pm.plotmap(data3d[0, :, :], lat, lon, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, ocean_mask=0, fig_name="figou1_teste.png.", barcolor=cor1, barlevs=lev1, barinf='both', barloc='right')
def maptercisrsm97(filein, figtitle, figout, maskocean=1): # TODO: Tirar leitura do netcdf e passar dados via cabeçalho da função ncfile = Dataset(filein) lat = ncfile.variables['latitude'][:] lon = ncfile.variables['longitude'][:] above = ncfile.variables['above'][:] normal = ncfile.variables['normal'][:] below = ncfile.variables['below'][:] belowp = np.where(((below > normal) & (below > above)), below, 0) normalp = np.where(((normal > above) & (normal > below)), normal+100, 0) abovep = np.where(((above > normal) & (above > below)), above+1000, 0) finalp = (belowp + normalp + abovep) deltalat = np.nanmean(np.diff(lat)) deltalon = np.nanmean(np.diff(lon)) y1, y2, x1, x2 = -21.397, 8., -55.637, -34. figname = "BELOW.png" my_colors = ('#ffed4c', '#f9bb34', '#f75026', '#dd2b28') xlabel = 'ABAIXO' levs = (40., 50., 60, 70.) myplot(belowp[0, :, :], lat-deltalat/2., lon-deltalon/2., my_colors, levs, xlabel, figname, y1, y2, x1, x2) img1 = Image.open(figname) img11 = img1.crop((110, 455, 550, 575)) # img11.show() img11.save("img11.png", quality=23) os.remove(figname) figname = "NORMAL.png" my_colors = ('#ccf2cc', '#abf2aa', '#57f255', '#16f200') xlabel = 'NORMAL' levs = (40., 50., 60, 70.) myplot(normalp[0, :, :]-100, lat-deltalat/2., lon-deltalon/2., my_colors, levs, xlabel, figname, y1, y2, x1, x2) img2 = Image.open(figname) img22 = img2.crop((200, 455, 610, 575)) # img22.show() img22.save("img22.png", quality=23) os.remove(figname) figname = "ABOVE.png" my_colors = ('#b2b2f2', '#8484f2', '#4143f2', '#0006f2') xlabel = 'ACIMA' levs = (40., 50., 60, 70.) myplot(abovep[0, :, :]-1000, lat-deltalat/2., lon-deltalon/2., my_colors, levs, xlabel, figname, y1, y2, x1, x2) img3 = Image.open(figname) img33 = img3.crop((250, 455, 700, 575)) # img33.show() img33.save("img33.png", quality=23) os.remove(figname) levs = ( 0., 40., 50., 60, 70., 100., 140., 150., 160., 170., 1000., 1040., 1050., 1060., 1070., 1100 ) my_colors = ('#ffffff', '#ffed4c', '#f9bb34', '#f75026', '#dd2b28', '#ffffff', '#ccf2cc', '#abf2aa', '#57f255', '#16f200', '#ffffff', '#b2b2f2', '#8484f2', '#4143f2', '#0006f2') pm.plotmap(finalp[0, :, :], lat-deltalat/2., lon-deltalon/2., latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=maskocean, meridians=np.arange(-160., 161., 5.), parallels=np.arange(-90., 91., 5.)) concat("img11.png", "img22.png", "img33.png", figname, figout)
# y1, y2, x1, x2 = -40., 40., -150., 70. # Globo #~ y1, y2, x1, x2 = -89., 89., -178., 178. # Globo #~ y1, y2, x1, x2 = -23., 9., -75., -34. # Região Reliability y1, y2, x1, x2 = -21.3, 7., -55.6, -34 # América do sul ########### CORRELAÇÃO ########### correl = cs.compute_pearson(hind, obs, n_years) figtitle = u'RSM97 x UTEXAS - {0}/{1} ({2})\nCorrelação - Precip Acum'.format(fcst_month_name, target_months, hind_period_name) figname = "{3}/bra_precip_persistida_{0}_null-{1}_null_{2}_rsm97_1dg_utexas_correlacao.png".format(hind_period_name, target_months, n_fcst_month, outdir) levs = (-1.0, -0.9, -0.7, -0.5, -0.3, 0.3, 0.5, 0.7, 0.9, 1.0) #10 my_colors = ('#2372c9', '#3498ed', '#4ba7ef', '#76bbf3', '#93d3f6', '#b0f0f7', '#ffffff', '#fbe78a', '#ff9d37', '#ff5f26', '#ff2e1b', '#ff0219', '#ae000c') #13 pm.plotmap(correl, obs_lats-0.54/2., obs_lons-0.54/2., latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=1) background = Image.open(figname) foreground = Image.open("/home/marcelo/FSCT-ECHAM46/FUNCEME_LOGO.png") foreground = foreground.resize((90, 70), Image.ANTIALIAS) background.paste(foreground, (313, 460), foreground) background.save(figname, optimize=True, quality=95) # ########### RMSE ########### # error_rmse = cs.compute_rmse(hind, obs) # rmse_title = u'ECHAM4.6 x CMAP - {0}/{1} ({2})\nRMSE (mm) - Precip Acum'.format(fcst_month_name, target_months, hind_period_name) # fig_rmse = '{3}/bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_rmse.png'.format(hind_period_name, target_months, n_fcst_month, outdir) # levs = (0., 50., 100., 200., 400., 600., 800.) #7 # my_colors = ('#ffffff', '#E1FFFF', '#B4F0FA', '#96D2FA', '#78B9FA', # '#50A5F5', '#3C96F5', '#2882F0') #8 # pm.plotmap(error_rmse, newlats-1./2., newlons-1./2., latsouthpoint=y1, latnorthpoint=y2,
caso_shape_so_plot('/estados/sergipe/sergipe.txt') y1, y2, x1, x2 = -20, 0, -50, -34 cor1 = ('#750000', '#ff0000', '#ff8000', '#fcd17d', '#ffff00', '#ffffff', '#00ffff', '#7dd1fa', '#0080ff', '#0000ff', '#000075') # Paleta lev1 = (-2., -1.6, -1.3, -0.8, -0.5, 0.5, 0.8, 1.3, 1.6, 2.) figou1 = 'ESI_Regiao_NEB_4WK_{0}_{1}.png'.format(mes[i], ANO) title1 = u'Índice de Estresse Evaporativo \n{0} - {1}'.format( mes[i], ANO) pm.plotmap(Dmasked[0, :, :], lats, lons, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, ocean_mask=1, shapefile=None, fig_name=figou1, fig_title=title1, barcolor=cor1, barlevs=lev1, barinf='both', barloc='right') plt.close('all') plt.cla()
ltime = 5 levs = (270., 275., 280., 285., 290., 295., 300.) #7 my_colors = ('#ffffff', '#E5E5E5', '#CBCBCB', '#B2B2B2', '#989898', '#7F7F7F', '#666666', '#4E4E4E') #8 # LIQIANG f1 = NetCDFFile('/home/marcelo/Downloads/sst-test/liq/obs.sst.2013.nc', 'r') sstliq = f1.variables['sst'][:] lons_sstliq = f1.variables['lon'][:] lats_sstliq = f1.variables['lat'][:] f1.close() sstliq, lons_sstliq = shiftgrid(180., sstliq, lons_sstliq, start=False) sstliq_title = u'TSM LIQ' fig_sstliq = '/home/marcelo/Downloads/sst-test/tsmliq.png' pm.plotmap(sstliq[ltime, :, :], lats_sstliq-2.8125/2., lons_sstliq-2.8125/2., latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=fig_sstliq, barloc='bottom', maptype='fillc', barcolor=my_colors, barlevs=levs, fig_title=sstliq_title, barinf='max', ocean_mask=0, meridians=np.arange(-160., 161., 30.), parallels=np.arange(-90., 91., 20.)) # NÃO INVERTIDO USANDO A LAT DO MENOR PARA O MAIOR # f4 = NetCDFFile('/home/marcelo/Downloads/sst-test/nc3/obs.sst.2013.nc', 'r') # sstnc3 = f4.variables['sst'][:, :, :] # lons_sstnc3 = f4.variables['lon'][:] # lats_sstnc3 = f4.variables['lat'][:] # f4.close() # sstnc3, lons_sstnc3 = shiftgrid(180., sstnc3, lons_sstnc3, start=False) # sstliq_title = u'NÃO INVERTIDO USANDO A LAT DO MENOR PARA O MAIOR' # fig_sstliq = '/home/marcelo/Downloads/sst-test/n3.png' # pm.plotmap(sstnc3[ltime, :, :], lats_sstnc3-2.8125/2., lons_sstnc3-2.8125/2., latsouthpoint=y1, latnorthpoint=y2, # lonwestpoint=x1, loneastpoint=x2, fig_name=fig_sstliq, barloc='bottom', maptype='fill', # barcolor=my_colors, barlevs=levs, fig_title=sstliq_title, barinf='max', ocean_mask=0,
print zi.shape # np.savetxt("zi.txt", zi) for ilon in range(0, 109): for ilat in range(0, 72): print lonrsm[ilon], latrsm[ilat], zi[ilat, ilon] exit() # print zi levs = [-2., -1.8, -1.3, -0.8, -0.5, 0.] my_colors = ('#730000', '#E60000', '#FFAA00', '#FCD37F', '#FFFF00') pm.plotmap(zi, latrsm-0.54/2., lonrsm-0.54/2., latnorthpoint=np.max(latrsm), latsouthpoint=np.min(latrsm), loneastpoint=np.max(lonrsm), lonwestpoint=np.min(lonrsm), barlevs=levs, barcolor=my_colors, barinf='min') exit() # inc = netCDF4.Dataset('/home/funceme/Downloads/pcp-seasonacc-echam46-hind8908-en51-jan2014_2014AMJ.ctl.nc') # time = inc.variables['time'][:] # latt42 = inc.variables['latitude'][:] # lont42_360 = inc.variables['longitude'][:] # pcpt42 = inc.variables['pcp'][0, :, :] # pcpt42 , lont42_360 = addcyclic(pcpt42, lont42_360) # pcpt42, lont42 = shiftgrid(180., pcpt42, lont42_360, start=False) # # inc = netCDF4.Dataset('/home/funceme/Downloads/pcp-seasonacc-echam46-hind8908-en51-jan2014_2014AMJ.ctl.1dg.nc') # lat1dg = inc.variables['LAT'][:] # lon1dg = inc.variables['LON'][:] # pcp1dg = inc.variables['pcp'][0, :, :]
correl = cs.compute_pearson(hind, obs) figtitle = u'RSM97 x {3} - {0}/{1} ({2})\nCorrelação - Precip Acum' \ .format(fcst_month.upper(), target_months, hind_period_name, obs_base.upper()) figname = '{3}/neb_precip_persistida_{0}_null-{1}_null_{2}' \ '_rsm97_1dg_{4}_correlacao.png' \ .format(hind_period_name, target_months, fcst_months[fcst_month], outdir, obs_base) levs = (-1.0, -0.9, -0.7, -0.5, -0.3, 0.3, 0.5, 0.7, 0.9, 1.0) #10 my_colors = ('#2372c9', '#3498ed', '#4ba7ef', '#76bbf3', '#93d3f6', '#b0f0f7', '#ffffff', '#fbe78a', '#ff9d37', '#ff5f26', '#ff2e1b', '#ff0219', '#ae000c') #13 pm.plotmap(correl, hind_lats, hind_lons, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=1, meridians=np.arange(-160., 161., 2.), parallels=np.arange(-90., 91., 2.)) # TODO: Colocar em uma funcao bx, by = 408, 460 background = Image.open(figname) foreground = Image.open("FUNCEME_LOGO.png") foreground = foreground.resize((90, 70), Image.ANTIALIAS) background.paste(foreground, (bx, by), foreground) background.save(figname, optimize=True, quality=95) ########### RMSE ########### error_rmse = cs.compute_rmse(hind, obs) rmse_title = u'RSM97 x {3} - {0}/{1} ({2})\nRMSE (mm) - Precip Acum' \ .format(fcst_month.upper(), target_months,
clim_pcp_obs = clim_obs_data.variables['PRECIP'][:] clim_obs_data.close() # exit() # pcp_obs = np.mean(pcp_obs, axis=0) # pcp_obs = pcp_obs * 89. # Fev 28, Mar 31, Abr 30 pcp_obs = pcp_obs * 89 clim_pcp_obs = clim_pcp_obs * 89 mytercis = cs.tercil_verification(clim_pcp_obs, pcp_obs) # Plot categorias lev = [-1, 0., 1., 2.] my_colors = ('#F75026', '#57F255', '#4143F2') pm.map_shaded(mytercis, lats-1./2., lons-1./2., meridians=np.arange(-160., 161., 10.), fig_name="cmap.fma.2015.cat.png", barlevs=lev, barcolor=my_colors, latsouthpoint=-60., latnorthpoint=15., fig_title="CMAP - FMA 2015 - CAT", lonwestpoint=-90., loneastpoint=-30., ocean_mask=1) # Plot precip acumulada lev = [0., 50., 100., 200., 300., 500., 700., 900., 1000.] my_colors = ('#CC3333', '#FF6633', '#FF9933', '#FFFF99', '#FFFFCC', '#CCFFCC', '#99FFCC', '#66FF66', '#00CC00', '#009900', '#003300') #11 pm.map_shaded(pcp_obs, lats-1./2., lons-1./2., meridians=np.arange(-160., 161., 10.), fig_name="cmap.fma.2015.accum.png", barlevs=lev, barcolor=my_colors, latsouthpoint=-60., latnorthpoint=15., fig_title="CMAP - FMA 2015 - ACUM", lonwestpoint=-90., loneastpoint=-30., barinf="max", ocean_mask=1)
obs = read_obs_file.variables['pcp'][:, :, :] read_obs_file.close() except: print "Erro ao ler arquivo observado" exit() # RMSE print "... RMSE ..." error_rmse = cs.rmse(hind, obs) rmse_title = u'ECHAM4.6 x CMAP - {0}/{1} ({2})\nRMSE (mm) - Precip Acum'.format(fcst_month, target_months, hind_period) fig_rmse = 'bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_rmse.png'.format(hind_period, target_months, n_fcst_month) levs = (0., 50., 100., 200., 400., 600., 800.) #7 my_colors = ('#ffffff', '#E1FFFF', '#B4F0FA', '#96D2FA', '#78B9FA', '#50A5F5', '#3C96F5', '#2882F0') #8 pm.map_shaded(error_rmse, lats-1./2., lons-1./2., latsouthpoint=-60., latnorthpoint=15., lonwestpoint=-90., loneastpoint=-30., fig_name=fig_rmse, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=rmse_title, barinf='max', ocean_mask=1) # Desvio padrão print u"... desvio padrão ..." hind_std = np.nanstd(hind, axis=0) hind_std_title = u'ECHAM4.6 x CMAP - {0}/{1} ({2})\nDesvio Padrão (mm) - Precip Acum'.format(fcst_month, target_months, hind_period) fig_hind_std = 'bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_std.png'.format(hind_period, target_months, n_fcst_month) levs = (0., 25., 50., 75., 100., 150., 200.) #7 my_colors = ('#ffffff', '#E1FFFF', '#B4F0FA', '#96D2FA', '#78B9FA', '#50A5F5', '#3C96F5', '#2882F0') #8 pm.map_shaded(hind_std, lats-1./2., lons-1./2., latsouthpoint=-60., latnorthpoint=15., lonwestpoint=-90., loneastpoint=-30., fig_name=fig_hind_std, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=hind_std_title, barinf='max', ocean_mask=1) # Viés
"#ffffff", "#fbe78a", "#ff9d37", "#ff5f26", "#ff2e1b", "#ff0219", "#ae000c", ) # 13 pm.plotmap( correl, newlats, newlons, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, barloc="right", barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf="neither", ocean_mask=1, ) background = Image.open(figname) foreground = Image.open("FUNCEME_LOGO.png") foreground = foreground.resize((90, 70), Image.ANTIALIAS) background.paste(foreground, (334, 461), foreground) background.save(figname, optimize=True, quality=95) ########### RMSE ########### error_rmse = cs.compute_rmse(hind, obs)
# Carrega arquivo da climatologia clim_file = Dataset('/Users/Hulk/TestPyFuncemeClimateTools/lib/python2.7/site-packages/PyFuncemeClimateTools/examples/pcp-daily-total-ec4amip_8908JFM.nc') clim_pcp = clim_file.variables['pcp'][:] # Carrega arquivo da previsão fsct_file = Dataset('/Users/Hulk/TestPyFuncemeClimateTools/lib/python2.7/site-packages/PyFuncemeClimateTools/examples/pcp-daily-total-ec4amip_2015JFM.nc') fsct_pcp = fsct_file.variables['pcp'][:] # Longitude e latitudes fsct_lon = fsct_file.variables['longitude'][:] fsct_lat = fsct_file.variables['latitude'][:] # Calcula anomalias # A função abaixo retornar dois parametros myanom, myanom_pad = cs.compute_anomaly(fsct_pcp, clim_pcp) # Shift na longitude e nos dados do modelo # Isso é necessário pois a longitude do NetCDF é no formato 0 - 360 # a função aceita valores de longitude no formato -180 - +180 myanom, fsct_lon = shiftgrid(180., myanom, fsct_lon, start=False) # Plot map # a variavel a ser plotada deve ser 2d pm.anom_map_shaded(myanom[0, :, :], fsct_lon-2.8125/2., fsct_lat-2.8125/2.)
img22.save("img22.png", quality=23) os.remove(figname) figname = "ABOVE.png" my_colors = ('#b2b2f2', '#8484f2', '#4143f2', '#0006f2') xlabel = 'ACIMA' levs = (40., 50., 60, 70.) myplot(abovep[0, :, :]-1000, lat-1./2., lon-1./2., my_colors, levs, xlabel, figname, y1, y2, x1, x2) img3 = Image.open(figname) img33 = img3.crop((250, 455, 700, 575)) # img33.show() img33.save("img33.png", quality=23) os.remove(figname) levs = ( 0., 40., 50., 60, 70., 100., 140., 150., 160., 170., 1000., 1040., 1050., 1060., 1070., 1100 ) my_colors = ('#ffffff', '#ffed4c', '#f9bb34', '#f75026', '#dd2b28', '#ffffff', '#ccf2cc', '#abf2aa', '#57f255', '#16f200', '#ffffff', '#b2b2f2', '#8484f2', '#4143f2', '#0006f2') figname, figtitle = "ECHAM4p6.png", "ECHAM4.6 - OUT/2015 - OND/2015\nPROB PREC (%) (89-08)" pm.plotmap(finalp[0, :, :], lat-1./2., lon-1./2., latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=1) concat("img11.png", "img22.png", "img33.png", figname, "echamprob.png")
#~ lat,lon = grb.latlons() #~ #~ figtitle = 'TITULO DA FIGURA' #~ figname_anom = 'atub1.png' #~ levs = range(100, 420, 20) #~ my_colors = ('#340003', '#ae000c', '#ff2e1b', '#ff5f26', '#ff9d37', '#fbe78a', #~ '#ffffff', '#b0f0f7', '#93d3f6', '#76bbf3', '#4ba7ef', '#3498ed', '#2372c9') #13 #~ pm.plotmap(aux1[0,217:231,130:280], lat[217:231,0], lon[0,130:280], fig_name=figname_anom, barloc='bottom', #~ barcolor=my_colors, barlevs=levs, fig_title=figtitle, #~ barinf='both', ocean_mask=0) print '---' grb = grbs.select(name='Potential temperature')[0] data = grb.values print data[217:231,130:280] exit() figtitle = 'TITULO DA FIGURA 2' figname_anom = 'atub2.png' levs = range(100, 420, 20) my_colors = ('#340003', '#ae000c', '#ff2e1b', '#ff5f26', '#ff9d37', '#fbe78a', '#ffffff', '#b0f0f7', '#93d3f6', '#76bbf3', '#4ba7ef', '#3498ed', '#2372c9') #13 pm.plotmap(data[217:231,130:280], lat[217:231,0], lon[0,130:280], fig_name=figname_anom, barloc='bottom', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='both', ocean_mask=0)
figtitle = "RSM97 - Precip Acum (mm)" figname = "{5}/neb_precip_persistida_{0}_{1}-{2}_{3}_{4}_" "rsm97_1dg_null_precip.png".format( hind_period_name, target_year, target_months, fcst_year, fcst_months[fcst_month], outdir ) pm.plotmap( fcst[0, :, :], fcst_lats, fcst_lons, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, fig_title=figtitle, barcolor=my_colors, ocean_mask=0, barlevs=lev, barinf="max", barloc="bottom", meridians=np.arange(-160.0, 161.0, 2.0), parallels=np.arange(-90.0, 91.0, 2.0), ) if obs_base == "inmet" or obs_base == "chirps" or obs_base == "cru": ### Anomalia corrigida: metódo do Caio (regressão linear) ### below, normal, above, f_signal, f_std, o_pad, fcst_sig_anom = cs.compute_probability(fcst, hind, obs) hind_corrigido = cs.compute_setrighthind(hind, obs)
data = netCDF4.Dataset(path_in + name) var = data.variables[ 'eto'][:, :, :] # Declaring variable under study to calculate the lats = data.variables['lat'][:] # Declaring latitude lons = data.variables['lon'][:] # Declaring longitude for m in range(0, var.shape[0]): print m, mes[m], dic[mes[m]] title1 = u'Evapotranspiração Potencial\n Desvio Padrão - {0}'.format( mes[m]) figou1 = 'plot_STD_CRU_{0}.png'.format(mes[m]) pm.plotmap(var[m, :, :] * dic[mes[m]], lats, lons, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, ocean_mask=1, fig_name=figou1, fig_title=title1, barcolor=cor1, barlevs=lev1, barinf='max', barloc='right') print np.nanmax(var), np.nanmin(var)
lonlat = np.array(polig) elif isinstance(polig, MultiPolygon): # Cria dicionario para os multipoligonos onde a chave do dicionário # é o número de vérticies do polígono poly = {} for poli in polig: xy = np.array(poli.exterior.coords) poly[xy.shape[0]] = xy lonlat = poly[max(poly)] # Salvar lonlat das regiões # fstr = "{0}.dat".format(sigla) # np.savetxt(fstr, lonlat, fmt='%15.6f', delimiter=' ', newline='\n') # Plotar mapas # pl.plot(lonlat[:, 0], lonlat[:, 1]) # pl.title(sigla) # pl.show() points_grid, lonlat_grid, array_bool = pointinsidev2(lats1, lons1, lonlat) pm.plotmap(array_bool, lats1-0.5, lons1-0.5)
if not os.path.exists(figrealname): print "entrooou... delicia! =)" fcst, hind, obs = readdata(myhind, myfmon, myfyear, mytyear, mytseason) if not os.path.exists("img"): os.makedirs("img") below, normal, above, fsignal, fstd, opad, fs_anom = cs.compute_probability( fcst[0, i_lat, i_lon], hind[:, i_lat, i_lon], obs[:, i_lat, i_lon], lenhind ) fsignal = np.expand_dims(fsignal, axis=0) pm.plotnorm(fsignal, fstd, opad, fig_name=figname, fig_title="") shutil.copy2(figname, figrealname) else: print "nao entrou =(" # se a imagem ja tiver sido gerada, apenas faz copia para exibir no site shutil.copy2(figrealname, figname) elif myopt == "a": fcst, hind, obs = readdata(myhind, myfmon, myfyear, mytyear, mytseason) lonlat = dg.getvertbd(myregion, filetxtout=False, figout=False)
figname_anom = '{5}/bra_precip_persistida_{0}_{1}-{2}_{3}_{4}_' \ 'echam46_1dg_null_anom.png'.format(hind_period_name, target_year, target_months, fcst_year, n_fcst_month, outdir) levs = (-700., -500., -300., -100., -50., -30., 30., 50., 100., 300., 500., 700.) #12 my_colors = ('#340003', '#ae000c', '#ff2e1b', '#ff5f26', '#ff9d37', '#fbe78a', '#ffffff', '#b0f0f7', '#93d3f6', '#76bbf3', '#4ba7ef', '#3498ed', '#2372c9') #13 pm.plotmap(anomaly_corrigida[0, :, :], newlats, newlons, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname_anom, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='both', ocean_mask=1) background = Image.open(figname_anom) foreground = Image.open("FUNCEME_LOGO.png") foreground = foreground.resize((90, 70), Image.ANTIALIAS) background.paste(foreground, (334, 461), foreground) background.save(figname_anom, optimize=True, quality=95) ### Tercil mais provável para toda a região do globo ### file_out = "{5}/prob_echam46_issue_{0}{1}_target_{2}{3}_{4}.nc" \ .format(fcst_month, fcst_year, target_months, target_year, hind_period, outdir) # below, normal, above, f_signal, f_std, o_pad, fcst_sig_anom = \
figura, ax = plot_reliability(above[:,0], above[:,1], maintitle=mytitle, first=False, fig=figura, cor='red') name_fig = "bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_reliability.png".format(hind_period, target_months, n_fcst_month) plt.savefig(name_fig) plt.close() correl = cs.compute_pearson(pcp_model, pcp_obs, timelen=14.) # correl_aux, lons_aux = shiftgrid(180., correl, lons, start=False) figtitle = u'RSM97 x PRECL - FMA - 02-15\nPersistida - 0.54x0.54 - Correlação - Precip Acum' figname = "correl_rsm97per_x_precl_jfm_0215.png" levs = (-1.0, -0.9, -0.7, -0.5, -0.3, 0.3, 0.5, 0.7, 0.9, 1.0) #10 my_colors = ('#2372c9', '#3498ed', '#4ba7ef', '#76bbf3', '#93d3f6', '#b0f0f7', '#ffffff', '#fbe78a', '#ff9d37', '#ff5f26', '#ff2e1b', '#ff0219', '#ae000c') #13 print "\n... salvando figura ..." pm.map_shaded(correl, lats-0.54/2., lons-0.54/2., latsouthpoint=-16., latnorthpoint=5., lonwestpoint=-54., loneastpoint=-30., fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=1) # pm.map_shaded(correl_aux, lats-2.8125/2., lons_aux-2.8125/2., fig_name=figname, barloc='right', # barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=0)
pcp_obs_ce = obs_file['pcp'][:, 29:31, 114] obs_ce = np.asarray(pcp_obs_ce) # Média sobre o CE fsct_aux_ce = np.apply_over_axes(np.mean, fsct_ce, [1, 2]) hind_aux_ce = np.apply_over_axes(np.mean, hind_ce, [1, 2]) obs_aux_ce = np.apply_over_axes(np.mean, obs_ce, [1, 2]) outdir = "%s%s_HIND%s" % (fcst_month.upper(), fcst_year, hind_period) if not os.path.exists(outdir): os.makedirs(outdir) # Curva de probabilidade para o CE figname = outdir + '/' + 'prob_echam46_issue_%s%s_target_%s%s_%s_curve_ce.png' % (fcst_month, fcst_year, target_months, target_year, hind_period) below_ce, normal_ce, above_ce, f_signal_ce, f_std_ce, o_pad_ce = cs.compute_probability(fsct_aux_ce[:, 0, 0], hind_aux_ce[:, 0, 0], obs_aux_ce[:, 0, 0]) pm.plotnorm(f_signal_ce, f_std_ce, o_pad_ce, fig_name=figname, fig_title='') ### Fim Bloco Curva para o CE ### # Tercil mais provável para toda a região do globo file_out = outdir + '/' + "prob_echam46_issue_%s%s_target_%s%s_%s.nc" % (fcst_month, fcst_year, target_months, target_year, hind_period) below, normal, above, f_signal, f_std, o_pad = cs.compute_probability(fsct, hind, obs) cn.create_netcdf_probs(below, normal, above, lats, lons, fileout=file_out) # ferret_command = "/home/marcelo/pyferret-0.0.9/bin/pyferret.sh -nojnl -gif -script plot_tercis_ensemble.jnl {0}".format(file_out) # os.system(ferret_command) # Correlacao correl = cs.corr_pearson(hind, obs) correl, lons_correl_aux = shiftgrid(180., correl, lons, start=False)
"#FFFFCC", "#CCFFCC", "#99FFCC", "#66FF66", "#00CC00", "#009900", "#003300", ) # 11 pm.plotmap( diff, lat1dg - 1 / 2.0, lon1dg - 1 / 2.0, meridians=np.arange(-180.0, 180.0, 30.0), fig_name="cdobilinterp.png", barlevs=lev, barcolor=my_colors, latsouthpoint=-90.0, latnorthpoint=90.0, fig_title="cdo bili interp", lonwestpoint=-180.0, loneastpoint=180.0, barinf="max", ocean_mask=0, ) exit() lev = [0.0, 50.0, 100.0, 200.0, 300.0, 500.0, 700.0, 900.0, 1000.0] my_colors = ( "#CC3333", "#FF6633", "#FF9933",
#~ y1, y2, x1, x2 = -89., 89., -178., 178. # Globo #~ y1, y2, x1, x2 = -23., 9., -75., -34. # Região Reliability y1, y2, x1, x2 = -60., 15., -90., -30. # América do sul ########### CORRELAÇÃO ########### correl = cs.compute_pearson(hind, obs, n_years) figtitle = u'ECHAM4.6 x CMAP - {0}/{1} ({2})\nCorrelação - Precip Acum'.format(fcst_month_name, target_months, hind_period_name) #~ figtitle = u'ECHAM4.6 x CMAP - {0}/{1} ({2})\nCorrelation - Precip Accum'.format(fcst_month_name, target_months, hind_period_name) figname = "{3}/bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_correlacao.png".format(hind_period_name, target_months, n_fcst_month, outdir) levs = (-1.0, -0.9, -0.7, -0.5, -0.3, 0.3, 0.5, 0.7, 0.9, 1.0) #10 my_colors = ('#2372c9', '#3498ed', '#4ba7ef', '#76bbf3', '#93d3f6', '#b0f0f7', '#ffffff', '#fbe78a', '#ff9d37', '#ff5f26', '#ff2e1b', '#ff0219', '#ae000c') #13 pm.plotmap(correl, newlats-1./2., newlons-1./2., latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=1) background = Image.open(figname) foreground = Image.open("FUNCEME_LOGO.png") foreground = foreground.resize((90, 70), Image.ANTIALIAS) background.paste(foreground, (334, 461), foreground) background.save(figname, optimize=True, quality=95) ########### RMSE ########### error_rmse = cs.compute_rmse(hind, obs) rmse_title = u'ECHAM4.6 x CMAP - {0}/{1} ({2})\nRMSE (mm) - Precip Acum'.format(fcst_month_name, target_months, hind_period_name) fig_rmse = '{3}/bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_rmse.png'.format(hind_period_name, target_months, n_fcst_month, outdir) levs = (0., 50., 100., 200., 400., 600., 800.) #7 my_colors = ('#ffffff', '#E1FFFF', '#B4F0FA', '#96D2FA', '#78B9FA', '#50A5F5', '#3C96F5', '#2882F0') #8 pm.plotmap(error_rmse, newlats-1./2., newlons-1./2., latsouthpoint=y1, latnorthpoint=y2,
os.makedirs('figs_expsolar/map_correl') figname = 'figs_expsolar/map_correl' \ '/bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_' \ 'correlacao.png' \ .format('8110', 'FMA', 'JAN') levs = (-1.0, -0.9, -0.7, -0.5, -0.3, 0.3, 0.5, 0.7, 0.9, 1.0) # 10 my_colors = ('#2372c9', '#3498ed', '#4ba7ef', '#76bbf3', '#93d3f6', '#b0f0f7', '#ffffff', '#fbe78a', '#ff9d37', '#ff5f26', '#ff2e1b', '#ff0219', '#ae000c') # 13 pm.plotmap(correl, nla, nlo, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=1) correl = cs.compute_pearson(pcpe[0:30, :, :], obs[0:30, :, :]) figtitle = u'ECHAM4.6 x CMAP - {0}/{1} ({2})\nCorrelação - Precip Acum (EXP SOLAR)' \ .format('JAN', 'FMA', '8110') figname = 'figs_expsolar/map_correl' \ '/bra_precip_persistida_{0}_null-{1}_null_{2}_echam46_1dg_cmap_' \ 'correlacao_exp.png' \ .format('8110', 'FMA', 'JAN') levs = (-1.0, -0.9, -0.7, -0.5, -0.3, 0.3, 0.5, 0.7, 0.9, 1.0) # 10
# lons = read_fcst_file.variables['lon'][:] # read_fcst_file.close() # hind_file = "/home/marcelo/FSCT-ECHAM46/APR2015_HIND89-08-1DG/pcp-daily-total-ec4amip_89-08MJJ.1.0dg.fix.nc" # read_hind_file = pupynere.NetCDFFile(hind_file, 'r') # hind = read_hind_file.variables['pcp'][:, :, :] # read_hind_file.close() # # obs_file = "/home/marcelo/FSCT-ECHAM46/APR2015_HIND89-08-1DG/cmap.89-08-MJJ-1.0dg.fix.nc" # read_obs_file = pupynere.NetCDFFile(obs_file, 'r') # obs = read_obs_file.variables['pcp'][:, :, :] # read_obs_file.close() if myopt == "p": n_lon, n_lat, i_lon, i_lat = dg.gridpoint(lons, lats, mylon, mylat) myfcst = fsct[0, i_lat, i_lon] myhind = hind[:, i_lat, i_lon] myobs = obs[:, i_lat, i_lon] below, normal, above, fsignal, fstd, opad = cs.compute_probability(myfcst, myhind, myobs) fsignal = np.expand_dims(fsignal, axis=0) figname = "curve_prob_%s_%s.png" % (mylon, mylat) pm.plotnorm(fsignal, fstd, opad, fig_name=figname, fig_title='') elif myopt == "a": print 't1' pass else: print 't2' pass
# obs_ce = obs_file.variables['pcp'][:, 53:58, 49:53] # obs_mean_ce = np.apply_over_axes(np.mean, obs_ce, [1, 2]) # obs_ce = obs_file.variables['pcp'][:, 52:54, 51:53] # obs_mean_ce = np.apply_over_axes(np.mean, obs_ce, [1, 2]) obs_ce = obs_file.variables['pcp'][:, 52:53, 53:54] obs_mean_ce = np.apply_over_axes(np.mean, obs_ce, [1, 2]) # Longitude e latitude lons = fsct_file.variables['lon'][:] lats = fsct_file.variables['lat'][:] # Curva de probabilidade below_ce, normal_ce, above_ce, f_signal_ce, f_std_ce, o_pad_ce = cm.compute_probability(fsct[:, 0, 0], hind[:, 0, 0], obs[:, 0, 0]) pm.plotnorm(f_signal_ce, f_std_ce, o_pad_ce, fig_name='prob.echam46+nmme.curve.ce.png', fig_title='') # below, normal, above, f_signal, f_std, o_pad = cm.compute_probability(fsct, hind, obs) # cn.create_netcdf_probs(below, normal, above, lats, lons, fileout="prob_nmme+echam46_issue_jan2015_target_fma2015.nc") # Anomalia # anomaly, anomaly_pad = cm.compute_anomaly(fsct, hind) # Shift na longitude e nos dados do modelo # Isso é necessário pois a longitude do NetCDF é no formato 0 - 360 # a função aceita valores de longitude no formato -180 - +180 # Chefinho quer ver todos os oceanos # anomaly, fsct_lon = shiftgrid(30., anomaly, fsct_lon, start=False) # anomaly, lons_anom_aux = shiftgrid(180., anomaly, lons, start=False) # Plot map anomalia globo
'#ffffff', '#00ffff', '#7dd1fa', '#0080ff', '#0000ff', '#000075') # Paleta lev1 = (-2., -1.6, -1.3, -0.8, -0.5, 0.5, 0.8, 1.3, 1.6, 2.) fig = plt.figure() figou1 = 'ESI_Regiao_SA_4WK_{0}_{1}.png'.format(mes[i], ANO) title1 = u'Índice de Estresse Evaporativo \n{0} - {1}'.format( mes[i], ANO) txtbox(u'Fonte: NOAA/ESSIC and USDA-ARS\nElaboração: FUNCEME', 0.46, 0.06, 8, (1, 1, 1)) pm.plotmap(aux_in[0, :, :], lat, lon, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, ocean_mask=1, fig_name=figou1, fig_title=title1, barcolor=cor1, barlevs=lev1, barinf='both', barloc='right') plt.close('all') plt.cla()
for i in range(30): obs[i, ...] = interp(obs_aux[i, ...], lons_obs, lats_obs, x, y, order=1) print(obs.shape) ########### CORRELAÇÃO ########### correl = cs.compute_pearson(hind, obs) figtitle = u'RSM2008 x INMET - JAN/{0} (8110)\nCORRELAÇÃO - PRECIP ACUM'.format(tri.upper()) figname = 'rsm.correl.{0}.png'.format(tri) levs = (-1.0, -0.9, -0.7, -0.5, -0.3, 0.3, 0.5, 0.7, 0.9, 1.0) #10 my_colors = ('#2372c9', '#3498ed', '#4ba7ef', '#76bbf3', '#93d3f6', '#b0f0f7', '#ffffff', '#fbe78a', '#ff9d37', '#ff5f26', '#ff2e1b', '#ff0219', '#ae000c') #13 pm.plotmap(correl, lats_hind, lons_hind, latsouthpoint=-38.27, latnorthpoint=13.63, lonwestpoint=-84.3, loneastpoint=-33., fig_name=figname, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='neither', ocean_mask=1) ########### VIÉS ########### print(hind.shape) print(obs.shape) exit() error_bias = cs.compute_bias(hind, obs) error_bias[np.isinf(error_bias)] = 0 print(np.min(error_bias)) print(np.max(error_bias)) figtitle =u'RSM2008 x INMET - JAN/{0} (8110)\nVIÉS (mm) - PRECIP ACUM'.format(tri.upper()) figname = 'rsm.vies.{0}.png'.format(tri) levs = (-4, -3, -2., -1., -0.5, 0.5, 1, 2, 3, 4)
"#CCFFCC", "#99FFCC", "#66FF66", "#00CC00", "#009900", "#003300", ) # 11 result_aux, lon_aux = shiftgrid(180.0, result, lon, start=False) pm.map_shaded( result_aux, lat - 2.5 / 2.0, lon_aux - 2.5 / 2.0, meridians=np.arange(-160.0, 161.0, 10.0), fig_name="sub.cmap.fma.2015.accum.png", barlevs=lev, barcolor=my_colors, latsouthpoint=-60.0, latnorthpoint=15.0, fig_title="SUB CMAP - FMA 2015 - ACUM", lonwestpoint=-90.0, loneastpoint=-30.0, barinf="both", ocean_mask=1, ) print result print "original.shape", original.shape print "myvar.shape", myvar.shape print "result.shape", result.shape print "np.min(result)", np.min(result) print "np.max(result)", np.max(result)
anom_diff = anom_exp - anom figtitle = u'Anom Diff (mm) (EXP - CONTROl)' figname_anom = '{0}/diff_anom_{1}.png'.format(directory, y) levs = (-300., -100., -50., -30., -15., -5., 5., 15., 30., 50., 100., 300.) # 12 my_colors = ('#340003', '#ae000c', '#ff2e1b', '#ff5f26', '#ff9d37', '#fbe78a', '#ffffff', '#b0f0f7', '#93d3f6', '#76bbf3', '#4ba7ef', '#3498ed', '#2372c9') # 13 pm.plotmap(anom_diff, nla, nlo, latsouthpoint=y1, latnorthpoint=y2, lonwestpoint=x1, loneastpoint=x2, fig_name=figname_anom, barloc='right', barcolor=my_colors, barlevs=levs, fig_title=figtitle, barinf='both', ocean_mask=1) # diff das anomalias percentual anom_diff_p = ((anom_exp - anom) / anom) * 100 print(np.max(anom_diff_p)) print(np.min(anom_diff_p)) figtitle = u'Anom Diff Percentual (mm) (EXP - CONTROl)' figname_anom = '{0}/diff_anom_{1}_p.png'.format(directory, y) # 10
print " === OUTPUT DIR: {0} ===\n".format(outdir) # Limites do mapa para fazer o plot # y1, y2, x1, x2 = -40., 40., -150., 70. # Globo # y1, y2, x1, x2 = -89., 89., -178., 178. # Globo y1, y2, x1, x2 = -60., 15., -90., -30. # América do sul ########## Apenas um plot ########## lev = [0., 50., 100., 200., 300., 500., 700., 900., 1000.] my_colors = ('#ffffff', '#E5E5E5', '#CBCBCB', '#B2B2B2', '#989898', '#7F7F7F', '#666666', '#4E4E4E') #8 figtitle = u'ECHAM4.6 - Precip Acum (mm)' figname = "{5}/bra_precip_persistida_{0}_{1}-{2}_{3}_{4}_echam46_1dg_null_precip_median.png" \ .format(hind_period_name, target_year, target_months, fcst_year, n_fcst_month, outdir) pm.plotmap(fcst[0, :, :], newlats-1./2., newlons-1./2., latsouthpoint=-88., latnorthpoint=88., lonwestpoint=-178., loneastpoint=178., fig_name=figname, fig_title=figtitle, barcolor=my_colors, ocean_mask=0, barlevs=lev, barinf='max', barloc='bottom', meridians=np.arange(-160., 161., 30.), parallels=np.arange(-90., 91., 20.)) ########## Anomalia corrigida metódo do Caio (regressão linear) ########## below, normal, above, f_signal, f_std, o_pad, fcst_sig_anom = cs.compute_probability(fcst, hind, obs, n_years) hind_corrigido = cs.compute_setrighthind(hind, obs, n_years) anomaly_corrigida, anomaly_pad = cs.compute_anomaly(fcst_sig_anom, hind_corrigido) #~ figtitle = u'ECHAM4.6 x CMAP - OCT/{4} - {1}/{4}\nAnomaly (mm) - Precip Accum ({2})'\ figtitle = u'ECHAM4.6 x CMAP - {0}/{3} - {1}/{4}\nAnomalia (mm) - Precip Acum ({2})'\ .format(fcst_month_name, target_months, hind_period_name, fcst_year, target_year) figname_anom = "{5}/bra_precip_persistida_{0}_{1}-{2}_{3}_{4}_echam46_1dg_null_anom_median.png" \ .format(hind_period_name, target_year, target_months, fcst_year, n_fcst_month, outdir) levs = (-700., -500., -300., -100., -50., -30., 30., 50., 100., 300., 500., 700.) #12 my_colors = ('#340003', '#ae000c', '#ff2e1b', '#ff5f26', '#ff9d37', '#fbe78a', '#ffffff', '#b0f0f7', '#93d3f6', '#76bbf3', '#4ba7ef', '#3498ed', '#2372c9') #13 pm.plotmap(anomaly_corrigida[0, :, :], newlats-1./2., newlons-1./2., latsouthpoint=y1, latnorthpoint=y2,
print clim_pcp_obs.shape clim_obs_data.close() # clim_pcp_obs_aux, lons_clim_aux = shiftgrid(180., clim_pcp_obs, lons, start=False) mytercis, tercilinf, tercilupp = cs.tercil_verification(clim_pcp_obs, pcp_obs) print mytercis.shape lons -= 1./2. lats -= 1./2. # Plot precip acumulada lev = [0., 50., 100., 200., 300., 500., 700., 900., 1000.] my_colors = ('#CC3333', '#FF6633', '#FF9933', '#FFFF99', '#FFFFCC', '#CCFFCC', '#99FFCC', '#66FF66', '#00CC00', '#009900', '#003300') #11 pm.map_shaded(pcp_obs, lats, lons, meridians=np.arange(-160., 161., 10.), fig_name="cmap.merge.funceme.fma.2015.accum.1dg.png", barlevs=lev, barcolor=my_colors, latsouthpoint=-60., latnorthpoint=15., fig_title="CMAP/FUNCEME - FMA 2015 - ACUM", lonwestpoint=-90., loneastpoint=-30., barinf="max", ocean_mask=1) # Plot categorias lev = [-1, 0., 1., 2.] my_colors = ('#F75026', '#57F255', '#4143F2') pm.map_shaded_tercis(mytercis, lats, lons, meridians=np.arange(-160., 161., 10.), fig_name="cmap.merge.funceme.fma.2015.catobs.1dg.png", barlevs=lev, barcolor=my_colors, latsouthpoint=-60., latnorthpoint=15., fig_title="CMAP/FUNCEME - FMA 2015 - CAT OBS", lonwestpoint=-90., loneastpoint=-30., ocean_mask=1) # Tercil inferior