def get_gcm_data_from_catalogue(self, catalogue=None):
        """
        Output: dictionary of GCM data arrays (historical + RCP)
        """

        self.current_model = 'gcm'

        catalogue = self.catalogue if catalogue is None else catalogue

        # Get historical run
        print("Loading historical data array...(1/{})".format(len(self.settings['future_rcp']) + 1))
        idx_historical = catalogue['Experiment'].str.find('historical').idxmax()
        da_historical = bp.open_dataset(catalogue.iloc[idx_historical])[self.settings['variable_name_gcm']]
        da_historical = dataprocessing.slice_time(da_historical, self.settings['model_start'], self.settings['model_end'])

        # Get RCP runs
        self.gcm_data = {}
        for i, rcp in enumerate(self.settings['future_rcp']):

            print("Loading {} data array...({}/{})".format(rcp, i + 2, len(self.settings['future_rcp']) + 1))

            idx_rcp = catalogue['Experiment'].str.find(rcp).idxmax()
            da_rcp = bp.open_dataset(catalogue.iloc[idx_rcp])[self.settings['variable_name_gcm']]
            da_rcp = dataprocessing.slice_time(da_rcp, self.settings['model_start'], self.settings['model_end'])

            da_gcm = xr.concat([da_historical, da_rcp], dim='time')
            self.gcm_data[rcp] = da_gcm

        print("Data arrays loaded.")

        return self.gcm_data
示例#2
0
def catalog_to_xr(catl_model):
    '''
    convert catalogue enetry of climate model to xarray
    Parameters:
    ----------
    catl_model (pandas.DataFrame 1 row)

    Returns:
    --------
    data (Xarray):
        with latitude, longitude, time and height dimensions 
        filled with the selected variable (e.g. tasmax)
    '''
    for index, row in catl_model.iterrows():
        ds = bp.open_dataset(row)

    df_xr = ds.tasmax
    return df_xr
示例#3
0
import baspy as bp
import xarray as xr
''' 
Define scope of CMIP6 that we want (our catalogue)
* amip = atmosphere-only run (with transient/observed sea surface temperatures)
* tasmin,tasmax = minimum/maximum temperature over period
* CMOR (Climate Model Output Rewriter), defines, amongst other things, the temporal 
    frequency of the data (monthly, daily etc)
    see: https://github.com/PCMDI/cmip6-cmor-tables/tree/master/Tables
* Model = our chosen CMIP6 climate model
* RunID = the run ID :-)
'''
catlg = bp.catalogue(dataset='cmip6',
                     Experiment='amip',
                     Var=['tasmax', 'tasmin'],
                     CMOR='day',
                     Model='CNRM-CM6-1',
                     RunID='r1i1p1f2')
''' Read Datasets using BASpy wrapper for Xarray '''
tasmin_ds = bp.open_dataset(catlg[catlg.Var == 'tasmin'])
tasmax_ds = bp.open_dataset(catlg[catlg.Var == 'tasmax'])
''' extract DataArray from Dataset '''
tasmin = tasmin_ds.tasmin
tasmax = tasmax_ds.tasmax
''' 
Now analyse CMIP6 data using the Xarray framework 
[1] http://xarray.pydata.org/en/stable/
[2] https://github.com/scotthosking/notebooks/blob/master/getting_started_with_Xarray%2BDask.ipynb
'''
示例#4
0
# -*- coding: UTF-8 -*-
from jasmin.downloader import dataprocessing as dp
from baspy._xarray.util import extract_region
import pandas as pd
import baspy as bp

## _cm ending means climate model
## tas means surface temp

cat_model = bp.catalogue(dataset='cmip5',
                         Model='HadGEM2-CC',
                         Frequency='day',
                         Experiment='rcp45',
                         RunID='r1i1p1',
                         Var='tas').reset_index(drop=True)

for index, row in cat_model.iterrows():
    cm = bp.open_dataset(row)

tas_cm = cm.tas

lon_cor_cm = dp.roll_lon(tas_cm)

## Extract a specific region
extr_reg_cm = extract_region(lon_cor_cm, kabul)

reg_time_sliced_cm = dp.slice_time(extr_reg_cm, 1979, 2050)