Beispiel #1
0
def hovmoller(array, lat_array, lon_array, latmin, latmax, lonmin,
              lonmax, mean):

    """Calcula a media meridional ou zonal
    :param array:
    :param lat_array:
    :param lon_array:
    :param latmin:
    :param latmax:
    :param lonmin:
    :param lonmax:
    :param mean:
    """

    latmin, lonmin, ilatmin, ilonmin = Dg.gridpoint(lat_array, lon_array,
                                                    latmin, lonmin)
    latmax, lonmax, ilatmax, ilonmax = Dg.gridpoint(lat_array, lon_array,
                                                    latmax, lonmax)

    lat = lat_array[ilatmin:ilatmax + 1]
    lon = lon_array[ilonmin:ilonmax + 1]

    if mean == 'lat':
        hov = np.nanmean(array[:, ilatmin:ilatmax + 1, ilonmin:ilonmax + 1],
                         axis=1)
    elif mean == 'lon':
        hov = np.nanmean(array[:, ilatmin:ilatmax + 1, ilonmin:ilonmax + 1],
                         axis=2)

    return hov, lat, lon
def cut2region(indata, inlat, inlon, minlat, minlon, maxlat, maxlon):
    """Cut input data to the region of interest

    :param indata: 3d data array that will be cut
    :type indata: numpy array
    :param inlat: 1d lat array that will be latitude
    :type inlat: numpy array
    :param inlon: 1d lon array that will be longitude
    :type inlon: numpy array
    :param minlat: value of the minimun latitude
    :type minlat: float
    :param minlon: value of the minimun longitude
    :type minlon: float
    :param maxlat: value of the maximum latitude
    :type maxlat: float
    :param maxlon: value of the maxium longitude
    :type maxlon: float
    :return: Return data array cut, lon array cut and lat array cut to
    the region of interest
    """

    min_lat, min_lon, min_lat_index, min_lon_index = Dg.gridpoint(inlat, inlon,
                                                                  minlat,
                                                                  minlon)
    max_lat, max_lon, max_lat_index, max_lon_index = Dg.gridpoint(inlat, inlon,
                                                                  maxlat,
                                                                  maxlon)
    cut_data = indata[..., min_lat_index:max_lat_index,
                      min_lon_index:max_lon_index]
    cut_lat = inlat[min_lat_index:max_lat_index]
    cut_lon = inlon[min_lon_index:max_lon_index]

    return cut_data, cut_lat, cut_lon
def verification_points(lat, lon):
    """
    Check whether the model grid points are contained Ceara Shape points.
    Verifica se os Pontos da Grade do Modelo estao contidos os pontos do Shape do Ceara.
    :return: points_grid_north, lonlat_grid_north, array_bool_north
             points_grid_south, lonlat_grid_south, array_bool_south
    """

    south = '/home/radar/gfs-analise/ceara_metade_de_baixo.txt'
    north = '/home/radar/gfs-analise/ceara_metade_de_cima.txt'

    points_grid_north, lonlat_grid_north, array_bool_north = defgrid.pointinside(lat, lon, north)
    points_grid_south, lonlat_grid_south, array_bool_south = defgrid.pointinside(lat, lon, south)

    return points_grid_north, lonlat_grid_north, array_bool_north, points_grid_south, lonlat_grid_south, array_bool_south
Beispiel #4
0
def caso_shape(data, lat, lon, shp):

    shapeurl = "http://opendap2.funceme.br:8001/data/utils/shapes/{0}".format(
        shp)
    line = re.sub('[/]', ' ', shapeurl)
    line = line.split()
    Ptshape = '/tmp/' + line[-1]
    shpn = line[-2].title()
    if not os.path.exists(Ptshape):
        Ptshape = wget.download(shapeurl, '/tmp', bar=None)

    xy = np.loadtxt(Ptshape)
    xx = xy[:, 0]
    yy = xy[:, 1]

    plt.plot(xx, yy, color='k', linewidth=1.0)
    plt.show()

    plt.savefig('Contorno_{0}.png'.format(shpn))
    plt.close()

    shpn = line[-2].title()

    # Quando lon de 0:360 mudando para -180:180
    if not np.any(lon < 0): lon = np.where(lon > 180, lon - 360, lon)

    # PONTOS DO POLIGONO QUE SERA MASCARADO
    Ptsgrid, lonlatgrid, Ptmask = Dg.pointinside(lat, lon, shapefile=Ptshape)

    # APLICANDO MASCARA DO POLIGONO NO DADO DE ENTRADA
    VarMasked_data = np.ma.array(
        data[:, :, :], mask=np.tile(Ptmask,
                                    (data.shape[0], 1)))  # Array masked

    return VarMasked_data
Beispiel #5
0
    background = Image.open(figname_anom)
    foreground = Image.open("/home/marcelo/FSCT-ECHAM46/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}_median.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 = cs.compute_probability(fcst, hind, obs, n_years)
    cn.create_netcdf_probs(below, normal, above, newlats, newlons, fileout=file_out)

    ##########  Curva para o CE  ##########
    # Retorna matriz com os pontos sobre o Ceará
    shapef = '/home/marcelo/FSCT-ECHAM46/pontos_ce.txt'
    pointsgrid, lonlatgrid, mymatriz = dg.pointinside(newlats, newlons, shapefile=shapef)

    # Aplica máscara para os pontos sobre o Ceará
    points_over_ce_fcst = np.ma.array(fcst[0, :, :], mask=mymatriz)
    points_over_ce_hind = np.ma.array(hind, mask=np.tile(mymatriz, (hind.shape[0], 1)))
    points_over_ce_obs = np.ma.array(obs, mask=np.tile(mymatriz, (obs.shape[0], 1)))

    mean_ce_fcst = np.zeros(1)
    mean_ce_hind = np.zeros(int(n_years))
    mean_ce_obs = np.zeros(int(n_years))

    mean_ce_fcst[0] = points_over_ce_fcst.mean()

    for i in range(0, int(n_years)):
        mean_ce_hind[i] = points_over_ce_hind[i, :, :].mean()
        mean_ce_obs[i] = points_over_ce_obs[i, :, :].mean()
Beispiel #6
0
esi_st = []
spi_st = []

for year in range(2003, 2015 + 1):

    for month in mes_esi:

        print year, month

        # Declaring variables
        name1 = 'esi_4WK_SMN_{0:04d}_SA.nc'.format(year)
        data1 = netCDF4.Dataset(str(path_in1) + name1)
        lat = data1.variables['latitude'][:]  # Declaring latitude
        lon = data1.variables['longitude'][:]  # Declaring longitude

        min_lat, min_lon, min_lat_index, min_lon_index = Dg.gridpoint(
            lat, lon, -22., -48.0)
        max_lat, max_lon, max_lat_index, max_lon_index = Dg.gridpoint(
            lat, lon, -6., -36.)
        lats = lat[min_lat_index:max_lat_index]
        lons = lon[min_lon_index:max_lon_index]

        aux_in1 = data1.variables['esi'][
            dic_esi[month], min_lat_index:max_lat_index, min_lon_index:
            max_lon_index]  # Declaring variable under study to calculate the thiessen aux_in
        time_esi = data1.variables['time']
        aux_in1 = np.expand_dims(aux_in1, axis=0)
        aux_in1 = ma.masked_where(aux_in1 <= -6., aux_in1)
        aux_in1 = ma.masked_where(aux_in1 >= 6., aux_in1)

        print "esi_sao_francisco"
        Dmasked1 = caso_shape(aux_in1[:, :, :], lats, lons,
Beispiel #7
0
    print season

    for ANO in range(2003, 2016 + 1):

        print ANO, dic_esi[season]

        name = 'esi_4WK_SMN_{0:4d}_SA.nc'.format(ANO)
        data = netCDF4.Dataset(str(path_in) + name)
        aux_in = data.variables['esi'][dic_esi[season], :, :]
        aux_in = np.expand_dims(aux_in, axis=0)

        lat = data.variables['latitude'][:]  # Declaring latitude
        lon = data.variables['longitude'][:]  # Declaring longitude

        min_lat, min_lon, min_lat_index, min_lon_index = Dg.gridpoint(
            lat, lon, -20., -50.0)
        max_lat, max_lon, max_lat_index, max_lon_index = Dg.gridpoint(
            lat, lon, 0., -34.)

        lats = lat[min_lat_index:max_lat_index]
        lons = lon[min_lon_index:max_lon_index]

        aux_in = data.variables['esi'][dic_esi[season],
                                       min_lat_index:max_lat_index,
                                       min_lon_index:max_lon_index]
        aux_in = np.expand_dims(aux_in, axis=0)

        aux_in = ma.masked_where(aux_in <= -6., aux_in)
        aux_in = ma.masked_where(aux_in >= 6., aux_in)

        txtbox(u'Fonte: NOAA/ESSIC and USDA-ARS\nElaboração: FUNCEME', 0.46,
Beispiel #8
0
def ProbMemb(fcst_month, fcst_year, target_year, target_months,
             hind_period, nyears, shapef, nmemb=20):

    """
    Esta função calcula a previsão (sinal) para todos
    os membros.

    :param fcst_month: mês previsão
    :type fcst_month: str

    :param fcst_year: ano do mês previsão
    :type fcst_year: str

    :param target_year: ano alvo da previsão
    :type target_year: str

    :param target_months: trimestre alvo da previsão
    :type target_months: str

    :param hind_period: período do hindcast
    :type hind_period: str

    :param nyears: número de anos do hindcast
    :type nyears: int

    :param shapef: arquivo de txt com pontos da região
    :type shapef: arquivo de txt

    :param nmemb: número de membros da preevisão/hinscast
    :type nmemb: int

    """


    #### OBSERVADO ####

    print "\n +++ LENDO A CLIMATOLOGIA OBSERVADA +++\n"

    url = 'http://opendap2.funceme.br:8001/data/dados-obs/cmap/2.5dg/' \
           'cmap.precip.season.accum.standard.2.5dg.{0}.{1}.nc' \
           .format("1981-2010", target_months)

    #~ print url

    obs_data = Dataset(url, 'r')

    obs_aux = obs_data.variables['precip'][:]

    obs_lons_360 = obs_data.variables['lon'][:]

    obs_lats = obs_data.variables['lat'][:]

    obs_data.close()

    obs_aux, obs_lons = shiftgrid(180., obs_aux, obs_lons_360, start=False)

    print " +++ INTERPOLANDO CLIMATOLOGIA OBSERVADA +++ \n"

    # Interpolação para 1 grau

    # Nova grade de 1 grau
    newlats = np.linspace(-90, 90, 181)

    newlons = np.linspace(-180, 179, 360)

    obs = np.zeros((int(obs_aux.shape[0]), int(len(newlats)), int(len(newlons))))

    x, y = np.meshgrid(newlons, newlats)

    for i in range(0, int(obs_aux.shape[0])):

        obs[i, :, :] = interp(obs_aux[i, :, :], obs_lons, obs_lats, x, y, order=1)

    #### PREVISÃO ####

    print " +++ LENDO OS MEMBROS PREVISÃO +++ \n"

    #~ Monta a url do ano da previsão com todos os membros
    url = 'http://opendap2.funceme.br:8001/data/dados-pos-processados-echam46' \
          '/forecasts/{0}/{2}/{1}/PCP/TRI/pcp-seasonacc-echam46-hind{0}-en%2.2d-{1}{2}_{3}{4}.ctl' \
          .format(hind_period, fcst_month, fcst_year, target_year, target_months)

    files = [url % d for d in range(51, 71)]

    # Inicializa array que irá receber os membros do ano da previsão
    fcst_t42 = np.zeros((20, 64, 128)) * 0

    for i, nc in enumerate(files):

        #~ print "", nc

        fcst_data = Dataset(nc, 'r')

        fcst_aux = fcst_data.variables['pcp'][:]

        fcst_lons_360 = fcst_data.variables['longitude'][:]

        fcst_lats = fcst_data.variables['latitude'][:]

        fcst_data.close()

        fcst_aux, fcst_lons = shiftgrid(180., fcst_aux, fcst_lons_360, start=False)

        fcst_t42[i, :, :] = fcst_aux[0, :, :]

    print " +++ INTERPOLANDO OS MEMBROS PREVISÃO +++ \n"

    # Interpolação para 1 grau

    # Nova grade de 1 grau

    fcst = np.zeros((20, int(len(newlats)), int(len(newlons)))) * 0

    for i in range(20):

        fcst[i, :, :] = interp(fcst_t42[i, :, :], fcst_lons, fcst_lats, x, y, order=1)

    #### HINDCAST ####

    print " +++ LENDO OS MEMBROS DE CADA ANO DO HINDCAST +++\n"

    print " ==> AGUARDE...\n"

    # Inicializa array que irá receber todos os anos e todos os membros

    hind_t42 = np.zeros((30, 20, 64, 128)) * 0

    for i, hind_year in enumerate(range(1981, 2011)):

        #~ print " ANO:", hind_year

        # Monta a url de cada ano com todos os membros
        url = 'http://opendap2.funceme.br:8001/data/dados-pos-processados-echam46' \
              '/hindcasts/{0}/{1}/PCP/TRI/pcp-seasonacc-echam46-hind{0}-en%2.2d-{1}{3}_{3}{2}.ctl' \
              .format(hind_period, fcst_month, target_months, hind_year)

        files = [url % d for d in range(51, 71)]

        # Inicializa array que irá receber os membros para cada ano
        hindmemb = np.zeros((20, 64, 128)) * 0

        for j, nc in enumerate(files):

            hind_data = Dataset(nc, 'r')

            hind_aux = hind_data.variables['pcp'][:]

            hind_lons_360 = hind_data.variables['longitude'][:]

            hind_lats = hind_data.variables['latitude'][:]

            hind_data.close()

            hind_aux, hind_lons = shiftgrid(180., hind_aux, hind_lons_360, start=False)

            hindmemb[j, :, :] = hind_aux[0, :, :]

        hind_t42[i, :, :, :] = hindmemb[:, :, :]

    print " +++ INTERPOLANDO OS ANOS DE CADA MEMBRO DO HINDCAST. +++ \n"

    print " ==> AGUARDE... \n"

    # Interpolação para 1 grau

    hind = np.zeros((30 , 20, int(len(newlats)), int(len(newlons)))) * 0

    for i in range(20):

        #~ print " MEMBRO:", i + 51

        for j in range(30):

            hind[j, i, :, :] = interp(hind_t42[j, i, :, :], hind_lons, hind_lats, x, y, order=1)

    print " +++ APLICANDO MÁSCARA DA REGIÃO +++ \n"

    # Retorna matriz com os pontos sobre o Ceará
    pointsgrid, lonlatgrid, mymatriz = dg.pointinside(newlats, newlons, shapefile=shapef)

    ce_fcst = np.ma.array(fcst, mask=np.tile(mymatriz, (fcst.shape[0], 1)))

    ce_hind = np.ma.array(hind, mask=np.tile(mymatriz, (hind.shape[0], hind.shape[1], 1)))

    ce_obs = np.ma.array(obs, mask=np.tile(mymatriz, (obs.shape[0], 1)))

    print " +++ MÉDIA DOS PONTOS SOBRE A REGIÃO PARA TODOS OS MEMBROS +++ \n"

    ave_ce_fcst = np.zeros((int(nmemb), 1)) * 0

    ave_ce_hind = np.zeros((int(nyears), int(nmemb), 1)) * 0

    ave_ce_obs = np.zeros((int(nyears), 1)) * 0

    for i in range(int(nmemb)):

        ave_ce_fcst[i, 0] = ce_fcst[i, :, :].mean()

        for j in range(int(nyears)):

            ave_ce_hind[j, i, 0] = ce_hind[j, i, :, :].mean()

    for i in range(int(nyears)):

            ave_ce_obs[i, 0] = ce_obs[i, :, :].mean()

    sig_membs_ce = np.zeros((int(nmemb))) * 0

    print " +++ CALCULANDO SINAL DA PREVISÃO PARA TODOS OS MEMBROS +++\n"

    for i in range(nmemb):
        below_ce, normal_ce, above_ce, sig_membs_ce[i], f_std_ce, \
        o_pad_ce, fcst_sig_anom = cs.compute_probability(ave_ce_fcst[i, 0],
        ave_ce_hind[:, i, 0], ave_ce_obs[:, 0], nyears)

    return sig_membs_ce
# lats = read_fcst_file.variables['lat'][:]
# 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
                   .format(fcst_month.upper(), fcst_year, target_months,
                   target_year, hind_period_name)

        pm.maptercis(file_out, figtitle, figout)

        background = Image.open(figout)
        foreground = Image.open("FUNCEME_LOGO.png")
        foreground = foreground.resize((90, 70), Image.ANTIALIAS)
        background.paste(foreground, (334, 461), foreground)
        background.save(figout, optimize=True, quality=95)

    #### Curva para o CE ####
    # Retorna matriz com os pontos sobre o Ceará
    shapef = 'pontos_ce.txt'
    pointsgrid, lonlatgrid, mymatriz = \
    dg.pointinside(newlats, newlons, shapefile=shapef)

    # Aplica máscara para os pontos sobre o Ceará
    points_over_ce_fcst = np.ma.array(fcst[0, :, :], mask=mymatriz)
    points_over_ce_hind = np.ma.array(hind, mask=np.tile(mymatriz, (hind.shape[0], 1)))
    if obs_base == 'cmap':
        points_over_ce_obs = np.ma.array(obs, mask=np.tile(mymatriz, (obs.shape[0], 1)))

    mean_ce_fcst = np.zeros(1)
    mean_ce_hind = np.zeros(int(n_years))
    if obs_base == 'cmap':
        mean_ce_obs  = np.zeros(int(n_years))

    mean_ce_fcst[0] = points_over_ce_fcst.mean()

    for i in range(0, int(n_years)):
def ProbMemb(fcst_month,
             fcst_year,
             target_year,
             target_months,
             hind_period,
             nyears,
             shapef,
             nmemb=20):
    """
    Esta função calcula a curva de probabilida a previsão (sinal)
    para todos os membros.

    :param fcst_month: Mês previsão
    :type fcst_month: str

    :param fcst_year: Ano do mês previsão
    :type fcst_year: str

    :param target_year: Ano alvo da previsão
    :type target_year: str

    :param target_months: Trimestre alvo da previsão
    :type target_months: str

    :param hind_period: Período do hindcast
    :type hind_period: str

    :param nyears: Número de anos do hindcast
    :type nyears: int

    :param shapef: Arquivo de txt com pontos da região
    :type shapef: arquivo de txt

    :param nmemb: Número de membros da preevisão/hinscast
    :type nmemb: int

    :return sig_membs_ce: Sinal da previsão para todos os membros

    """

    #### OBSERVADO ####

    print('\n +++ LENDO A CLIMATOLOGIA OBSERVADA +++\n')

    if target_year > fcst_year:

        url = 'http://opendap2.funceme.br:8001/data/dados-obs/cmap/2.5dg/' \
              'cmap.precip.season.accum.standard.2.5dg.{0}.{1}.nc' \
              .format("1982-2011", target_months)

    else:

        url = 'http://opendap2.funceme.br:8001/data/dados-obs/cmap/2.5dg/' \
              'cmap.precip.season.accum.standard.2.5dg.{0}.{1}.nc' \
              .format("1981-2010", target_months)

    print(target_year, fcst_year)

    print(url)

    obs_data = Dataset(url, 'r')

    obs_aux = obs_data.variables['precip'][:]

    obs_lons_360 = obs_data.variables['lon'][:]

    obs_lats = obs_data.variables['lat'][:]

    obs_data.close()

    obs_aux, obs_lons = shiftgrid(180., obs_aux, obs_lons_360, start=False)

    print('\n +++ INTERPOLANDO CLIMATOLOGIA OBSERVADA +++ \n')

    # Interpolação para 1 grau

    # Nova grade de 1 grau
    newlats = np.linspace(-90, 90, 181)

    newlons = np.linspace(-180, 179, 360)

    obs = np.zeros(
        (int(obs_aux.shape[0]), int(len(newlats)), int(len(newlons))))

    x, y = np.meshgrid(newlons, newlats)

    for i in range(0, int(obs_aux.shape[0])):

        obs[i, :, :] = interp(obs_aux[i, :, :],
                              obs_lons,
                              obs_lats,
                              x,
                              y,
                              order=1)

    #### PREVISÃO ####

    print(' +++ LENDO OS MEMBROS PREVISÃO +++ \n')

    #~ Monta a url do ano da previsão com todos os membros
    url = 'http://opendap2.funceme.br:8001/data/dados-pos-processados-echam46' \
          '/forecasts/{0}/{2}/{1}/PCP/TRI/pcp-seasonacc-echam46-hind{0}-en%2.2d-{1}{2}_{3}{4}.ctl' \
          .format(hind_period, fcst_month, fcst_year, target_year, target_months)

    files = [url % d for d in range(51, 71)]

    # Inicializa array que irá receber os membros do ano da previsão
    fcst_t42 = np.zeros((20, 64, 128)) * 0

    for i, nc in enumerate(files):

        print(nc)

        fcst_data = Dataset(nc, 'r')

        fcst_aux = fcst_data.variables['pcp'][:]

        fcst_lons_360 = fcst_data.variables['longitude'][:]

        fcst_lats = fcst_data.variables['latitude'][:]

        fcst_data.close()

        fcst_aux, fcst_lons = shiftgrid(180.,
                                        fcst_aux,
                                        fcst_lons_360,
                                        start=False)

        fcst_t42[i, :, :] = fcst_aux[0, :, :]

    print('\n    +++ INTERPOLANDO OS MEMBROS PREVISÃO +++ \n')

    # Interpolação para 1 grau

    # Nova grade de 1 grau

    fcst = np.zeros((20, int(len(newlats)), int(len(newlons)))) * 0

    for i in range(20):

        fcst[i, :, :] = interp(fcst_t42[i, :, :],
                               fcst_lons,
                               fcst_lats,
                               x,
                               y,
                               order=1)

    #### HINDCAST ####

    print('+++ LENDO OS MEMBROS DE CADA ANO DO HINDCAST +++\n')

    print(' ==> AGUARDE...\n')

    # Inicializa array que irá receber todos os anos e todos os membros

    hind_t42 = np.zeros((30, 20, 64, 128)) * 0

    for i, hind_year in enumerate(range(1981, 2011)):

        if target_year > fcst_year:

            target_hind_year = int(hind_year) + 1

        else:

            target_hind_year = hind_year

        # Monta a url de cada ano com todos os membros
        url = 'http://opendap2.funceme.br:8001/data/dados-pos-processados-echam46' \
              '/hindcasts/{0}/{1}/PCP/TRI/pcp-seasonacc-echam46-hind{0}-en%2.2d-{1}{3}_{4}{2}.ctl' \
              .format(hind_period, fcst_month, target_months, hind_year, target_hind_year)

        files = [url % d for d in range(51, 71)]

        # Inicializa array que irá receber os membros para cada ano
        hindmemb = np.zeros((20, 64, 128)) * 0

        for j, nc in enumerate(files):

            print(nc)

            hind_data = Dataset(nc, 'r')

            hind_aux = hind_data.variables['pcp'][:]

            hind_lons_360 = hind_data.variables['longitude'][:]

            hind_lats = hind_data.variables['latitude'][:]

            hind_data.close()

            hind_aux, hind_lons = shiftgrid(180.,
                                            hind_aux,
                                            hind_lons_360,
                                            start=False)

            hindmemb[j, :, :] = hind_aux[0, :, :]

        hind_t42[i, :, :, :] = hindmemb[:, :, :]

    print('\n +++ INTERPOLANDO OS ANOS DE CADA MEMBRO DO HINDCAST +++ \n')

    print(' ==> AGUARDE... \n')

    # Interpolação para 1 grau

    hind = np.zeros((30, 20, int(len(newlats)), int(len(newlons)))) * 0

    for i in range(20):

        for j in range(30):

            hind[j, i, :, :] = interp(hind_t42[j, i, :, :],
                                      hind_lons,
                                      hind_lats,
                                      x,
                                      y,
                                      order=1)

    print(' +++ APLICANDO MÁSCARA DA REGIÃO +++ \n')

    # Retorna matriz com os pontos sobre o Ceará
    pointsgrid, lonlatgrid, mymatriz = dg.pointinside(newlats,
                                                      newlons,
                                                      shapefile=shapef)

    ce_fcst = np.ma.array(fcst, mask=np.tile(mymatriz, (fcst.shape[0], 1)))

    ce_hind = np.ma.array(hind,
                          mask=np.tile(mymatriz,
                                       (hind.shape[0], hind.shape[1], 1)))

    ce_obs = np.ma.array(obs, mask=np.tile(mymatriz, (obs.shape[0], 1)))

    print(' +++ MÉDIA DOS PONTOS SOBRE A REGIÃO PARA TODOS OS MEMBROS +++ \n')

    ave_ce_fcst = np.zeros((int(nmemb), 1)) * 0

    ave_ce_hind = np.zeros((int(nyears), int(nmemb), 1)) * 0

    ave_ce_obs = np.zeros((int(nyears), 1)) * 0

    for i in range(int(nmemb)):
        ave_ce_fcst[i, 0] = ce_fcst[i, :, :].mean()
        for j in range(int(nyears)):
            ave_ce_hind[j, i, 0] = ce_hind[j, i, :, :].mean()

    for i in range(int(nyears)):
        ave_ce_obs[i, 0] = ce_obs[i, :, :].mean()

    print(' +++ CALCULANDO SINAL DA PREVISÃO PARA TODOS OS MEMBROS +++\n')

    sig_membs_ce = np.empty((int(nmemb)))

    sig_membs_ce[:] = np.nan

    for i in range(nmemb):
        below_ce, normal_ce, above_ce, sig_membs_ce[i], f_std_ce, \
        o_pad_ce, fcst_sig_anom = compute_probability(ave_ce_fcst[i, 0],
        ave_ce_hind[:, i, 0], ave_ce_obs[:, 0], nyears)

    return sig_membs_ce
    except:

        print "\n === Erro ao abrir arquivo observado ===\n"
        exit(1)

    # Interpola obs
    obs = np.zeros((int(obs_aux.shape[0]), int(len(lats1)), int(len(lons1))))
    for i in range(0, int(obs_aux.shape[0])):
        obs[i, :, :] = interp(obs_aux[i, :, :], obs_lons, obs_lats, x, y, order=1)

    return fcst, hind, obs


if myopt == "p":

    n_lon, n_lat, i_lon, i_lat = dg.gridpoint(lons1, lats1, mylon, mylat)

    n_lon = str(n_lon)
    n_lon = n_lon.replace(".", "")
    n_lat = str(n_lat)
    n_lat = n_lat.replace(".", "")

    figrealname = "img/curve_prob_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}.png".format(
        n_lon, n_lat, myopt, myhind, myfmon, mytseason, myfyear, mytyear
    )

    mylon = str(mylon)
    mylon = mylon.replace(".", "")
    mylat = str(mylat)
    mylat = mylat.replace(".", "")
                fcst_month.upper(), fcst_year, target_months, target_year, hind_period_name, obs_base.upper()
            )

            pm.maptercisrsm97(file_out, figtitle, figout, maskocean=1)

            background = Image.open(figout)
            foreground = Image.open("FUNCEME_LOGO.png")
            foreground = foreground.resize((90, 70), Image.ANTIALIAS)
            background.paste(foreground, (bx, by), foreground)
            background.save(figout, optimize=True, quality=95)

        ##########  Curva para o CE  ##########
        # Retorna matriz com os pontos sobre o Ceará
        # shapef = 'pontos_ce.txt'
        # TODO: Usar Thiessen
        pointsgrid, lonlatgrid, mymatriz = dg.pointinside(fcst_lats, fcst_lons, shapefile="pontos_ce.txt")

        # Aplica máscara para os pontos sobre o Ceará
        points_over_ce_fcst = np.ma.array(fcst, mask=mymatriz)
        mean_ce_fcst = np.zeros(1)
        mean_ce_fcst[0] = points_over_ce_fcst.mean()

        points_over_ce_hind = np.ma.array(hind, mask=np.tile(mymatriz, (hind.shape[0], 1)))

        mean_ce_hind = np.zeros(int(n_years))
        if obs_base == "inmet" or obs_base == "chirps" or obs_base == "cru":
            points_over_ce_obs = np.ma.array(obs, mask=np.tile(mymatriz, (obs.shape[0], 1)))
            mean_ce_obs = np.zeros(int(n_years))

        for i in range(0, int(n_years)):
            mean_ce_hind[i] = points_over_ce_hind[i, :, :].mean()