如何为保持点的时间和位置的数组创建计数函数(python)

问题描述 投票:-2回答:1

我有两个netcdf文件,我曾用它们来计算休斯顿地区的Humidex。从那里,我需要找到一种方法来计算每个纬度/经度满足特定阈值的天数(41)。然后,我需要绘制该区域内计数数量的空间图,以便可以比较该区域中每个点的极热天数。我已经使用xarray.where来隔离处于此阈值的天数,但是当我应用count函数时,我浪费了时间和经/纬度变量,只是在此获取数据点总数的输出阈。

humidex是两个不同的netcdf文件的计算,它具有经度和纬度变量

>>> hotday = xr.DataArray(humidex)
>>> hotday.where(hotday >=41)


<xarray.DataArray 'tasmax' (lat: 960, lon: 1920)>
array([[nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       ...,
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan]], dtype=float32)
Coordinates:
  * lat      (lat) float64 -89.86 -89.67 -89.48 -89.3 ... 89.3 89.48 89.67 89.86
  * lon      (lon) float64 0.0 0.1875 0.375 0.5625 ... 359.2 359.4 359.6 359.8
    height   float64 2.0

>>>for ii in hotday:
  >>> counting=xr.DataArray.count(ii)
>>>counting

<xarray.DataArray 'tasmax' ()>
array(1920)
Coordinates:
    lat      float64 89.86
    height   float64 ...

我希望这是有道理的,我还是编码的新手,这真的让我感到震惊。

python netcdf python-xarray
1个回答
0
投票

欢迎您加入。有很多方法可以解决您的问题。

这里是一种建议的方法:

import xarray as xr
data = xr.tutorial.open_dataset('air_temperature') 

high_temps = xr.where(data > 300, 1, 0) #set all temps over 300K = 1; others to 0
summed_temps = high_temps.sum(dim='time')

然后您可以直接绘制热图。

© www.soinside.com 2019 - 2024. All rights reserved.