Example #1
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')               
Example #2
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
Example #3
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
Example #4
0
def cmip_average(files, var):
    """ Creates and stores a netCDF file with the average data
        across all the models provided.
        Returns the name of the created file.
    """
    ens = cd.mkensemble('', filenames=files)
    out = 'netcdf/' + var + '_' + 'cmip5.nc'
    # skip if the new file was already made
    if not os.path.isfile(out):
        ens = cd.remap(ens, output_prefix='netcdf/forens-')
        ensemble_means, _ = cd.ens_stats(ens, var, output_prefix='netcdf/')
        os.rename(ensemble_means[0], out)
    return out
Example #5
0
def model_average(ens, var, model):
    """ Creates and stores a netCDF file with the average data
        across the realizations for a given variable, model, and experiment
        Returns the name of the created file.
    """
    new = 'cmipfiles/' + var + '_' + model + '.nc'

    # skip if the new file was already made
    if not os.path.isfile(new):
        means, stdevs = cd.ens_stats(ens, var)
        os.rename(means[0], new)
        os.remove(stdevs[0])
    return new
Example #6
0
def model_average(ens, var, model):
    """ Creates and stores a netCDF file with the average data
        across the realizations for a given variable, model, and experiment
        Returns the name of the created file.
    """
    new = 'cmipfiles/' + var + '_' + model + '.nc'
    
    # skip if the new file was already made
    if not os.path.isfile(new):
        means, stdevs = cd.ens_stats(ens, var)
        os.rename(means[0], new)
        os.remove(stdevs[0])
    return new
Example #7
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')