# clim_obs_path = "/Users/Hulk/FSCT-ECHAM46/obs_data/cmap/CMAP.glb.89-08-FMA-1.0dg.nc"
clim_obs_path = "/Users/Hulk/obs_pcp/cmap.precip.mean.enhanced.1989-2008.FMA.nc3.nc"
clim_obs_data = pupynere.NetCDFFile(clim_obs_path, 'r')
# clim_pcp_obs = clim_obs_data.variables['pcp'][:]
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.),
lats = obs_data.variables['lat'][:]
obs_data.close()
pcp_obs = np.mean(pcp_obs, axis=0)
# pcp_obs_aux, lons_obs_aux = shiftgrid(180., pcp_obs, lons, start=False)


obs_path = "/Users/Hulk/clim-verification/CMAP/CMAP89-08-FMA-T42.nc"
clim_obs_path = "/Users/Hulk/obs_pcp/cmap/cmap.merge.funceme.precip.standard.FMA.season.accum.1dg.nc"
clim_obs_data = pupynere.NetCDFFile(clim_obs_path, 'r')
print clim_obs_data.variables
clim_pcp_obs = clim_obs_data.variables['precip'][:]
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)