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
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,
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,
# 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