【发布时间】:2020-12-08 18:00:24
【问题描述】:
这是对以下问题的后续问题:How to process the Time variables of OCO-2/Tropomi NETCDF4 files using Xarray?
我正在处理相同的数据,但在理解格式方面存在一些问题。
我想绘制一张“xch4”的地图,作为给定时间的纬度和经度的函数。
我会假设我可以为给定时间定义一个新结构:
new_ds=ds.isel(time=0)
然后为这个结构绘制 xch4
new_ds.xch4.plot()
但这不起作用。
我对 Xarray 有点陌生,因此非常感谢任何帮助。
代码和输出如下:
import xarray as xr
ds=xr.open_dataset('ESACCI-GHG-L2-CH4-CO-TROPOMI-WFMD-20200430-fv1.nc')
ds
返回的输出是:
<xarray.Dataset>
Dimensions: (corners_dim: 4, layer_dim: 20, level_dim: 21, sounding_dim: 549041)
Dimensions without coordinates: corners_dim, layer_dim, level_dim, sounding_dim
Data variables:
time (sounding_dim) datetime64[ns] ...
latitude (sounding_dim) float32 ...
longitude (sounding_dim) float32 ...
solar_zenith_angle (sounding_dim) float32 ...
sensor_zenith_angle (sounding_dim) float32 ...
azimuth_difference (sounding_dim) float32 ...
xch4 (sounding_dim) float32 ...
xch4_uncertainty (sounding_dim) float32 ...
xco (sounding_dim) float32 ...
xco_uncertainty (sounding_dim) float32 ...
quality_flag (sounding_dim) int32 ...
pressure_levels (sounding_dim, level_dim) float32 ...
pressure_weight (sounding_dim, layer_dim) float32 ...
ch4_profile_apriori (sounding_dim, layer_dim) float32 ...
xch4_averaging_kernel (sounding_dim, layer_dim) float32 ...
co_profile_apriori (sounding_dim, layer_dim) float32 ...
xco_averaging_kernel (sounding_dim, layer_dim) float32 ...
orbit_number (sounding_dim) int32 ...
scanline (sounding_dim) int32 ...
ground_pixel (sounding_dim) int32 ...
latitude_corners (sounding_dim, corners_dim) float32 ...
longitude_corners (sounding_dim, corners_dim) float32 ...
altitude (sounding_dim) float32 ...
apparent_albedo (sounding_dim) float32 ...
land_fraction (sounding_dim) int32 ...
cloud_parameter (sounding_dim) float32 ...
h2o_column (sounding_dim) float32 ...
h2o_column_uncertainty (sounding_dim) float32 ...
Attributes:
title: TROPOMI/WFMD XCH4 and XCO
institution: University of Bremen
source: TROPOMI L1B version 01.00.00
history: 2019 - product generated with WFMD
tracking_id: 497532a4-fa32-406d-9f6e-52e87f527d47
Conventions: CF-1.6
product_version: v1.2
summary: Weighting Function Modified DOAS (WFMD) was ad...
keywords: satellite, Sentinel-5 Precursor, TROPOMI, atmo...
id: ESACCI-GHG-L2-CH4-CO-TROPOMI-WFMD-20200430-fv1.nc
naming_authority: iup.uni-bremen.de
keywords_vocabulary: NASA Global Change Master Directory (GCMD)
cdm_data_type: point
comment: These data were produced at the University of ...
date_created: 20201030T124301Z
creator_name: University of Bremen, IUP, Oliver Schneising
creator_email: schneising@iup.physik.uni-bremen.de
project: Climate Change Initiative - European Space Agency
geospatial_lat_min: -90
geospatial_lat_max: 90
geospatial_lat_units: degree_north
geospatial_lon_min: -180
geospatial_lon_max: 180
geospatial_lon_units: degree_east
geospatial_vertical_min: 0
geospatial_vertical_max: 100000
time_coverage_start: 20200430T000000Z
time_coverage_end: 20200430T235959Z
time_coverage_duration: P1D
time_coverage_resolution: P1D
standard_name_vocabulary: NetCDF Climate and Forecast (CF) Metadata Conv...
license: ESA CCI Data Policy: free and open access
platform: Sentinel-5 Precursor
sensor: TROPOMI
spatial_resolution: 7km x 7km at nadir (typically)
然后我试试:
new_ds=ds.isel(time=0)
输出是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/au159666/anaconda3/lib/python3.8/site-packages/xarray/core/dataset.py", line 1959, in isel
indexers = drop_dims_from_indexers(indexers, self.dims, missing_dims)
File "/Users/au159666/anaconda3/lib/python3.8/site-packages/xarray/core/utils.py", line 767, in drop_dims_from_indexers
raise ValueError(
ValueError: dimensions {'time'} do not exist. Expected one or more of Frozen(SortedKeysDict({'sounding_dim': 549041, 'level_dim': 21, 'layer_dim': 20, 'corners_dim': 4}))
我也试试1的建议:
ds.swap_dims({"sounding_dim": "time"})
new_ds=ds.isel(time=0)
但结果还是一样:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/au159666/anaconda3/lib/python3.8/site-packages/xarray/core/dataset.py", line 1959, in isel
indexers = drop_dims_from_indexers(indexers, self.dims, missing_dims)
File "/Users/au159666/anaconda3/lib/python3.8/site-packages/xarray/core/utils.py", line 767, in drop_dims_from_indexers
raise ValueError(
ValueError: dimensions {'time'} do not exist. Expected one or more of Frozen(SortedKeysDict({'sounding_dim': 549041, 'level_dim': 21, 'layer_dim': 20, 'corners_dim': 4}))
【问题讨论】:
-
你可能想试试我的包 ncplot,它可以自动创建 xarray 数据集的交互式绘图:pypi.org/project/ncplot。但是你能提供一个数据集的链接吗?似乎有些不标准。经度/纬度/时间是变量,而不是坐标,这就是您的代码失败的原因。
-
我会试试 ncplot。数据可以在这里找到:iup.uni-bremen.de/carbon_ghg/products/tropomi_wfmd
-
我快速查看了数据。它不适用于 ncplot。看起来你将不得不重组数据,以便经度、纬度和时间是坐标,以获得 ncplot 或 xarray 的内置绘图方法来生成地图
-
实际上,从数据来看,它似乎不太适合 xarray,它可以理想地处理 gidded 数据。 Geopandas 可能是可以使用的软件包,或者只是 pandas
标签: python python-xarray netcdf4