iiasa / climate-assessment

https://climate-assessment.readthedocs.io/en/latest
MIT License
19 stars 18 forks source link

Input data with output "AR6 climate diagnostics" only throws a duplication error at the end of the workflow #9

Open jkikstra opened 2 years ago

jkikstra commented 2 years ago

At the moment, if your input data has for instance AR6 climate diagnostics|Infilled|Emissions|Kyoto Gases (AR6-GWP100), then at the end of the workflow, you will probably see something like the following error:

Emissions|VOC|Energy|Demand|Transportation, Emissions|VOC|Energy|Supply, Emissions|VOC|Industrial Processes are being ignored for the calculation of the GWP100.
2022-06-14 22:54:40 pyam.logging MainThread - ERROR:  Duplicate rows in `data`:
       model               scenario region                                           variable             unit  year
0  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2015
1  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2016
2  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2017
3  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2018
4  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2019
...
Traceback (most recent call last):
  File "scripts/run_workflow.py", line 7, in <module>
    climate_assessment.cli.workflow()
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\kikstra\documents\2022_unep\climate-assessment\src\climate_assessment\cli.py", line 446, in workflow
    gwp=gwp,
  File "c:\users\kikstra\documents\2022_unep\climate-assessment\src\climate_assessment\cli.py", line 639, in run_workflow
    model=model,
  File "c:\users\kikstra\documents\2022_unep\climate-assessment\src\climate_assessment\postprocess.py", line 65, in do_postprocess
    prefixes=prefixes,
  File "c:\users\kikstra\documents\2022_unep\climate-assessment\src\climate_assessment\utils.py", line 313, in add_gwp100_kyoto_wrapper
    df = add_gwp100_kyoto(df, gwp_instance=gwp, prefix=prefix)
  File "c:\users\kikstra\documents\2022_unep\climate-assessment\src\climate_assessment\utils.py", line 278, in add_gwp100_kyoto
    return pyam.IamDataFrame(pyam.concat([df, kyoto]))
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\pyam\core.py", line 2812, in concat
    return IamDataFrame(pd.concat(ret_data, verify_integrity=False), meta=ret_meta)
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\pyam\core.py", line 158, in __init__
    self._init(data, meta, index=index, **kwargs)
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\pyam\core.py", line 174, in _init
    _data = format_data(data.copy(), index=index, **kwargs)
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\pyam\utils.py", line 374, in format_data
    "Duplicate rows in `data`", df[rows].index.to_frame(index=False)
  File "C:\Users\kikstra\.conda\envs\ca-unep\lib\site-packages\pyam\logging.py", line 32, in raise_data_error
    raise ValueError(msg)
ValueError: Duplicate rows in `data`:
       model               scenario region                                           variable             unit  year
0  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2015
1  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2016
2  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2017
3  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2018
4  IMAGE 3.2  SSP1_SPA1_19I_LIRE_LB  World  AR6 climate diagnostics|Infilled|Emissions|Kyo...  Mt CO2-equiv/yr  2019
...

Would be good to a. check whether this only happens for kyoto gases, or for all ar6 climate diagnostics b. throw an error earlier in the workflow, by adding an input data check, to not find this surprise only once all the calculations have been done