python salem 掩膜提取

2021-10-09 13:27:53 字數 3468 閱讀 2996

import xarray as xr

import numpy as np

from xarray.backends import netcdf4datastore

import salem

from datetime import datetime

from siphon.catalog import tdscatalog

import cartopy.crs as ccrs

import cartopy.feature as cfeat

from cartopy.mpl.ticker import longitudeformatter,latitudeformatter

from cartopy.io.shapereader import reader, natural_earth

import matplotlib.pyplot as plt

import matplotlib.ticker as mticker

import geopandas

best_gfs = tdscatalog(

'''global_0p25deg/catalog.xml?dataset=grib/ncep/gfs/global_0p25deg/best'

)ncss = best_gfs.datasets[0]

.subset(

)query = ncss.query(

)query.lonlat_box(north=

50, south=

0, east=

150, west=90)

.time(datetime.utcnow())

query.variables(

'temperature_su***ce'

)query.accept(

'netcdf4'

)nc = ncss.get_data(query)

data = xr.open_dataset(netcdf4datastore(nc)

)temp = data[

'temperature_su***ce'

].isel(time=0)

defcreate_map()

:# --建立畫圖空間

proj = ccrs.platecarree(

)# 建立座標系

fig = plt.figure(figsize=(6

,8), dpi=

400)

# 建立頁面

ax = fig.subplots(1,

1, subplot_kw=

)# --設定地圖屬性

provinces = cfeat.shapelyfeature(

reader(

'./cn_shp/province_9/province_9.shp'

).geometries(),

proj, edgecolor=

'k',

facecolor=

'none'

) ax.add_feature(provinces, linewidth=

0.6, zorder=2)

ax.add_feature(cfeat.coastline.with_scale(

'50m'

), linewidth=

0.6, zorder=10)

ax.add_feature(cfeat.rivers.with_scale(

'50m'

), zorder=10)

ax.add_feature(cfeat.lakes.with_scale(

'50m'

), zorder=10)

# --設定網格屬性

gl = ax.gridlines(

crs = ccrs.platecarree(),

draw_labels =

false

, linewidth =

0.9,

color =

'k',

alpha =

0.5,

linestyle =

'--'

) gl.xlabels_top = gl.ylabels_right = gl.ylabels_left = gl.ylabels_bottom =

false

# 關閉經緯度標籤

# --設定刻度

ax.set_xticks(np.arange(90,

145+5,

5)) ax.set_yticks(np.arange(0,

50+5,

5)) ax.xaxis.set_major_formatter(longitudeformatter())

ax.xaxis.set_minor_locator(plt.multiplelocator(1)

) ax.yaxis.set_major_formatter(latitudeformatter())

ax.yaxis.set_minor_locator(plt.multiplelocator(1)

) ax.tick_params(axis=

'both'

, labelsize=

5, direction=

'out'

)# -- 設定範圍

ax.set_extent([90

,140,0

,50], crs=ccrs.platecarree())

return ax

cbar_kwargs =

levels = np.arange(

270,

310,1)

temp.plot.contourf(

ax=create_map(),

cmap=

'spectral_r'

, levels=levels,

cbar_kwargs=cbar_kwargs,

transform=ccrs.platecarree(),

extend=

'both'

)# 讀取陸地,按陸地掩膜提取

shp_path =

'./ne_10m_land_scale_rank/'

shp = geopandas.read_file(shp_path +

'ne_10m_land_scale_rank.shp'

)t = temp.salem.roi(shape=shp)

t.plot.contourf(

ax=create_map(),

cmap=

'spectral_r'

, levels=levels,

cbar_kwargs=cbar_kwargs,

transform=ccrs.platecarree(

))

arcgis按掩膜提取工具

arcgis按掩膜提取工具 掩膜 通俗的理解就是ps中的蒙版,其作用就是保護被覆蓋的區域不受改動 開啟arcgis中的toolbox的空間分析工具,找到提取分析中的按掩膜提取,雙擊點開得到如下介面 1.輸入柵格就是輸入你想要進行掩膜提取的柵格,也就是被提取的那乙個圖層 2.輸入柵格資料或要素掩膜資料...

OpenCV學習 掩膜

影象掩膜,用選定的影象 圖形或物體,對處理的影象 全部或區域性 進行遮擋,來控制影象處理的區域或處理過程。掩膜是一種影象濾鏡的模板,實用掩膜經常處理的是遙感影象。當提取道路或者河流,或者房屋時,通過乙個n n的矩陣來對影象進行畫素過濾,然後將我們需要的地物或者標誌突出顯示出來。這個矩陣就是一種掩膜。...

opencv 掩膜操作

saturate cast函式保證運算後全部歸一化在0 255之間,注意上面row,col的移動範圍是很有講究的,的四個邊緣行因為沒有完整的上下左右所以省略,然而在實際應用掩膜操作時候並不用到自己這麼複雜的寫 opencv中提供了乙個filter2d函式。mat kernel mat 3,3 0,1...