当前位置: 首页>>代码示例>>Python>>正文


Python basemap.maskoceans函数代码示例

本文整理汇总了Python中mpl_toolkits.basemap.maskoceans函数的典型用法代码示例。如果您正苦于以下问题:Python maskoceans函数的具体用法?Python maskoceans怎么用?Python maskoceans使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了maskoceans函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calc_ratio

def calc_ratio(fsoil_mary, fsoil_kettle):
    lon, lat, topo = sp.parse_STEM_coordinates(
        os.path.join(os.environ['SARIKA_INPUT'], 'TOPO-124x124.nc'))
    fsoil_mary = maskoceans(lon, lat, fsoil_mary)
    fsoil_kettle = maskoceans(lon, lat, fsoil_kettle)
    ratio = ma.masked_invalid(fsoil_kettle) / ma.masked_invalid(fsoil_mary)
    return(ratio)
开发者ID:Timothy-W-Hilton,项目名称:COS_Spatial_Analyses,代码行数:7,代码来源:mary_soil_model.py

示例2: main

def main(base_folder="/skynet3_rech1/huziy/veg_fractions/",
         fname="pm1983120100_00000000p", canopy_name="Y2C", label="USGS",
         depth_to_bedrock_name="8L"
         ):
    data_path = os.path.join(base_folder, fname)
    r = RPN(data_path)

    veg_fractions = r.get_2D_field_on_all_levels(name=canopy_name)
    print(list(veg_fractions.keys()))
    sand = r.get_first_record_for_name("SAND")
    clay = r.get_first_record_for_name("CLAY")

    dpth_to_bedrock = r.get_first_record_for_name(depth_to_bedrock_name)

    proj_params = r.get_proj_parameters_for_the_last_read_rec()

    lons, lats = r.get_longitudes_and_latitudes_for_the_last_read_rec()
    print(lons.shape)

    rll = RotatedLatLon(lon1=proj_params["lon1"], lat1=proj_params["lat1"],
                        lon2=proj_params["lon2"], lat2=proj_params["lat2"])

    lon0, lat0 = rll.get_true_pole_coords_in_rotated_system()
    plon, _ = rll.get_north_pole_coords()

    b = Basemap(projection="rotpole", llcrnrlon=lons[0, 0], llcrnrlat=lats[0, 0],
                urcrnrlon=lons[-1, -1], urcrnrlat=lats[-1, -1], lon_0=lon0 - 180,
                o_lon_p=lon0, o_lat_p=lat0)

    lons[lons > 180] -= 360
    for lev in list(veg_fractions.keys()):
        veg_fractions[lev] = maskoceans(lons, lats, veg_fractions[lev], inlands=False)

    sand = maskoceans(lons, lats, sand)
    clay = maskoceans(lons, lats, clay)
    dpth_to_bedrock = maskoceans(lons, lats, dpth_to_bedrock)

    x, y = b(lons, lats)
    plot_veg_fractions(x, y, b, veg_fractions, out_image=os.path.join(base_folder,
                                                                      "veg_fractions_{0}.jpeg".format(label)))
    plot_sand_and_clay(x, y, b, sand, clay, out_image=os.path.join(base_folder,
                                                                   "sand_clay_{0}.jpeg".format(label)))

    # set relation between vegetation frsction fields and names
    veg_fract_dict = {}
    for lev, the_field in veg_fractions.items():
        lev = int(lev)
        if lev not in y2c_level_to_title:
            continue
        veg_fract_dict[y2c_level_to_title[lev]] = the_field

    data = {
        "SAND": sand, "CLAY": clay, "BDRCK_DEPTH": dpth_to_bedrock
    }
    data.update(veg_fract_dict)

    return b, lons, lats, data, label
开发者ID:guziy,项目名称:RPN,代码行数:57,代码来源:plot_veg_fractions.py

示例3: get_mask

def get_mask(arr, lats=None, lons=None, masknan=True, maskocean=False, maskland=False):
    '''
        Return array which is a mask for the input array
        to mask the ocean or land you need to put in the lats, lons of the data
    '''
    mask=np.zeros(np.shape(arr),dtype=np.bool)
    if masknan:
        mask=np.isnan(arr)
    if maskocean or maskland:
        if len(np.shape(lats)) == 1:
            lons,lats = np.meshgrid(lons,lats)
    if maskocean:
        mask = mask + maskoceans(lons,lats,arr, inlands=False).mask
    if maskland:
        mask = mask + ~(maskoceans(lons,lats,arr, inlands=False).mask)
    return mask
开发者ID:jibbals,项目名称:OMI_regridding,代码行数:16,代码来源:utilities.py

示例4: ResearchRegion_surface

def ResearchRegion_surface():
    """
    在地图上画出柱表面混合比图
    :return:
    """

    fig = plt.figure(figsize=(11, 8), facecolor="white")
    # data = np.loadtxt('seasonAvr_data/SurfaceMixingRatio/1_seasonAvr.txt')
    data = np.loadtxt("allYearAvr_data/SurfaceMixingRatio/allYearAvr.txt")
    arr = np.zeros((180, 360))
    for i in range(180):
        arr[i, :] = data[179 - i, :]

    longitude = np.loadtxt("lonlat_data/longitude.txt")
    latitude = np.loadtxt("lonlat_data/latitude.txt")

    m = Basemap(llcrnrlon=70, llcrnrlat=15, urcrnrlon=138, urcrnrlat=55, projection="mill", resolution="h")
    m.drawparallels(np.arange(5.5, 90.5, 1.0), color="w", linewidth=0.5, dashes=[1, 1], labels=[0, 0, 0, 0])
    m.drawmeridians(np.arange(60.5, 181.5, 1.0), color="w", linewidth=0.5, dashes=[1, 1], labels=[0, 0, 0, 0])
    m.drawmapboundary(fill_color="0.3")
    m.readshapefile("shp/CHINA", "CHINA", drawbounds=1, color="black")

    topo = maskoceans(longitude, latitude, arr)
    im = m.pcolormesh(longitude, latitude, topo, shading="flat", cmap=plt.cm.jet, latlon=True, vmin=0, vmax=500)
    m.drawlsmask(ocean_color="w", lsmask=0)

    cbar = m.colorbar()
    cbar.ax.set_ylabel("SurfaceMixingRatio", color="black", fontsize="14", rotation=90)
    plt.show()
开发者ID:wuliangradi,项目名称:RemoteSensing,代码行数:29,代码来源:plotImg.py

示例5: main

def main():

    # create the image folder if necessary
    img_folder = "bulk_field_capacity_model"
    if not os.path.isdir(img_folder):
        os.mkdir(img_folder)

    data, lons, lats, bmp = get_data_and_coords()
    lons[lons > 180] -= 360
    print(list(data.keys()))

    # reproject coords
    x, y = bmp(lons, lats)

    clevs = np.arange(0, 0.5, 0.02)
    cmap = cm.get_cmap("rainbow", lut=len(clevs))
    # plot for all levels right away
    for lev, field in data.items():
        fig = plt.figure()
        plt.title(r"$\theta_{\rm fc}$, " + "soil lev = {}".format(lev))
        to_plot = maskoceans(lons, lats, field, inlands=True)
        img = bmp.contourf(x, y, to_plot, levels=clevs, cmap=cmap)
        bmp.colorbar(img)

        bmp.drawcoastlines()

        print("lev={}, fc-min={}, fc-max={}".format(lev, field.min(), field.max()))

        fname = "thfc_lev_{}.png".format(lev)
        fig.savefig(os.path.join(img_folder, fname))
        plt.close(fig)
开发者ID:guziy,项目名称:RPN,代码行数:31,代码来源:plot_soil_field_capacity_liq.py

示例6: plot_for_simulation

def plot_for_simulation(axis=None, sim_path="", cmap=None, cnorm=None,
                        start_year=None, end_year=None, months=None):
    """
    plot a panel for each simulation

    :param axis:
    :param sim_path:
    :param cmap:
    :param cnorm:
    """

    if months is None:
        months = list(range(1, 13))

    lons, lats, bm = analysis.get_basemap_from_hdf(sim_path)

    params = dict(
        path1=sim_path, path2=sim_path,
        start_year=start_year, end_year=end_year,
        varname1="I1", level1=0,
        varname2="AV", level2=0,
        months=months
    )

    corr, i1_clim, av_clim = calculate_correlation_field_for_climatology(**params)

    # convert longitudes to the [-180, 180] range
    lons[lons > 180] -= 360
    corr = maskoceans(lons, lats, corr)

    x, y = bm(lons, lats)

    im = bm.pcolormesh(x, y, corr, norm=cnorm, cmap=cmap, ax=axis)
    bm.drawcoastlines()
    return im, corr
开发者ID:guziy,项目名称:RPN,代码行数:35,代码来源:compare_soil_moisture_latent_heat_correlations.py

示例7: latlonggrid

def latlonggrid(longmin, longmax, latmin, latmax, step, **kwargs):
    """ Produce a dense grid suitable for drawing climate maps -- land areas only.
    
    The number of grid points per degree is the same for longitude and latitude at the equator.
    Away from the equator, we thin it out a bit more to keep the number of grid points
    per kilometer roughhly constant.
    
    Parameters --
    longmin -- minimum longtiude
    longmax -- maximum longtiude
    latmin -- minimum latitude
    latmax -- maximum latitude
    step -- The number of grid points per degree for latitude and for longitude at the equator.
    """
    llgrid = pd.DataFrame(
        [
            [lat / step, long / step / cos(pi * lat / step / 180)]
            for lat in range(latmin * step, latmax * step + 1)
            for long in range(
                floor(longmin * step * cos(pi * lat / step / 180)), floor(longmax * step * cos(pi * lat / step / 180))
            )
        ],
        columns=["lat", "long"],
    )

    masked = maskoceans(llgrid.long, llgrid.lat, llgrid.index.get_level_values(0), **kwargs)
    return llgrid[masked.mask == False]
开发者ID:lpriccio,项目名称:noaa,代码行数:27,代码来源:noaa_analysis.py

示例8: __plot_timings

    def __plot_timings(prefix, show_cb=False, row=0, col=0, the_storage=None):
        _dates = ds["{}_dates.month".format(prefix)][:]

        ax = fig.add_subplot(gs[row, col])

        if the_storage is not None:
            _dates = _dates.where(~np.isnan(the_storage))
            _dates = np.ma.masked_where(the_storage.mask, _dates)

        _dates = maskoceans(lons2d_, lats2d, _dates)

        cs = bmap.pcolormesh(xx, yy, _dates, norm=norm_timings, cmap=cmap_timings)
        cb = bmap.colorbar(cs, location="bottom", format=FuncFormatter(__timing_cb_format_ticklabels))

        if show_cb:
            cb.ax.set_xlabel("month")

            maj_locator = cb.ax.xaxis.get_major_locator()


            print("old tick locs = {}".format(maj_locator.locs))
            maj_locator.locs = __get_new_tick_locs_middle(maj_locator.locs, len(clevs_timings) - 1, shift_direction=-1)
            print("new tick locs = {}".format(maj_locator.locs))


            for tick_line in cb.ax.xaxis.get_ticklines():
                tick_line.set_visible(False)

        cb.ax.set_visible(show_cb)
        ax.set_title("{} timing".format(prefix))
        axes.append(ax)
开发者ID:guziy,项目名称:RPN,代码行数:31,代码来源:calculate_flood_storage.py

示例9: plot_only_vegetation_fractions

def plot_only_vegetation_fractions(
        data_path="/RESCUE/skynet3_rech1/huziy/geof_lake_infl_exp/geophys_Quebec_0.1deg_260x260_with_dd_v6_with_ITFS",
        canopy_name="VF", label="QC_10km"):
    r = RPN(data_path)

    veg_fractions = r.get_2D_field_on_all_levels(name=canopy_name)
    print(list(veg_fractions.keys()))

    proj_params = r.get_proj_parameters_for_the_last_read_rec()

    lons, lats = r.get_longitudes_and_latitudes_for_the_last_read_rec()
    print(lons.shape)

    rll = RotatedLatLon(lon1=proj_params["lon1"], lat1=proj_params["lat1"],
                        lon2=proj_params["lon2"], lat2=proj_params["lat2"])

    lon0, lat0 = rll.get_true_pole_coords_in_rotated_system()
    plon, _ = rll.get_north_pole_coords()

    b = Basemap(projection="rotpole", llcrnrlon=lons[0, 0], llcrnrlat=lats[0, 0],
                urcrnrlon=lons[-1, -1], urcrnrlat=lats[-1, -1], lon_0=lon0 - 180,
                o_lon_p=lon0, o_lat_p=lat0)

    lons[lons > 180] -= 360
    for lev in list(veg_fractions.keys()):
        veg_fractions[lev] = maskoceans(lons, lats, veg_fractions[lev], inlands=False)

    x, y = b(lons, lats)
    plot_veg_fractions(x, y, b, veg_fractions, out_image=os.path.join(os.path.dirname(data_path),
                                                                      "veg_fractions_{0}.png".format(label)))
开发者ID:guziy,项目名称:RPN,代码行数:30,代码来源:plot_veg_fractions.py

示例10: __init__

 def __init__(self, filename):
     nc = Dataset(filename)
     self.debug_mode = 1.
     print self.debug_mode
     self.dt = nc.variables["time"][1]-nc.variables["time"][0]
     self.xlon = nc.variables["xlon"][:]
     self.xlat = nc.variables["xlat"][:]
     N_lon = self.xlon.shape[1]
     N_lat = self.xlat.shape[0]
     #self.idx_to_lon = interp1d(numpy.arange(N_lon), self.xlon[0,:])
     #self.idx_to_lat = interp1d(numpy.arange(N_lat), self.xlat[:,0])
     self.idx_to_lon = interp2d(numpy.arange(N_lon), numpy.arange(N_lat), self.xlon)
     self.idx_to_lat = interp2d(numpy.arange(N_lon), numpy.arange(N_lat), self.xlat)
     self.left = self.xlon.min()
     self.right = self.xlon.max()
     self.bottom = self.xlat.min()+18
     self.top = self.xlat.max()-8
     self.m = Basemap(llcrnrlon=self.left,
                      llcrnrlat=self.bottom,
                      urcrnrlon=self.right,
                      urcrnrlat=self.top,
                      projection='cyl', resolution='l')
     self.ocean_mask = maskoceans(self.xlon, self.xlat, self.xlon).mask
     self.time_min = 0.
     self.time_max = 0.
     self.no_ingested = 0
     self.masks = numpy.empty((0,)+self.ocean_mask.shape)
     self.tc_table = numpy.empty((0,5))
     self.time = numpy.empty((0,))
开发者ID:fuentesfranco,项目名称:kyklop,代码行数:29,代码来源:kyklop.py

示例11: plot_swe_bfes

def plot_swe_bfes(runconfig_rea, runconfig_gcm, vname_model="I5", season_to_months=None,
                  bmp_info=None, axes_list=None):

    seasonal_clim_fields_rea = analysis.get_seasonal_climatology_for_runconfig(run_config=runconfig_rea,
                                                                               varname=vname_model, level=0,
                                                                               season_to_months=season_to_months)

    seasonal_clim_fields_gcm = analysis.get_seasonal_climatology_for_runconfig(run_config=runconfig_gcm,
                                                                               varname=vname_model, level=0,
                                                                               season_to_months=season_to_months)

    lons = bmp_info.lons.copy()
    lons[lons > 180] -= 360

    assert len(seasonal_clim_fields_rea) > 0
    season_to_err = OrderedDict()
    for season, field in seasonal_clim_fields_rea.items():
        rea = field
        gcm = seasonal_clim_fields_gcm[season]

        # Mask oceans and lakes

        season_to_err[season] = maskoceans(lons, bmp_info.lats, gcm - rea)
        assert hasattr(season_to_err[season], "mask")

    plot_performance_err_with_cru.plot_seasonal_mean_biases(season_to_error_field=season_to_err,
                                                            varname=vname_model, basemap_info=bmp_info,
                                                            axes_list=axes_list)
开发者ID:guziy,项目名称:RPN,代码行数:28,代码来源:plot_swe_pe_and_bfe.py

示例12: compare_vars

def compare_vars(vname_model, vname_to_obs, r_config, season_to_months, bmp_info_agg, axes_list):
    season_to_clim_fields_model = analysis.get_seasonal_climatology_for_runconfig(run_config=r_config,
                                                                                  varname=vname_model, level=0,
                                                                                  season_to_months=season_to_months)

    for season, field in season_to_clim_fields_model.items():
        print(field.shape)
        if vname_model == "PR":
            field *= 1.0e3 * 24 * 3600

    seasonal_clim_fields_obs = vname_to_obs[vname_model]

    lons = bmp_info_agg.lons.copy()
    lons[lons > 180] -= 360

    season_to_err = OrderedDict()
    for season in seasonal_clim_fields_obs:
        season_to_err[season] = season_to_clim_fields_model[season] - seasonal_clim_fields_obs[season]
        season_to_err[season] = maskoceans(lons, bmp_info_agg.lats, season_to_err[season], inlands=False)

    cs = plot_seasonal_mean_biases(season_to_error_field=season_to_err,
                                   varname=vname_model,
                                   basemap_info=bmp_info_agg,
                                   axes_list=axes_list)

    return cs
开发者ID:guziy,项目名称:RPN,代码行数:26,代码来源:plot_performance_err_with_anusplin_rb_tt_pr_swe.py

示例13: __plot_storage

    def __plot_storage(prefix, show_cb=False, row=0, col=0, plot_deviations=True):

        if plot_deviations:
            clevs = [0, 1e3, 1e4, 1e5, 1.0e6, 1e7, 1e8, 1.0e9]
            clevs = [-c for c in reversed(clevs)][:-1] + clevs
            cmap = cm.get_cmap("bwr", len(clevs) - 1)
        else:
            clevs = [0, 1e3, 1e4, 1e5, 1.0e6, 1e7, 1e8, 1.0e9]
            cmap = cm.get_cmap("YlGnBu", len(clevs) - 1)

        norm = BoundaryNorm(boundaries=clevs, ncolors=len(clevs) - 1)

        _storage = ds["{}_{}".format(prefix, storage_var_name)][:]
        ax = fig.add_subplot(gs[row, col])
        _storage = _storage.where(_storage > storage_lower_limit_m3)
        _storage = maskoceans(lons2d_, lats2d, _storage)
        _storage = np.ma.masked_where(np.isnan(_storage), _storage)


        if plot_deviations:
            cs = bmap.pcolormesh(xx, yy, _storage - bankfull_storage, norm=norm, cmap=cmap)
        else:
            cs = bmap.pcolormesh(xx, yy, _storage, norm=norm, cmap=cmap)


        ext = "both" if plot_deviations else "max"


        cb = bmap.colorbar(cs, location="bottom", format=FuncFormatter(__storage_cb_format_ticklabels), extend=ext)
        cb.ax.set_visible(show_cb)
        cb.ax.set_xlabel(r"${\rm m^3}$")
        ax.set_title(prefix)
        axes.append(ax)
        return _storage
开发者ID:guziy,项目名称:RPN,代码行数:34,代码来源:calculate_flood_storage.py

示例14: plotKoppen

def plotKoppen(Dict):
    """
    Plot a map of the Koppen climate zones used in the correlation analysis.
    """
    m

    empty = np.zeros((27,22))

    empty[23:,14:] = 1.0 #equatorial
    empty[19:23,14:] = 2.0 #tropical
    empty[10:19,16:] = 3.0 #subtropical
    empty[9:17,14:15] = 4.0 #desert

    empty[17:19,14:15] = 5.0#grass1
    empty[17:19,15:16] = 5.0 #grass2
    empty[4:17,15:16] = 5.0 #grass3
    empty[4:9,14:15] = 5.0 #grass4

    empty[4:10,16:] = 6.0 #temperate1
    empty[:4,14:20] = 6.0 #temperate2

    [lonall,latall] = np.meshgrid((Dict['lon']),(Dict['lat']))
    x,y = m(lonall,latall)

    eastern_Aus = maskoceans(lonall,latall,empty)
    eastern_Aus = np.ma.masked_where(eastern_Aus == 0.0,eastern_Aus)
    cs = m.pcolor(x,y,eastern_Aus)
    plt.title("Climate zones in eastern Australia")
    plt.show()
    return eastern_Aus
开发者ID:sonyawellby,项目名称:anu_honours,代码行数:30,代码来源:plot.py

示例15: plot_field_2d

def plot_field_2d(lons_2d, lats_2d, field_2d, start_lon = -180, end_lon = 0, color_map = None,
                   minmax = (None, None)  ):


    plt.figure()
    m = Basemap(llcrnrlon = start_lon,llcrnrlat = np.min(lats_2d),
                urcrnrlon = end_lon,urcrnrlat = np.max(lats_2d), resolution = 'l')

    m.drawmeridians(range(start_lon,end_lon,10))
    m.drawparallels(range(-90,90,10))


 #   y, x = meshgrid(lats_2d, lons_2d)
#    lons_2d[lons_2d < start_lon] = lons_2d[lons_2d < start_lon] + 360
    x, y = m(lons_2d, lats_2d)


    x -= 360 ###########CONVERTING LONGITUDE TO -180:180
    field_2d = maskoceans(x, y, field_2d)


    m.pcolormesh(x, y, field_2d, cmap = color_map, vmin = minmax[0], vmax = minmax[1])
    m.drawcoastlines()
    #plt.imshow(np.transpose(data[:,:]), origin = 'lower') #for plotting in order to see i,j we supply j,i
    numticks = color_map.N + 1 if color_map != None else 10
    plt.colorbar(ticks = LinearLocator(numticks = numticks), format = '%.01f',
                 orientation = 'vertical', shrink = 0.6)
开发者ID:guziy,项目名称:RPN,代码行数:27,代码来源:test_rpn.py


注:本文中的mpl_toolkits.basemap.maskoceans函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。