Skip to content

Commit 14e6402

Browse files
committed
Revise tests for carbon_pool adjustments
1 parent 1e75847 commit 14e6402

File tree

1 file changed

+94
-30
lines changed

1 file changed

+94
-30
lines changed

message_ix/tests/test_emission_pool.py

Lines changed: 94 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_tax_emission_pool_world(test_mp):
191191
pdt.assert_frame_equal(exp, obs, check_dtype=False)
192192

193193

194-
def test_bound_emission_pool(test_mp):
194+
def test_bound_emission_pool_up(test_mp):
195195
s = make_westeros(test_mp, quiet=True)
196196
prep_scenario(s, test_mp)
197197

@@ -206,8 +206,8 @@ def test_bound_emission_pool(test_mp):
206206
"unit": "???",
207207
}
208208
)
209-
s.add_par("bound_emission_pool", df)
210-
s.commit("bound_emission_pool added")
209+
s.add_par("bound_emission_pool_up", df)
210+
s.commit("bound_emission_pool_up added")
211211

212212
s.solve()
213213

@@ -242,7 +242,7 @@ def test_bound_emission_pool(test_mp):
242242
pdt.assert_frame_equal(exp, obs, check_dtype=False)
243243

244244

245-
def test_bound_emission_pool_removal(test_mp):
245+
def test_bound_emission_pool_lo(test_mp):
246246
s = make_westeros(test_mp, quiet=True)
247247
prep_scenario(s, test_mp)
248248

@@ -257,31 +257,95 @@ def test_bound_emission_pool_removal(test_mp):
257257
"unit": "???",
258258
}
259259
)
260-
s.add_par("bound_emission_pool", df)
261-
s.commit("bound_emission_pool added")
260+
s.add_par("bound_emission_pool_up", df)
261+
262+
df = pd.DataFrame(
263+
{
264+
"node": "Westeros",
265+
"type_emission": "GHG",
266+
"type_tec": "all",
267+
"year": [710],
268+
"value": [84000],
269+
"unit": "???",
270+
}
271+
)
272+
s.add_par("bound_emission_pool_lo", df)
273+
274+
s.commit("bound_emission_pool_lo and _up added")
275+
276+
s.solve()
277+
278+
exp = pd.DataFrame(
279+
{
280+
"node": "Westeros",
281+
"emission": "CO2",
282+
"type_tec": "all",
283+
"year": [700, 710, 720],
284+
"lvl": [86254.74797636835, 84000.0, 85000.0],
285+
"mrg": 0.0,
286+
}
287+
)
288+
289+
obs = s.var("EMISS_POOL")
290+
291+
pdt.assert_frame_equal(exp, obs, check_dtype=False)
292+
293+
exp = pd.DataFrame(
294+
{
295+
"node": "Westeros",
296+
"type_emission": "GHG",
297+
"type_tec": "all",
298+
"year": [720],
299+
"lvl": [33.075572],
300+
"mrg": 0.0,
301+
}
302+
)
303+
304+
obs = s.var("PRICE_EMISSION_POOL")
305+
306+
pdt.assert_frame_equal(exp, obs, check_dtype=False)
307+
308+
309+
def test_bound_emission_pool_up_removal(test_mp):
310+
s = make_westeros(test_mp, quiet=True)
311+
prep_scenario(s, test_mp)
312+
313+
s.check_out()
314+
df = pd.DataFrame(
315+
{
316+
"node": "Westeros",
317+
"type_emission": "GHG",
318+
"type_tec": "all",
319+
"year": [700, 710, 720],
320+
"value": [87000, 86000, 85000],
321+
"unit": "???",
322+
}
323+
)
324+
s.add_par("bound_emission_pool_up", df)
325+
s.commit("bound_emission_pool_up added")
262326

263327
# Ensure that bound has been added
264-
obs = s.par("bound_emission_pool")
328+
obs = s.par("bound_emission_pool_up")
265329
pdt.assert_frame_equal(df, obs, check_dtype=False)
266330

267331
s.solve()
268332

269333
# Ensure that is_ set for bound has been added upon solving
270334
exp = df.drop(["value", "unit"], axis=1)
271-
obs = s.set("is_bound_emission_pool")
335+
obs = s.set("is_bound_emission_pool_up")
272336
pdt.assert_frame_equal(exp, obs, check_dtype=False)
273337

274338
# Esnure that is_ set is removed when removing parameter
275339
s.remove_solution()
276340
s.check_out()
277-
s.remove_par("bound_emission_pool", df)
341+
s.remove_par("bound_emission_pool_up", df)
278342
s.commit("bound_emission_poll removed")
279343

280-
obs = s.set("is_bound_emission_pool")
344+
obs = s.set("is_bound_emission_pool_up")
281345
assert obs.empty is True
282346

283347

284-
def test_bound_emission_pool_modification_inc_yrs(test_mp):
348+
def test_bound_emission_pool_up_modification_inc_yrs(test_mp):
285349
s = make_westeros(test_mp, quiet=True)
286350
prep_scenario(s, test_mp)
287351

@@ -296,18 +360,18 @@ def test_bound_emission_pool_modification_inc_yrs(test_mp):
296360
"unit": "???",
297361
}
298362
)
299-
s.add_par("bound_emission_pool", df)
300-
s.commit("bound_emission_pool added")
363+
s.add_par("bound_emission_pool_up", df)
364+
s.commit("bound_emission_pool_up added")
301365

302366
# Ensure that bound has been added
303-
obs = s.par("bound_emission_pool")
367+
obs = s.par("bound_emission_pool_up")
304368
pdt.assert_frame_equal(df, obs, check_dtype=False)
305369

306370
s.solve()
307371

308372
# Ensure that is_ set for bound has been added upon solving
309373
exp = df.drop(["value", "unit"], axis=1)
310-
obs = s.set("is_bound_emission_pool")
374+
obs = s.set("is_bound_emission_pool_up")
311375
pdt.assert_frame_equal(exp, obs, check_dtype=False)
312376

313377
# Now check that when the dataframe is extended, if the "is_" set
@@ -324,22 +388,22 @@ def test_bound_emission_pool_modification_inc_yrs(test_mp):
324388
"unit": "???",
325389
}
326390
)
327-
s.add_par("bound_emission_pool", df)
328-
s.commit("bound_emission_pool added")
391+
s.add_par("bound_emission_pool_up", df)
392+
s.commit("bound_emission_pool_up added")
329393

330394
# Ensure that bound has been added
331-
obs = s.par("bound_emission_pool")
395+
obs = s.par("bound_emission_pool_up")
332396
pdt.assert_frame_equal(df, obs, check_dtype=False)
333397

334398
s.solve()
335399

336400
# Ensure that is_ set for bound has been added upon solving
337401
exp = df.drop(["value", "unit"], axis=1)
338-
obs = s.set("is_bound_emission_pool")
402+
obs = s.set("is_bound_emission_pool_up")
339403
pdt.assert_frame_equal(exp, obs, check_dtype=False)
340404

341405

342-
def test_bound_emission_pool_modification_red_yrs(test_mp):
406+
def test_bound_emission_pool_up_modification_red_yrs(test_mp):
343407
s = make_westeros(test_mp, quiet=True)
344408
prep_scenario(s, test_mp)
345409

@@ -354,18 +418,18 @@ def test_bound_emission_pool_modification_red_yrs(test_mp):
354418
"unit": "???",
355419
}
356420
)
357-
s.add_par("bound_emission_pool", df)
358-
s.commit("bound_emission_pool added")
421+
s.add_par("bound_emission_pool_up", df)
422+
s.commit("bound_emission_pool_up added")
359423

360424
# Ensure that bound has been added
361-
obs = s.par("bound_emission_pool")
425+
obs = s.par("bound_emission_pool_up")
362426
pdt.assert_frame_equal(df, obs, check_dtype=False)
363427

364428
s.solve()
365429

366430
# Ensure that is_ set for bound has been added upon solving
367431
exp = df.drop(["value", "unit"], axis=1)
368-
obs = s.set("is_bound_emission_pool")
432+
obs = s.set("is_bound_emission_pool_up")
369433
pdt.assert_frame_equal(exp, obs, check_dtype=False)
370434

371435
# Now check that when the dataframe is extended, if the "is_" set
@@ -374,8 +438,8 @@ def test_bound_emission_pool_modification_red_yrs(test_mp):
374438
s.check_out()
375439

376440
# Remove existing
377-
df = s.par("bound_emission_pool")
378-
s.remove_par("bound_emission_pool", df)
441+
df = s.par("bound_emission_pool_up")
442+
s.remove_par("bound_emission_pool_up", df)
379443

380444
df = pd.DataFrame(
381445
{
@@ -387,16 +451,16 @@ def test_bound_emission_pool_modification_red_yrs(test_mp):
387451
"unit": "???",
388452
}
389453
)
390-
s.add_par("bound_emission_pool", df)
391-
s.commit("bound_emission_pool added")
454+
s.add_par("bound_emission_pool_up", df)
455+
s.commit("bound_emission_pool_up added")
392456

393457
# Ensure that bound has been added
394-
obs = s.par("bound_emission_pool")
458+
obs = s.par("bound_emission_pool_up")
395459
pdt.assert_frame_equal(df, obs, check_dtype=False)
396460

397461
s.solve()
398462

399463
# Ensure that is_ set for bound has been added upon solving
400464
exp = df.drop(["value", "unit"], axis=1)
401-
obs = s.set("is_bound_emission_pool")
465+
obs = s.set("is_bound_emission_pool_up")
402466
pdt.assert_frame_equal(exp, obs, check_dtype=False)

0 commit comments

Comments
 (0)