コード例 #1
0
def apply_seasons(data_set_dict):
    """Extract seaons and apply a time mean per season."""
    data_file = data_set_dict['filename']
    logger.info("Loading %s for seasonal extraction", data_file)
    data_cube = iris.load_cube(data_file)
    seasons = ['DJF', 'MAM', 'JJA', 'SON']
    season_cubes = [extract_season(data_cube, season) for season in seasons]
    season_meaned_cubes = [
        season_cube.collapsed('time', iris.analysis.MEAN)
        for season_cube in season_cubes
    ]

    return season_meaned_cubes
コード例 #2
0
ファイル: trendcli.py プロジェクト: lukruh/trend_framework
logger.info("Opening dataset.")
data = xr.open_mfdataset(args.pattern, combine='by_coords')
data = data[args.varname]
logger.info("Selecting time period.")
data = data.loc[dict(time=slice(args.startdate, args.enddate))]
if args.downsample:
    logger.info(f"Downsampling spatial resolution (1 out of 10 gridpoints).")
    data = data[:, ::10, ::10]

# Now convert to Iris for using esmvalcore preprocessor functions
logger.debug("Converting to Iris cube")
cube = data.to_iris()

if args.period in ['DJF', 'MAM', 'JJA', 'SON']:
    logger.info(f"Statistics over season {args.period}")
    cube = pp.extract_season(cube, args.period)
else:
    logger.info(f"Statistics over full year")

logger.info(f"Calculating statistics '{args.statistics}' over period")
cube = pp.annual_statistics(cube, operator=args.statistics)

# Back to xarray
data = xr.DataArray.from_iris(cube)
logger.info('Calculating theil-sen trend')
theilsen = theilsen_trend(data)
logger.info('Calculating Mann Kendall test')
mk = mannkendall(data, alpha=args.alpha)

# Mask theilsen with mk test results
theilsen_masked = theilsen.where(mk!=0, np.nan)