#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri May 15 15:40:35 EDT 2020 if __name__ == '__main__': from misc.timer import Timer tt = Timer(f'start {__file__}') import sys, os.path, os, glob import xarray as xr, numpy as np, pandas as pd import matplotlib.pyplot as plt #more imports from misc.wysalem import get_world_shape # if __name__ == '__main__': tt.check('end import') #start from here cntry_name = 'Japan' df = get_world_shape(cntry_name) years = range(1981, 2020) if __name__ == '__main__': for year in years: print(year, 'of', years.stop) ifile = f'/tigress/wenchang/data/chirps/daily/chirps-v2.0.{year:04d}.days_p05.nc' ofile = f'tmp/chirps-v2.0.{year:04d}.days_p05.{cntry_name}.nc' if os.path.exists(ofile): print('[exists]:', ofile) continue da = xr.open_dataarray(ifile) da = da.salem.subset(shape=df, margin=2).salem.roi(shape=df) ds = da.to_dataset().load() ds.to_netcdf(ofile) print('[saved]:', ofile) tt.check(f'**Done**')