简体   繁体   English

在 Basemap 上绘制 netCDF4 数据

[英]Plotting netCDF4 data on Basemap

I have a csv file with 3 columns ( longitude , latitude and precipitation ) and 90 rows and I need to plot it as a map in Python. I have a csv file with 3 columns ( longitude , latitude and precipitation ) and 90 rows and I need to plot it as a map in Python. I have not a time index, only value associated with coordinates.我没有时间索引,只有与坐标相关的值。 I have followed this procedure:我遵循了这个程序:

  1. Convert.cvs to.nc (netCDF file)将.cvs 转换为.nc(netCDF 文件)
  2. Plot.nc thought Basemap + Matplotlib Plot.nc 思想底图 + Matplotlib

In the second step, I got the follow error:在第二步中,我收到以下错误:

ValueError: need more than 1 value to unpack

Which seems to be in line c_scheme = mp.pcolor(x,y,avp[:], cmap = 'jet') from the code, especially avp[:] .这似乎与代码中的c_scheme = mp.pcolor(x,y,avp[:], cmap = 'jet')一致,尤其是avp[:] When I run avp.shape I get it have a shape of (90L,) and avp.ndim show a value of 1.当我运行avp.shape时,我得到它的形状为 (90L,),而avp.ndim显示的值为 1。

My questions are: What values should be displayed in "avp" exactly?我的问题是:应该在“avp”中准确显示什么值? What should I extract from this dimension?我应该从这个维度中提取什么?

from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

data = Dataset(r'SN1_PTPM.nc')

fig = plt.figure(figsize=(12,9))

lats = data.variables['Latitude'][:] #latitute column
lons = data.variables['Longitude'][:] #longitute column
avp = data.variables['Precipitation'][:] #precipitation column

mp = Basemap(projection = 'merc',
            llcrnrlon = 5.5,
            llcrnrlat = 8.5,
            urcrnrlon = -75,
            urcrnrlat = -72,
            resolution = 'i')

lon,lat = np.meshgrid(lons,lats)
x,y = mp(lon,lat)

c_scheme = mp.pcolor(x,y,avp[:], cmap = 'jet')
cbar = mp.colorbar(c_scheme, location = 'right', pad = '10%')

plt.show()

I thank you in advance for any information you can give me.我提前感谢您提供的任何信息。

I imagine the issue is your coordinates are tuples (lat,lon) associated with one value each.我想问题是您的坐标是元组(纬度,经度),每个都与一个值相关联。 In that case you can't use meshgrid because that will create a grid of coordinates but you don't have values at all of those points (you create a 2 dimensional grid but only have a 1 dimensional list of values)在这种情况下,您不能使用 meshgrid,因为这将创建一个坐标网格,但您在所有这些点上都没有值(您创建一个二维网格,但只有一个一维值列表)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM