Xarray在时间上找到每个网格点的最大值
我有以下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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般而言
两种方法都有可选的参数
dim
,以指定要找到最大值的维度。在您的情况下,
每个
latitude
和pentitude
的数据集将返回一个数据集,并将返回达到此最大值的时间。
这是一个可复制的示例,其中包括示例数据:
In general
Dataset.max
finds the maximum valueDataset.argmax
finds the coordinate at which the maxium value is attained.Both methods have the optional parameter
dim
, to specify which dimension to find the maximum over.In your case,
will return a dataset with the maximum over time per each
latitude
andlongitude
, andwill return the time at which this maximum is attained.
Here's a reproducible example with sample data: