-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add feature to "downscale" timeseries data to subregions (#313)
- Loading branch information
1 parent
67dd7e9
commit 510851d
Showing
5 changed files
with
94 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
import pandas as pd | ||
import pyam | ||
|
||
|
||
@pytest.mark.parametrize("variable", ( | ||
('Primary Energy'), | ||
(['Primary Energy', 'Primary Energy|Coal']), | ||
)) | ||
def test_downscale_region(aggregate_df, variable): | ||
df = aggregate_df | ||
df.set_meta([1], name='test') | ||
|
||
regions = ['reg_a', 'reg_b'] | ||
|
||
# return as new IamDataFrame | ||
obs_df = df.downscale_region(variable, proxy='Population') | ||
exp_df = df.filter(variable=variable, region=regions) | ||
assert pyam.compare(obs_df, exp_df).empty | ||
pd.testing.assert_frame_equal(obs_df.meta, exp_df.meta) | ||
|
||
# append to `self` (after removing to-be-downscaled timeseries) | ||
inplace_df = df.filter(variable=variable, region=regions, keep=False) | ||
inplace_df.downscale_region(variable, proxy='Population', append=True) | ||
assert pyam.compare(inplace_df, df).empty | ||
pd.testing.assert_frame_equal(inplace_df.meta, df.meta) |