【发布时间】:2021-10-16 04:58:28
【问题描述】:
我有 10 年的 WRF 气候模型输出。我正在寻找一个有效的代码,它对于 xarray 中的每个网格点只选择 T>0 超过 2 天的天数。对于我的情节,我希望每个月在每个网格点的总天数中 T>2 超过 2 天。
我是 xarrays 的新手,并且正在查看类似的问题,但我仍然找不到合适的循环或计数函数来应用每个网格点和月份!非常感谢有关此代码的任何帮助。
这是我当前的代码:
import xarray as xr
import pandas as pd
import matplotlib.pyplot as plt
import netCDF4
from netCDF4 import Dataset
import numpy as np
#concatenate the 10year output
dataset=xr.open_mfdataset("\Python files for plotting wrfoutput\era5_1990-2000_output\*.nc",concat_dim='Time', combine='nested', compat='no_conflicts', preprocess=None, engine=None, data_vars='all', coords='all', parallel=False, join='outer', attrs_file=None,)
#dimensions are: Time, south_north, west_east
DS=dataset
DS = DS.assign_coords(Time=pd.to_datetime(DS['Time'].values))
#Select/extract only the mean 2m surface temperature (T2) from the large xarray
DST2=DS.T2
#apply the where function to check at which grid points in each month the T2>0
T2threshold=DST2.groupby('Time.month').where(DST2>0)
【问题讨论】:
标签: python pandas python-xarray weather