E G*_*emi 5 netcdf coordinate-transformation python-3.x python-xarray netcdf4
我刚来这地方。首先,我非常感谢您的时间和考虑。我有两个关于在 python 中管理 2 个不同的 netcdf 文件的问题。我进行了很多搜索,但不幸的是我找不到解决方案。
1-我有一个 netcdf 文件,其坐标如下:
time datetime64[ns] 2016-08-16T22:00:00
* y (y) int32 220000 ... 620000
* x (x) int32 20000 ... 720000
lat (y, x) float64 dask.array<shape=(401, 701),
lon (y, x) float64 dask.array<shape=(401, 701),
Run Code Online (Sandbox Code Playgroud)
我需要将坐标更改为经度/纬度,以便我可以根据特定的经度/纬度坐标(通过使用 xarray)对区域进行切片。但我不知道如何将 x 和 y 更改为 lon lat。这是我的代码:
import xarray as xr
import matplotlib.pyplot as plt
p = "R_201608.nc"
ds = xr.open_mfdataset(p)
q=ds.RR.sel(time='2016-08-16T21:00:00')
Run Code Online (Sandbox Code Playgroud)
2-与 1 类似,我有另一个 netcdf 文件,其坐标如下:
* X (X) float32 557600.0 .. 579400.0
* Y (Y) float32 5190600 ... 5205400.0
* time (time) datetime64[ns] 2007-01I
Run Code Online (Sandbox Code Playgroud)
如何将 x 和 y 转换为 lon/lat 系统,以便可以在 lon/lat 系统中绘制它?
与@Ryan相关的编辑: 1-是的。该文件显示了大面积的降雨。我想将其切成更小的区域 - 与 q2 相关的文件的类似区域 - 并使用偏差、RMSE 等对它们进行比较。这里是与此文件相关的完整信息:
<xarray.Dataset>
Dimensions: (time: 2976, x: 701, y: 401)
Coordinates:
* time (time) datetime64[ns] 2016-08-31T23:45:00
* y (y) int32 220000 221000 ... 619000 620000
* x (x) int32 20000 21000 ... 719000 720000
lat (y, x) float64 dask.array<shape=(401, 701),chunksize=(401, 701)>
lon (y, x) float64 dask.array<shape=(401, 701), chunksize=(401, 701)
Data variables:
RR (time, y, x) float32 dask.array<shape=(2976, 401, 701), chunksize=(2976, 401, 701)>
lambert_conformal_conic int32 ...
Conventions: CF-1.5
Run Code Online (Sandbox Code Playgroud)
与@Ryan相关的编辑:2-这是有关第二个文件的完整信息(较小的区域):
<xarray.DataArray 'Precip' (time: 8928, Y: 75, X: 110)>
dask.array<shape=(8928, 75, 110), dtype=float32, chunksize=(288, 75, 110)>
Coordinates:
sensor_height_precip float32 1.5
sensor_height_P float32 1.5
* X (X) float32 557600.0 557800.0 ... 579200.0 579400.0
* Y (Y) float32 5190600.0 5190800.0 ... 5205400.0
* time (time) datetime64[ns] 2007-01-31T23:55:00
Attributes:
grid_mapping: UTM33N
ancillary_variables: QFlag_Precip QGrid_Precip
long_name: Precipitation Amount
standard_name: precipitation_amount
cell_methods: time:sum
units: mm
Run Code Online (Sandbox Code Playgroud)
在问题 1) 中,无法将 lon 和 lat 转换为维度坐标,因为它们是二维的(都有维度 x, y)。用于切片的维度坐标只能是一维的。如果您可以更具体地说明切片后要执行的操作,我们可以提供有关如何继续的更多建议。您是否想选择特定的纬度/经度范围,然后计算一些统计数据(例如平均值/方差)?
在问题 2) 中,看起来您有一个地图投影。如果没有有关投影的更多信息,就不可能转换为纬度/经度坐标或在地图上绘制。您的数据集中是否包含有关所使用的地图投影的更多信息?你能发布完整的输出吗print(ds)?
| 归档时间: |
|
| 查看次数: |
3813 次 |
| 最近记录: |