Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用cartopy从netcdf文件打印四维变量中的数据_Python_Matplotlib_Cartopy_Netcdf4 - Fatal编程技术网

Python 使用cartopy从netcdf文件打印四维变量中的数据

Python 使用cartopy从netcdf文件打印四维变量中的数据,python,matplotlib,cartopy,netcdf4,Python,Matplotlib,Cartopy,Netcdf4,我想知道如何使用cartopy在地图上绘制NetCDF文件的变量“r”(相对湿度)的数据 enter code here 根组(NETCDF3\u 64位\u偏移量数据模型,文件格式NETCDF3): 公约:CF-1.6 历史记录:2021-02-19 10:03:12格林尼治标准时间grib_to_netcdf-2.16.0:/opt/ecmwf/eccodes/bin/grib_to_netcdf-S param-o/cache/data7/adapter.marsdev.interna

我想知道如何使用cartopy在地图上绘制NetCDF文件的变量“r”(相对湿度)的数据

enter code here

根组(NETCDF3\u 64位\u偏移量数据模型,文件格式NETCDF3):
公约:CF-1.6
历史记录:2021-02-19 10:03:12格林尼治标准时间grib_to_netcdf-2.16.0:/opt/ecmwf/eccodes/bin/grib_to_netcdf-S param-o/cache/data7/adapter.marsdev.internal-1613728991.1847723-6796-17-440f19fd-bb8f-478f-bc36-959e3e9d9c42.nc/cache/tmp/440f19fd-bb8f-478f-bc36-959e9d9c42-adapter.1619c42-tmp-21389
尺寸:经度(480)、纬度(241)、高度(8)、时间(53)
变量(维度):float32经度(经度)、float32纬度(纬度)、int32级别(级别)、int32时间(时间)、int16 r(时间、级别、纬度、经度)
组:
口述键([‘经度’、‘纬度’、‘水平’、‘时间’、‘r’]))
las维度变量r es:(‘时间’、‘水平’、‘纬度’、‘经度’)
(53, 8, 241, 480)
----------------------------------------------------------------------
int16 r(时间、水平、纬度、经度)
比例系数:0.001964639476266317
加上偏移量:64.43876426873042
_填充值:-32767
缺少_值:-32767
单位:%
名称:相对湿度
标准名称:相对湿度
无限尺寸:
当前形状=(53,8241480)
填补
las维度变量r es:(‘时间’、‘水平’、‘纬度’、‘经度’)
(53, 8, 241, 480)
######################################################### 门萨误差

回溯(最近一次呼叫最后一次): 文件“/usr/lib/python3/dist packages/IPython/core/interactiveshell.py”,第3331行,运行代码 exec(代码对象、self.user\u全局、self.user\n) 文件“”,第1行,在 运行文件('/home/leo/Documentos/Universidad/Trabajo_de_investigación/perfilesverticalscontaminatesatmosfera/Datos/readnetdcf4200mas.py',wdir='/home/leo/Documentos/Universidad/Trabajo_de_investigación/perfilesverticalscontaminatesatmosfera/Datos')) 文件“/snap/pycharm professional/230/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py”,第197行,在runfile中 pydev_imports.execfile(文件名、全局变量、本地变量)#执行脚本 文件“/snap/pycharm professional/230/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py”,execfile中第18行 exec(编译(内容+“\n”,文件,'exec'),全局,loc) 文件“/home/leo/Documentos/Universidad/Trabajo_de_investigación/perfilesverticalscontaminantesatmosfera/Datos/readNetdcf42003_2020CMAS.py”,第65行,in plt.contourf(lon,lat,r_ds,transform=ccrs.PlateCarree()) 文件“/home/leo/.local/lib/python3.8/site packages/matplotlib/pyplot.py”,第2577行,轮廓图格式 __ret=gca().f( 文件“/home/leo/.local/lib/python3.8/site packages/cartopy/mpl/geoaxes.py”,第321行,在包装器中 返回函数(self、*args、**kwargs) 文件“/home/leo/.local/lib/python3.8/site packages/cartopy/mpl/geoaxes.py”,第1586行,轮廓图格式 结果=matplotlib.axes.axes.contourf(self,*args,**kwargs) 文件“/home/leo/.local/lib/python3.8/site packages/matplotlib/init.py”,第1447行,在内部 return func(ax,*map(sanitize_序列,args),**kwargs) 文件“/home/leo/.local/lib/python3.8/site packages/matplotlib/axes/_axes.py”,第6335行,轮廓图格式 等高线=mcontour.QuadContourSet(自,*args,**kwargs) 文件“/home/leo/.local/lib/python3.8/site packages/matplotlib/contour.py”,第816行,在init kwargs=self.\u进程\u参数(*参数,**kwargs) 文件“/home/leo/.local/lib/python3.8/site packages/matplotlib/contour.py”,第1430行,在进程参数中 x、 y,z=自身轮廓参数(参数,kwargs) 文件“/home/leo/.local/lib/python3.8/site packages/matplotlib/contour.py”,第1488行,在参数中 x、 y,z=自我检查(args[:3],kwargs) 文件“/home/leo/.local/lib/python3.8/site packages/matplotlib/contour.py”,第1514行,在检查xyz中 x=np.asarray(x,dtype=np.float64) asarray中的文件“/usr/local/lib/python3.8/dist packages/numpy/core/_asarray.py”,第102行 返回数组(a,数据类型,copy=False,order=order)
TypeError:数组()不接受任何参数(给定1个)

您应该可以使用我的ncplot包()执行此操作:


这将创建一个交互式绘图。

您可以修复代码高亮显示吗?在代码前一行使用三个反勾(``````),在代码的最后一行使用三个反勾。当我使用(ncplot)时,我有几个错误。文件“/usr/local/lib/python3.8/dist packages/hvplot/converter.py”,第1067行,在call raise importror('Datashading不可用')ImportError:Datashading不可用OK,这很奇怪。其中一个依赖项应该安装datashader,但它似乎不再安装在pypi上。但它在conda forge上安装。因此,最近对依赖项的更新肯定会破坏一切。今天下午我将更新pypi版本。现在,您应该可以使用
pip install data来修复此问题着色器
File“/usr/local/lib/python3.8/dist-packages/holoviews/plotting/bokeh/element.py”,第1359行,在初始glyphs-self中。更新glyph(渲染器、属性、映射、glyph、source、source.data)文件“/usr/local/lib/python3.8/dist-packages/holoviews/core/options.py”,第227行,退出(etype,value,traceback)holoviews.core.options.缩写异常:AttributeError:“str”对象没有属性“dataspecs”,无法查看原始回溯,捕获此异常并调用print_traceback()方法。是否要帮助我编写代码?这行代码给我一个错误。
plt.pcolormesh(ilon,ilat,r#ds,60,transform=ccrs.PlateCarree())
---------------------------------------地图上的绘图变量(ilon,ilat,r_ds,60,transform=ccrs.PlateCarree())ax.co岸线()
from netCDF4 import Dataset
import cartopy.crs as ccrs
import numpy as np
import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
ds = Dataset('relative_humidityEne_Dic2003_2020CMAS.nc', 'r')
lon = ds.variables["longitude"]
lat = ds.variables["latitude"]
level = ds.variables["level"]
time = ds.variables["time"]
r = ds.variables["r"]
ax = plt.axes(projection=ccrs.PlateCarree())
r_ds = ds.variables['r'][0, :, :, :]
plt.contourf(lon, lat, r_ds, transform=ccrs.PlateCarree())
ax.coastlines()
plt.show()
root group (NETCDF3_64BIT_OFFSET data model, file format NETCDF3):
    Conventions: CF-1.6
    history: 2021-02-19 10:03:12 GMT by grib_to_netcdf-2.16.0: /opt/ecmwf/eccodes/bin/grib_to_netcdf -S param -o /cache/data7/adaptor.marsdev.internal-1613728991.1847723-6796-17-440f19fd-bb8f-478f-bc36-959e3e9d9c42.nc /cache/tmp/440f19fd-bb8f-478f-bc36-959e3e9d9c42-adaptor.marsdev.internal-1613728966.210842-6796-20-tmp.grib
    dimensions(sizes): longitude(480), latitude(241), level(8), time(53)
    variables(dimensions): float32 longitude(longitude), float32 latitude(latitude), int32 level(level), int32 time(time), int16 r(time,level,latitude,longitude)
    groups: 
dict_keys(['longitude', 'latitude', 'level', 'time', 'r'])
las dimenciones variable r es:  ('time', 'level', 'latitude', 'longitude')
(53, 8, 241, 480)

----------------------------------------------------------------------
<class 'netCDF4._netCDF4.Variable'>
int16 r(time, level, latitude, longitude)
    scale_factor: 0.001964639476266317
    add_offset: 64.43876426873042
    _FillValue: -32767
    missing_value: -32767
    units: %
    long_name: Relative humidity
    standard_name: relative_humidity
unlimited dimensions: 
current shape = (53, 8, 241, 480)
filling on
las dimenciones variable r es:  ('time', 'level', 'latitude', 'longitude')
(53, 8, 241, 480)
from ncplot import view
view('relative_humidityEne_Dic2003_2020CMAS.nc', 'r')