pyam icon indicating copy to clipboard operation
pyam copied to clipboard

Aggregate variables with different units

Open pjuergens opened this issue 3 years ago • 1 comments

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)

pjuergens avatar Nov 19 '20 14:11 pjuergens

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?

danielhuppmann avatar Nov 19 '20 14:11 danielhuppmann