def setUp(self):
     self.preprocessor = preprocessor.CMIP5Preprocessor('.' + os.sep,
                                                        'test_file',
                                                        'nc',
                                                        'model',
                                                        'experiment',
                                                        institute='MPI',
                                                        mip='Amon',
                                                        realm='atmos')
Beispiel #2
0
    def _get_ensemble_filename(self, the_variable, mip, realm):
        """
        get filename of ensemble mean file
        if required, then all pre-processing steps are done

        Parameters
        ----------
        the_variable : str
            variable name to be processed

        Returns
        -------
        returns filename of file with multi-ensemble means
        """

        # use model parser to generate a list of available institutes and
        # models from data directory
        data_dir = self.data_dir
        if data_dir[-1] != os.sep:
            data_dir += os.sep

        CMP = preprocessor.CMIP5ModelParser(self.data_dir)
        model_list = CMP.get_all_models()

        # model name in configuration file is assumed to be INSTITUTE:MODEL
        institute = self.model.split(':')[0]
        model = self.model.split(':')[1]

        # TODO why is the institute not in the model output name ???
        output_file = get_temporary_directory(
        ) + the_variable + '_' + mip + '_' + model + '_' + self.experiment + '_ensmean.nc'

        if institute not in model_list.keys():
            raise ValueError('Data for this institute is not existing: %s' %
                             institute)

        # do preprocessing of data from multiple ensembles if file
        # already existing, then no processing is done
        C5PP = preprocessor.CMIP5Preprocessor(data_dir,
                                              output_file,
                                              the_variable,
                                              model,
                                              self.experiment,
                                              institute=institute,
                                              mip=mip,
                                              realm=realm)

        # calculate the ensemble mean and store as file
        # also the STDV is calculated on the fly calculated
        # resulting filenames are available by C5PP.outfile_ensmean and C5PP.outfile_ensstd
        C5PP.ensemble_mean(delete=False,
                           start_time=self.start_time,
                           stop_time=self.stop_time)

        return C5PP.outfile_ensmean
Beispiel #3
0
def main():
    from pycmbs.benchmarking import preprocessor
    import datetime as dt
    import sys

    if len(sys.argv) == 3:
        the_experiment = sys.argv[1]
        the_variable = sys.argv[2]
    else:
        # specifiy experiment here
        the_experiment = 'historical'
        the_variable = 'rsds'

    print('Experiment: %s' % the_experiment)
    print('Variable: %s' % the_variable)

    output_dir = '/data/share/mpiles/TRS/PROJECT_RESULTS/EvaClimod/CMIP5_RAWDATA_NEW/radiation/dummy_out/' + the_experiment + '_' + the_variable + '/'
    data_dir = '/data/share/mpiles/TRS/PROJECT_RESULTS/EvaClimod/CMIP5_RAWDATA_NEW/radiation/'

    # init parser that returns a list of institutes and models
    CP = preprocessor.CMIP5ModelParser(data_dir)
    model_list = CP.get_all_models()

    # perform for each institute and model the calculation of ensemble means etc.
    for institute in model_list.keys():
        for model in model_list[institute]:
            output_file = output_dir + the_variable + '_Amon_' + model + '_' + the_experiment + '_ensmean.nc'
            E = preprocessor.CMIP5Preprocessor(data_dir,
                                               output_file,
                                               the_variable,
                                               model,
                                               the_experiment,
                                               institute=institute)
            E.get_ensemble_files()
            E.ensemble_mean(delete=False,
                            start_time=dt.datetime(1979, 1, 1),
                            stop_time=dt.datetime(2012, 12, 31))