#!/usr/bin/env python

## Just run code in recipes, use it carefully
## example: use netcdf4 to make cache file. Since python is faster than ncl.
#;DIAG_NORCPM; RUNTHESECODES: print('    no codes run here.')

## DJF, 1st year will be D, last year will be JF
import xarray as xr
from os.path import exists
from sys import exit
infile = "gpcp_prec_atm_grid_2000-2020.nc"
outfile = "gpcp_prec_atm_grid_JJA_2000-2020.nc"
months = [6,7,8]
if exists(outfile): exit()
ds = xr.open_dataset(infile)
ds = ds.sel(time=ds.time.dt.month.isin(months))
ds = ds.groupby("time.year").mean('time')
#clids = ds.mean(dim='time')
#ds = ds.sel(time=ds.time.dt.year.isin(years))

ds.to_netcdf(outfile)


