Exemple #1
0
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
Exemple #2
0
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)
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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')
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
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
Exemple #10
0
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
Exemple #11
0
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
Exemple #12
0
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
Exemple #13
0
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
Exemple #14
0
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)
Exemple #15
0
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')               
Exemple #16
0
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
Exemple #17
0
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
Exemple #18
0
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
Exemple #19
0
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
Exemple #20
0
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}
Exemple #21
0
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
Exemple #22
0
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
Exemple #23
0
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
Exemple #24
0
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
Exemple #25
0
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
Exemple #26
0
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') 
Exemple #27
0
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')
Exemple #28
0
def test_starting_files(directory, sourcefiles):
    ctt.loadtestfiles(directory, sourcefiles)
    filepattern = '*.nc'
    ens = cd.mkensemble(filepattern)
    data = ctt.sha(ens)
    return data
Exemple #29
0
def test_starting_files(directory, sourcefiles):
    ctt.loadtestfiles(directory, sourcefiles)
    filepattern = "*.nc"
    ens = cd.mkensemble(filepattern)
    data = ctt.sha(ens)
    return data