最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python讀取nc數(shù)據(jù)并繪圖的方法實(shí)例

 更新時(shí)間:2022年05月07日 14:23:18   作者:細(xì)細(xì)47  
最近項(xiàng)目中需要處理和分析NC數(shù)據(jù),所以下面這篇文章主要給大家介紹了關(guān)于python讀取nc數(shù)據(jù)并繪圖的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

獲取nc數(shù)據(jù)的相關(guān)信息

from netCDF4 import Dataset
import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt

path = "F:\\OCO2.SIF.all.daily.2001.nc"
csv_path = "F:\\test.csv"
dst = Dataset(path, mode='r', format="netCDF4")

 print(dst.variables.keys())
    data = dst.variables['all_daily_sif'][:]
    print(data.shape)
    # 輸出結(jié)果如下:
    # dict_keys(['lat', 'lon', 'doy', 'all_daily_sif'])
    # (92, 360, 720)
    #可見有92個(gè)時(shí)間序列,經(jīng)度(lon)、緯度(lat)的取值有720,360個(gè)

    # # 查看數(shù)據(jù)經(jīng)緯度范圍,經(jīng)度-179.75~179.75,其中負(fù)值為西經(jīng),正值為東經(jīng);緯度正為北緯,負(fù)為南緯
    # # 格點(diǎn)分辨率為0.5度
    long = dst.variables['lon'][:]
    lati = dst.variables['lat'][:]
    print(long[0], long[-1], lati[0], lati[-1])
    print(long.shape, lati.shape)

繪圖

用matplotlib繪圖

參考文獻(xiàn)1

 # plt對(duì)某個(gè)doy的全球sif值作圖。左半部分為西半球,右邊是東半球
    # 選了doy為10的sif數(shù)據(jù)作圖
    plt.contourf(long, lati, data[10, :, :] )
    plt.colorbar(label="Sif", orientation="horizontal")
    plt.show()

運(yùn)行結(jié)果:

用Basemap繪圖

參考文獻(xiàn)2

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

    lat = dst.variables['lat'][:]
    lon = dst.variables['lon'][:]
    data = dst.variables['all_daily_sif'][:]    
    data[10] = data[10]
    # use .shape function to check that arrays have
    # the correct size.
    # e.g. lon.shape
    print(data[10].shape)

    lon0 = lon.mean()
    lat0 = lat.mean()
    # 設(shè)置投影方式:cyl為圓柱投影、還可設(shè)置merc為mercator投影 llcrnrlat為起始lat;urcrnrlat為終止lat
    # m = Basemap(projection='merc', llcrnrlat=lat[0], urcrnrlat=lat[-1], \
    #              llcrnrlon=lon[0], urcrnrlon=lon[-1], ax=ax1)
   # 參數(shù) "resolution" 用于控制地圖面積邊緣的精細(xì)程度,有'l'和'h'兩種取值
    m = Basemap(lat_0=lat0, lon_0=lon0,projection='cyl',resolution='l')
    # 繪制等經(jīng)緯度線 緯度每隔20度畫一條線,且標(biāo)注經(jīng)緯度
    m.drawparallels(np.arange(-90., 91., 20.), labels=[1, 0, 0, 0], fontsize=10)
    m.drawmeridians(np.arange(-180., 181., 40.), labels=[0, 0, 0, 1], fontsize=10)
    m.drawcoastlines()# 繪制海岸線
    # m.drawcountries(linewidth=0.25)  # 繪制國界線
    # m.readshapefile('F:\E\data\grass_yield\shp\quhua\\省', 'states')  # 讀取中國各省邊界,并繪圖

    lon, lat = np.meshgrid(lon, lat)
    xi, yi = m(lon, lat)
    # cmap是顏色,還可選‘jet'、‘spring'、‘winter'、'summer'、'autumn'
    cs = m.contourf(xi, yi, data[10],  cmap='summer')
    # pad指位置,
    cbar = m.colorbar(cs, location='bottom', pad="10%",format='%.1f')
    # cbar = m.colorbar(C, 'right', ticks=np.arange(-128, 128, 40), format='%.1f')
    font1 = {'family': 'DejaVu Sans', 'weight': 'normal', 'size': 16}
    plt.title('CSIF', font1)
    plt.show()

運(yùn)行效果:

用Cartopy繪圖

參考文獻(xiàn)3

此前 Python 最常用的地圖包是 Basemap,然而它將于 2020 年被棄用,官方推薦使用 Cartopy 包作為替代。Cartopy 是英國氣象局開發(fā)的地圖繪圖包,實(shí)現(xiàn)了 Basemap 的大部分功能,還可以通過 Matplotlib 的 API 實(shí)現(xiàn)豐富的自定義效果。

安裝Cartopy包

下載安裝OSGeo4W4

參考文獻(xiàn):https://zhuanlan.zhihu.com/p/129351199 

參考文獻(xiàn):https://blog.csdn.net/weixin_39618339的plt畫圖像圖例的位置怎么寫代碼_用basemap畫氣象圖 

參考文獻(xiàn): https://zhajiman.github.io/ 

https://trac.osgeo.org/osgeo4w/

總結(jié)

到此這篇關(guān)于python讀取nc數(shù)據(jù)并繪圖的文章就介紹到這了,更多相關(guān)python讀取nc數(shù)據(jù)繪圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

泸水县| 白银市| 五寨县| 德格县| 边坝县| 沽源县| 松江区| 文安县| 丰宁| 栖霞市| 茶陵县| 孟津县| 九台市| 星座| 沙坪坝区| 赫章县| 永安市| 东至县| 时尚| 临潭县| 柞水县| 阳西县| 鄂托克旗| 武邑县| 西华县| 铁力市| 南部县| 漯河市| 西乌| 闵行区| 封开县| 苗栗县| 绿春县| 吉安市| 杂多县| 常宁市| 都江堰市| 本溪市| 栖霞市| 雷州市| 团风县|