Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate variables with different units #460

Open
pjuergens opened this issue Nov 19, 2020 · 1 comment
Open

Aggregate variables with different units #460

pjuergens opened this issue Nov 19, 2020 · 1 comment

Comments

@pjuergens
Copy link
Contributor

If I have an IamDataFrame df with two variables, 'Primary Energy|Gas' with unit 'TWh/yr' and 'Emission Factor|Gas' with unit 'Mt/TWh'. If I want to aggregate both variables to 'Emissions|Gas' doing the following:

df.aggregate('Emissions|Gas', components=['Primary Energy|Gas', 'Emission Factor|Gas'], method=np.prod)

instead of getting the unit 'Mt/yr' I get two entries with units 'TWh/yr' and 'Mt/TWh'.
I'd like to have either

  1. automatic unit conversion or
  2. manual unit conversion like
    df.aggregate('Emissions|Gas', components=['Primary Energy|Gas', 'Emission Factor|Gas'], method=np.prod, unit='Mt/TWh)

Currently as a workaround I'm doing something like
temp_df = df.convert_unit('Mt/TWh', to='Mt/yr', factor=1)
temp_df = temp_df.convert_unit('TWh/yr', to='Mt/yr', factor=1)
temp_df.aggregate('Emissions|Gas', components=['Primary Energy|Gas', 'Emission Factor|Gas'], method=np.prod)

@danielhuppmann
Copy link
Member

Thanks @pjuergens for raising this issue!

You are trying to do something that's going beyond the intent of the aggregation-function. But you actually found a nice workaround using standard pyam functions, so kudos!

Anyway, @gaurav-ganti started a similar issue (see #332) and in response @gidden started a PR a few months ago (see #333) that implemented basic operations (multiplication, division, addition, subtraction). Unfortunately, this development didn't quite make it into the master branch, but if you feel up to the task, you could look into this and bring it to completion! What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants