Skip to content

Commit

Permalink
Add check that regional sum == global
Browse files Browse the repository at this point in the history
  • Loading branch information
znichollscr committed Jan 9, 2025
1 parent 994c9fa commit 88e6a2e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion notebooks/0104_GFED-BB4CMIP-postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,34 @@

# %%
df_renamed_desired_units = convert_to_desired_units(df_renamed)
df_renamed_desired_units.columns = df_renamed_desired_units.columns.astype(int)

# %%
out_global = df_renamed_desired_units.loc[pix.ismatch(region="World")]
out_global

# %%
out_national = df_reordered.loc[~pix.ismatch(region="World")]
out_national = df_renamed_desired_units.loc[~pix.ismatch(region="World")]
out_national

# %%
assert out_national.shape[0] + out_global.shape[0] == df_renamed_desired_units.shape[0]

# %% [markdown]
# Check that national sums equal global total.

# %%
national_sums_checker = (
pix.assignlevel(out_national.groupby(["model", "scenario", "variable", "unit"]).sum(), region="World")
.reset_index()
.set_index(out_global.index.names)
)
national_sums_checker.columns = national_sums_checker.columns.astype(int)
national_sums_checker

# %%
pd.testing.assert_frame_equal(out_global, national_sums_checker, check_like=True)

# %%
out_global.to_csv(out_path_global)
out_path_global
Expand Down

0 comments on commit 88e6a2e

Please sign in to comment.