iiasa / aneris

Harmonization of Emissions Trajectories for Integrated Assessment Models
Apache License 2.0
4 stars 11 forks source link

comment out to prevent divide by zero #26

Closed jkikstra closed 2 years ago

jkikstra commented 4 years ago

with a simple input file, this line gives ZeroDivisionError: division by zero at:

File "c:\users\kikstra\documents\github\aneris\aneris\harmonize.py", line 631, in _harmonize_regions
    model = utils.subtract_regions_from_world(model, 'model', base_year)
  File "c:\users\kikstra\documents\github\aneris\aneris\utils.py", line 243, in subtract_regions_from_world
    glb[(glb / total).abs() < threshold] = 0.

@gidden can you check?

gidden commented 4 years ago

This seems like a total sum across all regions (including world) is equal to 0.

The reason this function is called is because some models report global-only emissions in World, which do not exist in a specific region. Therefore they need to be harmonized separately.

Is it possible to assess if 0-only emissions are in the data set to be harmonized?

jkikstra commented 4 years ago

Hi @gidden thanks for having a look!

Yes, I know what it does, but could not figure out why the error comes up in the case of supplying it with data that has only the 'World' region to start with. Perhaps it comes from changes in the pandas package?

It should not be possible that 0-only emissions are provided to harmonization, and this was also not the case in my test case.

In my commit I've put in a check that will, for the model part, only do subtract_regions_from_world() if there are actually other regions in the model data. It's a bit patchy, but perhaps catches one problem that might occur?

gidden commented 4 years ago

Hi Jarmo - if there is only world data, maybe the best way is to do the check before going into _harmonize_regions()?

jkikstra commented 4 years ago

Hi Matt - yes that would be better. However, it seems to me that there is a bit of rewiring required to make that work.

Right now it seems that there are two options, determined by the .yaml input boolean global_harmonization_only.

  1. _harmonize_regions: this will harmonize regions and also gases at a lower detail, but does not have a catch for if there is only world data
  2. _harmonize_global_total: this will harmonize only global regions, but also only total gases for many, rather than just the most detailed data available. Hence, this will crash if for instance only 'Emissions|CO2|Energy and Industrial Processes' is supplied.

So probably a third function, or an extra boolean, should be added that does something like "harmonize_global" (so not gas totals), which is what we do for the climate assessment.

gidden commented 2 years ago

ping on this @jkikstra - if this is no longer need for ar6 pipeline can you close please?