在ecmwf下的气象数据然后利用xarray和cfgrib进行读取,先开始一直报错
data_ow_1 = xr.open_dataset(file_ocean_wave_1, engine=('cfgrib'))
skipping variable: paramId==140235 shortName='mdww'
Traceback (most recent call last):
File "D:\anaconda\envs\program1\lib\site-packages\cfgrib\dataset.py", line 676, in build_dataset_components
dict_merge(variables, coord_vars)
File "D:\anaconda\envs\program1\lib\site-packages\cfgrib\dataset.py", line 607, in dict_merge
raise DatasetBuildError(
cfgrib.dataset.DatasetBuildError: key present and new value is different: key='latitude' value=Variable(dimensions=('latitude',), data=array([60. , 59.7
然后在网上找了好久,按坐标层次读取
data_ow_1 = xr.open_dataset(file_ocean_wave_1, engine=('cfgrib'),backend_kwargs={'filter_by_keys':{'typeOfLevel': 'meanSea'}})
<xarray.Dataset>
Dimensions: (time: 744, latitude: 121, longitude: 720)
Coordinates:
number int32 ...
* time (time) datetime64[ns] 2019-05-01 ... 2019-05-31T23:00:00
step timedelta64[ns] ...
meanSea float64 ...
* latitude (latitude) float64 60.0 59.5 59.0 58.5 58.0 ... 1.5 1.0 0.5 0.0
* longitude (longitude) float64 -180.0 -179.5 -179.0 ... 178.5 179.0 179.5
valid_time (time) datetime64[ns] ...
Data variables:
mdww (time, latitude, longitude) float32 ...
mpww (time, latitude, longitude) float32 ...
mwd (time, latitude, longitude) float32 ...
mwp (time, latitude, longitude) float32 ...
swh (time, latitude, longitude) float32 ...
shww (time, latitude, longitude) float32 ...
Attributes:
GRIB_edition: 1
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
history: 2023-04-19T18:07 GRIB to CDM+CF via cfgrib-0.9.1...
我尝试着将读取的文件转为dataframe
new_data_clean_1 = pd.DataFrame([])
for i in data_h_index:
if select_time[i].split('-')[0] == '2019':
data_clean_1 = data_ow_1.sel(time=select_time[i], longitude=select_lon[i], latitude=select_lat[i],method='nearest')
DT_1 = data_clean_1.to_pandas()
print(DT_1)
out:
u10 0.345963
v10 0.389984
dtype: float64
u10 -0.416733
v10 -0.414703
dtype: float64
u10 -0.416733
v10 -0.414703
dtype: float64
这里u10 和v10被当作数据了
怎么才能将xarray.dataset转化为正常的列表,将u10,v10作为索引