def test_time_slice(directory, sourcefiles, sd, ed): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.time_slice(ens, start_date=sd, end_date=ed) data = ctt.sha(ens) return data
def test(directory, sourcefiles, cwd): """ Makes a file in /testdata/ name testclasses_file.txt whcih has the ensemble info after using match ensembles and match_realizations """ # first change to a scratch dir and link in test data. The paths are CCCma specific. ctt.loadtestfiles(directory, sourcefiles) f = cwd + '/testdata/testclasses_file.txt' # ========================================================================= # mkensemble # ========================================================================= fp = '*historical*' ens = cd.mkensemble(fp, prefix='') ens.fulldetails_tofile(f) # Create a second cmipdata ensemble fp2 = '*ts*' ens2 = cd.mkensemble(fp2, prefix='') ens.fulldetails_tofile(f) # ========================================================================= # match_ensembles # ========================================================================= print 'Matching ensembles...' enso1, enso2 = cd.match_ensembles(ens, ens2) enso1.sinfo() enso2.sinfo() ens.fulldetails_tofile(f) # ========================================================================= # match_realizations # ========================================================================= print 'Matching realizations...' ensem1, ensem2 = cd.match_realizations(ens, ens2) ensem1.sinfo() ensem2.sinfo() ens.fulldetails_tofile(f)
def test_zonal_mean(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.zonmean(ens, delete=True) data = ctt.sha(ens) return data
def test_cat_experiments(directory, sourcefiles, var, e1name, e2name): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.cat_experiments(ens, var, exp1_name=e1name, exp2_name=e2name) data = ctt.sha(ens) return data
def test_remap(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.remap(ens, remap='r1x180') data = ctt.sha(ens) return data
def test_1dtimeseries(directory, sourcefiles, var, cwd): """ Tests plot_realizations_1d for a timeseries plot Parameters ---------- directory : string the directory to link the files to sourcefiles : list a list of the locations of the files to link var : string the variable plotted cwd : string directory of the test modules """ ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) data = cd.loadfiles(ens, var, cdostr='-fldmean -yearmean', toDatetime=True) fig, axt = plt.subplots(1, 1, figsize=(8, 8)) cd.plot_realizations_1d(data, var, 'time', ax=axt, pdf='tsplot', kwargs={ 'color': 'r', 'alpha': 0.3 }) plotcompare(directory, cwd, 'tsplot') os.system('rm tsplot.pdf')
def test_cat_experiments(directory, sourcefiles, var, e1name, e2name): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.cat_experiments(ens, var, exp1_name=e1name, exp2_name=e2name) data = ctt.sha(ens) return data
def test_zonal_mean(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.zonmean(ens, delete=True) data = ctt.sha(ens) return data
def test_climatology(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.climatology(ens) data = ctt.sha(ens) return data
def test_areamean(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.areamean(ens) data = ctt.sha(ens) return data
def test_remap(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.remap(ens, remap="r1x180") data = ctt.sha(ens) return data
def test_areamean(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.areamean(ens) data = ctt.sha(ens) return data
def test_time_slice(directory, sourcefiles, sd, ed): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.time_slice(ens, start_date=sd, end_date=ed) data = ctt.sha(ens) return data
def test(directory, sourcefiles, cwd): """ Makes a file in /testdata/ name testclasses_file.txt whcih has the ensemble info after using match ensembles and match_realizations """ # first change to a scratch dir and link in test data. The paths are CCCma specific. ctt.loadtestfiles(directory,sourcefiles) f = cwd + '/testdata/testclasses_file.txt' # ========================================================================= # mkensemble # ========================================================================= fp = '*historical*' ens = cd.mkensemble(fp, prefix='') ens.fulldetails_tofile(f) # Create a second cmipdata ensemble fp2 = '*ts*' ens2 = cd.mkensemble(fp2, prefix='') ens.fulldetails_tofile(f) # ========================================================================= # match_ensembles # ========================================================================= print 'Matching ensembles...' enso1, enso2 = cd.match_ensembles(ens, ens2) enso1.sinfo() enso2.sinfo() ens.fulldetails_tofile(f) # ========================================================================= # match_realizations # ========================================================================= print 'Matching realizations...' ensem1, ensem2 = cd.match_realizations(ens, ens2) ensem1.sinfo() ensem2.sinfo() ens.fulldetails_tofile(f)
def test_ensembleenvelope(directory, sourcefiles, var, sd, ed, cwd): """ Tests ensemble_envelope_timeseries Parameters ---------- directory : string the directory to link the files to sourcefiles : list a list of the locations of the files to link var : string the variable plotted sd : int start date for time slice ed : int end date for time slice cwd : string directory of the test modules """ ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.time_slice(ens, sd, ed) ens = cd.remap(ens, 'r360x180', delete=True) ens = cd.my_operator(ens, my_cdo_str='cdo -fldmean -yearmean {infile} {outfile}', output_prefix='processed_', delete=True) cd.ens_stats(ens, var) cd.ensemble_envelope_timeseries(ens, 'ENS-MEAN_processed_remap_ts_Amon_CanESM2_historical_R-MEAN_195001-200012.nc', 'ENS-STD_processed_remap_ts_Amon_CanESM2_historical_STD_195001-200012.nc', var, pdf='ensenv') plotcompare(directory, cwd, 'ensenv') os.system('rm ensenv.pdf')
def test_cat_exp_slices(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.cat_exp_slices(ens) data = ctt.sha(ens) return data
def test_cat_exp_slices(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.cat_exp_slices(ens) data = ctt.sha(ens) return data
def test_climatology(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.climatology(ens) data = ctt.sha(ens) return data
def test_time_anomaly(directory, sourcefiles, sd, ed): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.time_anomaly(ens, start_date=sd, end_date=ed, delete=True) ens.fulldetails() data = ctt.sha(ens) return data
def test_loadingtools(directory, sourcefiles, var): """ Loads the data from a set of files """ ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) data = hashlib.sha1(cd.loadfiles(ens,var)['data']).hexdigest() return {var: data}
def test_time_anomaly(directory, sourcefiles, sd, ed): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.time_anomaly(ens, start_date=sd, end_date=ed, delete=True) ens.fulldetails() data = ctt.sha(ens) return data
def test_ens_stats(directory, sourcefiles, var): ctt.loadtestfiles(directory, [sourcefiles[0]]) filepattern = "*.nc" ens = cd.mkensemble(filepattern) cd.ens_stats(ens, var) filepattern = "ENS*" ens = cd.mkensemble(filepattern) data = ctt.sha(ens) return data
def test_ens_stats(directory, sourcefiles, var): ctt.loadtestfiles(directory, [sourcefiles[0]]) filepattern = '*.nc' ens = cd.mkensemble(filepattern) cd.ens_stats(ens, var) filepattern = 'ENS*' ens = cd.mkensemble(filepattern) data = ctt.sha(ens) return data
def test_my_operator(directory, sourcefiles, var, e1name, e2name): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) ens = cd.cat_experiments(ens, var, exp1_name=e1name, exp2_name=e2name) filepattern = "*.nc" ens = cd.mkensemble(filepattern) my_cdo_str = "cdo remapdis,r1x180 -zonmean -seldate,1950-01-01,2000-12-31\ -sub {infile} -timmean -seldate,1950-01-01,2000-12-31 {infile}\ {outfile}" ens = cd.my_operator(ens, my_cdo_str, output_prefix="test_", delete=True) data = ctt.sha(ens) return data
def test_my_operator(directory, sourcefiles, var, e1name, e2name): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.cat_experiments(ens, var, exp1_name=e1name, exp2_name=e2name) filepattern = '*.nc' ens = cd.mkensemble(filepattern) my_cdo_str = 'cdo remapdis,r1x180 -zonmean -seldate,1950-01-01,2000-12-31\ -sub {infile} -timmean -seldate,1950-01-01,2000-12-31 {infile}\ {outfile}' ens = cd.my_operator(ens, my_cdo_str, output_prefix='test_', delete=True) data = ctt.sha(ens) return data
def test_1dtimeseries(directory, sourcefiles, var, cwd): """ Tests plot_realizations_1d for a timeseries plot Parameters ---------- directory : string the directory to link the files to sourcefiles : list a list of the locations of the files to link var : string the variable plotted cwd : string directory of the test modules """ ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) data = cd.loadfiles(ens, var, cdostr='-fldmean -yearmean', toDatetime=True) fig, axt = plt.subplots(1, 1, figsize=(8, 8)) cd.plot_realizations_1d(data, var, 'time', ax=axt, pdf='tsplot', kwargs={'color': 'r', 'alpha': 0.3}) plotcompare(directory, cwd, 'tsplot') os.system('rm tsplot.pdf')
def test_ensembleenvelope(directory, sourcefiles, var, sd, ed, cwd): """ Tests ensemble_envelope_timeseries Parameters ---------- directory : string the directory to link the files to sourcefiles : list a list of the locations of the files to link var : string the variable plotted sd : int start date for time slice ed : int end date for time slice cwd : string directory of the test modules """ ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) ens = cd.time_slice(ens, sd, ed) ens = cd.remap(ens, 'r360x180', delete=True) ens = cd.my_operator( ens, my_cdo_str='cdo -fldmean -yearmean {infile} {outfile}', output_prefix='processed_', delete=True) cd.ens_stats(ens, var) cd.ensemble_envelope_timeseries( ens, 'ENS-MEAN_processed_remap_ts_Amon_CanESM2_historical_R-MEAN_195001-200012.nc', 'ENS-STD_processed_remap_ts_Amon_CanESM2_historical_STD_195001-200012.nc', var, pdf='ensenv') plotcompare(directory, cwd, 'ensenv') os.system('rm ensenv.pdf')
def test_starting_files(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = '*.nc' ens = cd.mkensemble(filepattern) data = ctt.sha(ens) return data
def test_starting_files(directory, sourcefiles): ctt.loadtestfiles(directory, sourcefiles) filepattern = "*.nc" ens = cd.mkensemble(filepattern) data = ctt.sha(ens) return data