def test_run_scenarios_multiple(self): ts1_erf = np.linspace(0, 4, 101) ts2_erf = np.sin(np.linspace(0, 4, 101)) inp = ScmRun( data=np.vstack([ts1_erf, ts2_erf]).T, index=np.linspace(1750, 1850, 101).astype(int), columns={ "scenario": ["test_scenario_1", "test_scenario_2"], "model": "unspecified", "climate_model": "junk input", "variable": "Effective Radiative Forcing", "unit": "W/m^2", "region": "World", }, ) model = self.tmodel() res = model.run_scenarios(inp) for scenario_ts in inp.groupby("scenario"): scenario = scenario_ts.get_unique_meta("scenario", no_duplicates=True) model.set_drivers( scenario_ts.values.squeeze() * ur(inp.get_unique_meta("unit", no_duplicates=True))) model.reset() model.run() res_scen = res.filter(scenario=scenario) npt.assert_allclose( res_scen.filter( variable="Surface Temperature|Upper").values.squeeze(), model._temp_upper_mag, ) assert (res.filter( variable="Surface Temperature|Upper").get_unique_meta( "unit", no_duplicates=True) == "delta_degC") npt.assert_allclose( res_scen.filter( variable="Surface Temperature|Lower").values.squeeze(), model._temp_lower_mag, ) assert (res.filter( variable="Surface Temperature|Lower").get_unique_meta( "unit", no_duplicates=True) == "delta_degC") npt.assert_allclose( res_scen.filter(variable="Heat Uptake").values.squeeze(), model._rndt_mag, ) assert (res.filter(variable="Heat Uptake").get_unique_meta( "unit", no_duplicates=True) == "W/m^2")
def _check_heat_content_heat_uptake_consistency(res): hc_deltas = ScmRun( res.filter(variable="Heat Content", region="World") .timeseries(time_axis="year") .diff(axis="columns") ) hc_deltas["unit"] = "{} / yr".format(hc_deltas.get_unique_meta("unit", True)) ratio = hc_deltas.divide( res.filter(variable="Heat Uptake", region="World"), op_cols={"variable": "Heat Content / Heat Uptake"}, ) earth_surface_area = 5.100536e14 npt.assert_allclose( earth_surface_area, ratio.convert_unit("m^2").timeseries(drop_all_nan_times=True), )