[英]Extract coordinate values in xarray
I would like to extract the values of the coordinate variables.我想提取坐标变量的值。
For example I create a DataArray as:例如,我创建一个 DataArray 为:
import xarray as xr
import numpy as np
import pandas as pd
years_arr=range(1982,1986)
time = pd.date_range('14/1/' + str(years_arr[0]) + ' 12:00:00', periods=len(years_arr), freq=pd.DateOffset(years=1))
lon = range(20,24)
lat = range(10,14)
arr1 = xr.DataArray(data, coords=[time, lat, lon], dims=['time', 'latitude', 'longitude'])
I now would like to output the lon
values from arr1
.我现在想从
arr1
输出lon
值。 I'm asking as arr1
going into a function so I may not have the lon
values available.我要求
arr1
进入一个函数,所以我可能没有可用的lon
值。
arr1.coords['lon']
为您提供xarray.DataArray
,而arr1.coords['lon'].values
为您提供 numpy 数组的值。
Another possible solution is:另一种可能的解决方案是:
time, lat, lon = arr1.indexes.values()
The result is a Float64Index for your lat/lon coordinates.结果是您的纬度/经度坐标的 Float64Index。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.