【发布时间】:2019-08-07 16:31:00
【问题描述】:
我是新来的。 首先,我非常感谢您的时间和考虑。 关于在 python 中管理 2 个不同的 netcdf 文件,我有 2 个问题。 我搜索了很多,但不幸的是我找不到解决方案。
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),
我需要将坐标更改为 lon/lat,以便我可以根据特定的 lon/lat 坐标(通过使用 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')
2- 与 1 类似,我有另一个 netcdf 文件,其坐标如下:
* X (X) float32 557600.0 .. 579400.0
* Y (Y) float32 5190600 ... 5205400.0
* time (time) datetime64[ns] 2007-01I
如何将 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
与@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
【问题讨论】:
-
非常感谢,巴特。我阅读了示例并进行了很多搜索,但是由于我的文件是多维的(x,y,t,rain),因此无法进行转换。
-
我想我没有很好地解释这个问题。我有两个不同的 netcdf 文件,它们具有不同的协调系统和不同的网格大小(我在上面描述过)。我需要更改坐标系,以便我可以重新调整其中一个坐标系,然后使用一些统计指数(比如说,偏差 RMSE ...)来比较它们。
标签: python-3.x netcdf coordinate-transformation python-xarray netcdf4