![](/img/trans.png)
[英]Take maximum rainfall value for each season over a time period (xarray)
[英]Xarray find maximum value for each grid point across time
我有以下 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
我想提取每个网格点(即每个纬度/经度点)的最大沉淀值。 我需要最大值来保持其纬度、经度和时间属性,因为然后我将分析这些最大值发生的时间和地点。
我知道我可以使用以下方法在第一个网格点处获得最大值,跨越时间。 但是我如何才能看到这个最大值发生在哪里以及在什么日期?
ds1a.precip[:,0,0].max()
我真的很难为所有网格点执行此操作。 我真的很感激指导。
一般来说
Dataset.max
找到最大值Dataset.argmax
找到达到最大值的坐标。 这两种方法都有可选参数dim
,用于指定要在哪个维度上找到最大值。
在你的情况下,
ds1a.max(dim='time')
将返回每个latitude
和longitude
随时间变化的最大值的数据集,并且
ds1a.argmax(dim='time')
将返回达到此最大值的时间。
这是一个带有示例数据的可重现示例:
import xarray as xr
ds = xr.tutorial.open_dataset('air_temperature').load()
ds.max(dim='time')
ds.argmax(dim='time')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.