test_conversion.py 954 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import climate_categories as cc
  2. import primap2 as pm2
  3. import pytest
  4. def test_yaml_to_python():
  5. cat = cc.from_yaml("FAO.yaml")
  6. cat.to_python("FAO.py")
  7. @pytest.mark.xfail
  8. def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
  9. # make categorisation A from yaml
  10. categorisation_a = cc.from_yaml("FAO.yaml")
  11. # make categorisation B from yaml
  12. categorisation_b = cc.IPCC2006_PRIMAP
  13. # categories not part of climate categories so we need to add them manually
  14. cats = {
  15. "A": categorisation_a,
  16. "B": categorisation_b,
  17. }
  18. # make conversion from csv
  19. conv = cc.Conversion.from_csv("conversion.FAO.IPPCC2006_PRIMAP.csv", cats=cats)
  20. ds = pm2.open_dataset(
  21. "extracted_data/v2024-11-14/FAOSTAT_Agrifood_system_emissions_v2024-11-14.nc"
  22. )
  23. result = ds.pr.convert(
  24. dim="category",
  25. conversion=conv,
  26. auxiliary_dimensions={"gas": "source (gas)"},
  27. )
  28. assert result