Xarray在时间上找到每个网格点的最大值

发布于 2025-01-31 15:29:29 字数 1449 浏览 4 评论 0原文

我有以下NETCDF文件,其中包含在一个地区的每日降雨(爆炸),并且我以Xarray开放。

<xarray.Dataset>
Dimensions:    (latitude: 500, longitude: 600, time: 120)
Coordinates:
  * latitude   (latitude) float32 -35.22 -35.17 -35.12 ... -10.38 -10.33 -10.28
  * longitude  (longitude) float32 10.27 10.32 10.38 10.43 ... 40.12 40.18 40.22
  * time       (time) datetime64[ns] 2022-01-01 2022-01-02 ... 2022-04-30
Data variables:
    precip     (time, latitude, longitude) float32 ...
Attributes: (12/15)
    Conventions:       CF-1.6
    title:             CHIRPS Version 2.0
    history:           created by Climate Hazards Group
    version:           Version 2.0
    date_created:      2022-05-16
    creator_name:      Pete Peterson
    ...                ...
    reference:         Funk, C.C., Peterson, P.J., Landsfeld, M.F., Pedreros,...
    comments:           time variable denotes the first day of the given day....
    acknowledgements:  The Climate Hazards Group InfraRed Precipitation with ...
    ftp_url:           ftp://chg-ftpout.geog.ucsb.edu/pub/org/chg/products/CH...
    website:           http://chg.geog.ucsb.edu/data/chirps/index.html
    faq:               http://chg-wiki.geog.ucsb.edu/wiki/CHIRPS_FAQ

我想在每个网格点(即每个LAT/LON点)拉出最大降水值。我需要最大值才能保持其纬度,经度和时间的属性,因为然后我将分析这些最大值何时何地。

我知道我可以使用以下内容在第一个网格点跨时间获得最大值。但是,我该如何查看最大发生在哪里以及在什么日期发生?

ds1a.precip[:,0,0].max()

然后,我真的很努力地为所有网格点这样做。我真的很感谢指导。

I have the following netcdf file, which contains daily rainfall (precip) over a region, and I have opened it as an xarray.

<xarray.Dataset>
Dimensions:    (latitude: 500, longitude: 600, time: 120)
Coordinates:
  * latitude   (latitude) float32 -35.22 -35.17 -35.12 ... -10.38 -10.33 -10.28
  * longitude  (longitude) float32 10.27 10.32 10.38 10.43 ... 40.12 40.18 40.22
  * time       (time) datetime64[ns] 2022-01-01 2022-01-02 ... 2022-04-30
Data variables:
    precip     (time, latitude, longitude) float32 ...
Attributes: (12/15)
    Conventions:       CF-1.6
    title:             CHIRPS Version 2.0
    history:           created by Climate Hazards Group
    version:           Version 2.0
    date_created:      2022-05-16
    creator_name:      Pete Peterson
    ...                ...
    reference:         Funk, C.C., Peterson, P.J., Landsfeld, M.F., Pedreros,...
    comments:           time variable denotes the first day of the given day....
    acknowledgements:  The Climate Hazards Group InfraRed Precipitation with ...
    ftp_url:           ftp://chg-ftpout.geog.ucsb.edu/pub/org/chg/products/CH...
    website:           http://chg.geog.ucsb.edu/data/chirps/index.html
    faq:               http://chg-wiki.geog.ucsb.edu/wiki/CHIRPS_FAQ

I would like to pull out the maximum precip value at each grid point (i.e. each lat/lon point). I need the maximum value to keep its attributes of latitude, longitude and time because I will then analyse when and where these maximums occurred.

I know I can use the following to get a maximum value at the first grid point, across time. But how do I then see where this max occurs and on what date?

ds1a.precip[:,0,0].max()

I am really struggling to then do this for all grid points. I would really appreciate guidance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木緿 2025-02-07 15:29:29

一般而言

  • ​A>找到最大值
  • 代码> 找到达到最大值的坐标。

两种方法都有可选的参数dim,以指定要找到最大值的维度。

在您的情况下,

ds1a.max(dim='time')

每个latitudepentitude的数据集将返回一个数据集,并将

ds1a.argmax(dim='time')

返回达到此最大值的时间。

这是一个可复制的示例,其中包括示例数据:

import xarray as xr

ds = xr.tutorial.open_dataset('air_temperature').load()
ds.max(dim='time')
ds.argmax(dim='time')

In general

Both methods have the optional parameter dim, to specify which dimension to find the maximum over.

In your case,

ds1a.max(dim='time')

will return a dataset with the maximum over time per each latitude and longitude, and

ds1a.argmax(dim='time')

will return the time at which this maximum is attained.

Here's a reproducible example with sample data:

import xarray as xr

ds = xr.tutorial.open_dataset('air_temperature').load()
ds.max(dim='time')
ds.argmax(dim='time')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文