def test_cumulative_out_of_range(): # set logger level to exclude warnings in unit test output logging.getLogger("pyam").setLevel('ERROR') # note that the series is not order and the index is defined as float y = pd.Series(data=[np.nan, 1, 3, 1], index=[2002., 2005., 2007., 2013.]) assert cumulative(y, 2008, 2015) is np.nan logging.getLogger("pyam").setLevel('NOTSET')
def overshoot_severity(x, meta): exceedance_yr = meta.loc[x.name[0:2]]['exceedance year|1.5°C'] return_yr = meta.loc[x.name[0:2]]['return year|1.5°C'] - 1 # do not include year in which mean temperature returns to below 1.5 if exceedance_yr > 0 and return_yr > 0: return pyam.cumulative( x, exceedance_yr, return_yr) - (return_yr - exceedance_yr + 1) * 1.5
def test_cumulative(): # note that the series is not order and the index is defined as float y = pd.Series(data=[np.nan, 1, 3, 1], index=[2002.0, 2007.0, 2003.0, 2013.0]) assert cumulative(y, 2008, 2013) == 6
# ### Cumulative CO2 emissions until peak warming #%% def get_from_meta_column(df, x, col): val = df.meta.loc[x.name[0:2], col] return val if val < np.inf else max(x.index) #%% name = 'cumulative CO2 emissions ({} to peak warming, {})'.format( baseyear, cumulative_unit) sr1p5.set_meta( co2.apply(lambda x: pyam.cumulative(x, first_year=baseyear, last_year=get_from_meta_column( sr1p5, x, 'year of peak warming (MAGICC6)')), raw=False, axis=1), name) meta_docs[ name] = 'cumulative net CO2 emissions from {} until the year of peak warming as computed by MAGICC6 (including the year of peak warming, {})'.format( baseyear, cumulative_unit) #%% (sr1p5.filter(category=cats).scatter( x='cumulative CO2 emissions (2016 to peak warming, {})'.format( cumulative_unit), y='median warming at peak (MAGICC6)', color='category'))