pik-primap / primap2

The next generation of the PRIMAP climate policy analysis suite
https://primap2.readthedocs.io
Apache License 2.0
8 stars 2 forks source link

Downscaling does not work if all values are zero #254

Open crdanielbusch opened 3 weeks ago

crdanielbusch commented 3 weeks ago

Describe the bug

If all values of the basket contents are zero, the downscale_timeseries function does not work.

Expected behavior

The function should fill all empty values with zeros.

Screenshots

Screenshot 2024-08-27 at 15 15 41

System (please complete the following information):

mikapfl commented 3 weeks ago

Do you have the exact code which was called?

crdanielbusch commented 3 weeks ago

sample_1.csv

entity,unit,category,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018
CH4,CH4 * gigagram / a,2,,,,,,,,,,,0.0
CO2,CO2 * gigagram / a,2,,,,,,,,,,,0.0
KYOTOGHG (AR5GWP100), CO2 * gigagram / a,2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
N2O,N2O * gigagram / a,2,,,,,,,,,,,0.0

sample_2.csv

entity,unit,category,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018
CH4,CH4 * gigagram / a,2,,,,,,,,,,,0.0
CO2,CO2 * gigagram / a,2,,,,,,,,,,,1
KYOTOGHG (AR5GWP100), CO2 * gigagram / a,2,1,1,1,1,1,1,1,1,1,1,1
N2O,N2O * gigagram / a,2,,,,,,,,,,,0.0
import pandas as pd
import primap2 as pm2

df = pd.read_csv("sample.csv")

data_if = pm2.pm2io.convert_wide_dataframe_if(
    df,
    coords_cols={
        "category": "category",
        "entity": "entity",
        "unit": "unit",
    },
    coords_defaults={
        "source": "KNA-GHG-Inventory",
        "provenance": "measured",
        "area": "KNA",
        "scenario": "BUR1",
    },
    coords_terminologies={
        "area": "ISO3",
        "category": "IPCC2006_PRIMAP",
        "scenario": "PRIMAP",
    },
    coords_value_mapping=None,
    filter_remove=None,
    meta_data={
        "references": "https://unfccc.int/documents/633382",
        "rights": "",  # unknown
        "contact": "daniel-busch@climate-resource.de",
        "title": "Saint Kitts and Nevis. Biennial update report (BUR). BUR1",
        "comment": "Read fom pdf by Daniel Busch",
        "institution": "UNFCCC",
    },
    convert_str=True,
    time_format="%Y",
)

data_pm2 = pm2.pm2io.from_interchange_format(data_if)

data_pm2 = data_pm2.pr.downscale_gas_timeseries(
    basket="KYOTOGHG (AR5GWP100)",
    basket_contents=[
        "CO2",
        "CH4",
        "N2O",
    ],
    skipna=True,
    skipna_evaluation_dims=None,
)

data_pm2_downscale_if = data_pm2.pr.to_interchange_format()

Values are filled with sample_2 but not with sample_1.