예제 #1
0
파일: prept.py 프로젝트: fallisd/cmipdata
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
예제 #2
0
파일: prept.py 프로젝트: wydh/cmipdata
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
예제 #3
0
파일: plot.py 프로젝트: fallisd/cmipdata
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')               
예제 #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
예제 #5
0
def preprocess_models(datapath='./'):
    # where we are starting from
    cwd = os.getcwd()
    # move to where the data is
    os.chdir(datapath)

    # time-merge, remap and zonal mean the model data
    variables = ['uas', 'psl', 'tauu']
    for var in variables:
        # time-merge the data across the historical and rcp45 experiments
        filepattern = var + '_Amon*.nc'
        ens = cd.mkensemble(filepattern)
       
        # remap to a 1x1 grid
        ens_remap = cd.remap(ens,remap='r360x180', delete=True)

        # Compute zonal means
        ens_zonmean = cd.zonmean(ens_remap, delete=False)

    # move back
    os.chdir(cwd)
예제 #6
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')