问题描述
我正在处理一个具有逻辑 (1,2,3...) 和物理坐标 (lat,on) 的 netCDF 文件。
我知道我必须在 xarray 中分配多维坐标,但我找不到语法。
目标是生成这样的数组数据集:
import numpy as np
import pandas as pd
import xarray as xr
import cartopy.crs as ccrs
from matplotlib import pyplot as plt
ds = xr.tutorial.open_dataset('rasm').load()
ds
其中 xc 和 yc 是我的物理坐标。到目前为止,这是我的位置(显然未完成):
no2_da = xr.DataArray(no2[0],dims=("x","y"),coords={
"lat": ("x",scanline)
"lon": ()
}
)
谢谢!
解决方法
您可以使用这种格式
no2[0] = 15 + 10 * np.random.randn(size)# value of no2[0]
lat = np.random.uniform(low=-90,high=90,size=size)#your latitude here
lon = np.random.uniform(low=-180,high=180,size=size)#your longitude here
# round to two digits after decimal point
no2[0],lat,lon = np.around([no2[0],lon],decimals=2)
df = pd.DataFrame({"no2[0]": no2[0],"lat": lat,"lon": lon})