test_conversion.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. import climate_categories as cc
  2. import pandas as pd
  3. import primap2 as pm2
  4. import xarray as xr
  5. from src.faostat_data_primap.helper.paths import (
  6. downloaded_data_path,
  7. extracted_data_path,
  8. )
  9. from src.faostat_data_primap.read import read_data
  10. def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
  11. # make categorisation A from yaml
  12. categorisation_a = cc.from_python("FAO.py")
  13. # make categorisation B from yaml
  14. categorisation_b = cc.IPCC2006_PRIMAP
  15. # category a not part of climate categories, so we need to add them manually
  16. cats = {
  17. "FAOSTAT": categorisation_a,
  18. "IPCC2006_PRIMAP": categorisation_b,
  19. "gas": cc.cats["gas"],
  20. }
  21. # make conversion from csv
  22. conv = cc.Conversion.from_csv("conversion_FAO_IPPCC2006_PRIMAP.csv", cats=cats)
  23. ds_fao = (
  24. extracted_data_path
  25. / "v2024-11-14/FAOSTAT_Agrifood_system_emissions_v2024-11-14.nc"
  26. )
  27. ds = pm2.open_dataset(ds_fao)
  28. # drop UNFCCC data
  29. ds = ds.drop_sel(source="UNFCCC")
  30. ds_if = ds.pr.to_interchange_format()
  31. da_dict = {}
  32. for var in ds.data_vars:
  33. da_dict[var] = ds[var].pr.convert(
  34. dim="category (FAOSTAT)",
  35. conversion=conv,
  36. auxiliary_dimensions={"gas": "entity"},
  37. )
  38. result = xr.Dataset(da_dict)
  39. # ds = ds.set_coords(("lat", "lon"))
  40. result_if = result.pr.to_interchange_format()
  41. df_all = pd.concat([ds_if, result_if], axis=0, join="outer", ignore_index=True)
  42. compare = df_all.loc[
  43. (df_all["category (IPCC2006_PRIMAP)"] == "3.A")
  44. | (df_all["category (FAOSTAT)"] == "3")
  45. ].sort_values(by="area (ISO3)")
  46. compare_short = compare[
  47. [
  48. "source",
  49. "scenario (FAO)",
  50. "area (ISO3)",
  51. "entity",
  52. "unit",
  53. "category (FAOSTAT)",
  54. "2021",
  55. "2022",
  56. "2023",
  57. "category (IPCC2006_PRIMAP)",
  58. ]
  59. ]
  60. assert compare_short
  61. def test_read(tmp_path):
  62. domains_and_releases_to_read = [
  63. ("farm_gate_agriculture_energy", "2024-11-14"),
  64. ("farm_gate_emissions_crops", "2024-11-14"),
  65. ("farm_gate_livestock", "2024-11-14"),
  66. ("land_use_drained_organic_soils", "2024-11-14"),
  67. ("land_use_fires", "2024-11-14"),
  68. ("land_use_forests", "2024-11-14"),
  69. ("pre_post_agricultural_production", "2024-11-14"),
  70. ]
  71. read_data(
  72. domains_and_releases_to_read=domains_and_releases_to_read,
  73. read_path=downloaded_data_path,
  74. save_path=tmp_path,
  75. )
  76. def test_yaml_to_python():
  77. cat = cc.from_yaml("FAO.yaml")
  78. cat.to_python("FAO.py")
  79. def test_python_to_yaml():
  80. from FAO import spec
  81. cat = cc.from_spec(spec)
  82. assert cat
  83. def test_make_dict_comprehension_for_faster_typing(): # noqa: PLR0912 PLR0915
  84. spec = {
  85. "name": "FAOSTAT",
  86. "title": (
  87. "Food and Agriculture Organization of the United Nations (FAO) "
  88. "FAOSTAT data set categorisation"
  89. ),
  90. "comment": "Needed to add FAOSTAT data to PRIMAP-hist",
  91. "references": "",
  92. "institution": "FAO",
  93. "hierarchical": True,
  94. "last_update": "2024-12-10",
  95. "version": "2024",
  96. "total_sum": True,
  97. "canonical_top_level_category": "0",
  98. }
  99. categories = {}
  100. # 0. main categories
  101. categories["0"] = {
  102. "title": "Total",
  103. "comment": "All emissions and removals",
  104. "children": [["1", "2", "3", "4", "5", "6", "7"]],
  105. }
  106. children_1 = ["1.A", "1.B"]
  107. children_2 = ["2.A", "2.B", "2.C", "2.D", "2.E"]
  108. children_3 = [f"3.{i}" for i in "ABCDEFGHIJKLMNOPQR"]
  109. # children_4 = ["4.A"]
  110. # children_5 = ["5.A", "5.B"]
  111. # children_6 = ["6.A", "6.B", "6.C"]
  112. # children_7 = [f"3.{i}" for i in "ABCDEFGHIJKLM"]
  113. main_categories = (
  114. # category code, name and comment, gases, children
  115. ("1", "Crops", ["CH4", "N2O"], children_1),
  116. (
  117. "2",
  118. "Energy use in agriculture",
  119. ["CH4", "N2O", "CO2"],
  120. children_2,
  121. ),
  122. ("3", "Livestock", ["CH4", "N2O"], children_3),
  123. # ("4", "Forest", ["CO2"], children_4),
  124. # (
  125. # "5",
  126. # "Drained organic soils",
  127. # ["N2O", "CO2"],
  128. # children_5,
  129. # ),
  130. # ("6", "Fires", ["CH4", "N2O", "CO2"], children_6),
  131. # (
  132. # "7",
  133. # "Pre and post agricultural production",
  134. # ["CH4", "N2O", "CO2"],
  135. # children_7,
  136. # ),
  137. )
  138. for code, name, gases, children in main_categories:
  139. categories[code] = {
  140. "title": name,
  141. "comment": name,
  142. # "alternative_codes": code.replace(".", ""),
  143. "children": [children],
  144. "info": {"gases": gases},
  145. }
  146. # 1. crops
  147. # all crops category
  148. code_all_crops = "1.A"
  149. codes_crops = [f"1.A.{i}" for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]
  150. categories[code_all_crops] = {
  151. "title": "All crops",
  152. "comment": "All crops",
  153. # "alternative_codes": code_all_crops.replace(".", ""),
  154. "children": [codes_crops],
  155. "info": {"gases": ["CH4", "N2O"]},
  156. }
  157. crops = [
  158. "Wheat",
  159. "Rice",
  160. "Potatoes",
  161. "Millet",
  162. "Barley",
  163. "Maize (corn)",
  164. "Sugar cane",
  165. "Beans, dry",
  166. "Oats",
  167. "Rye",
  168. "Sorghum",
  169. "Soya beans",
  170. ]
  171. crop_burnings = [
  172. True,
  173. True,
  174. False,
  175. False,
  176. False,
  177. True,
  178. True,
  179. False,
  180. False,
  181. False,
  182. False,
  183. False,
  184. ]
  185. rice_cultivations = [
  186. False,
  187. True,
  188. False,
  189. False,
  190. False,
  191. False,
  192. False,
  193. False,
  194. False,
  195. False,
  196. False,
  197. False,
  198. ]
  199. for crop, code, crop_burning, rice_cultivation in zip(
  200. crops, codes_crops, crop_burnings, rice_cultivations
  201. ):
  202. # all crops have at least N2O emissions
  203. gases_main = "N2O"
  204. if crop_burning or rice_cultivation:
  205. gases_main = ["CH4", "N2O"]
  206. # all crops have at least crop residues as child
  207. children_main = [f"{code}.a"]
  208. if crop_burning:
  209. children_main.append(f"{code}.b")
  210. if rice_cultivation:
  211. children_main.append(f"{code}.c")
  212. categories[f"{code}"] = {
  213. "title": f"{crop}",
  214. "comment": f"{crop}",
  215. # "alternative_codes": [f"{code}".replace(".", "")],
  216. "info": {"gases": gases_main},
  217. "children": [children_main],
  218. }
  219. # crop residues (every crop has it)
  220. categories[f"{code}.a.i"] = {
  221. "title": f"{crop} crop residues direct emissions",
  222. "comment": f"{crop} crop residues direct emissions",
  223. # "alternative_codes": [f"{code}.a".replace(".", "")],
  224. "info": {"gases": ["N2O"]},
  225. }
  226. categories[f"{code}.a.ii"] = {
  227. "title": f"{crop} crop residues indirect emissions",
  228. "comment": f"{crop} crop residues indirect emissions",
  229. # "alternative_codes": [f"{code}.a.i".replace(".", "")],
  230. "info": {"gases": ["N2O"]},
  231. }
  232. categories[f"{code}.a"] = {
  233. "title": f"{crop} crop residues",
  234. "comment": f"{crop} crop residues",
  235. # "alternative_codes": [f"{code}.a".replace(".", "")],
  236. "info": {"gases": ["N2O"]},
  237. "children": [[f"{code}.a.ii", f"{code}.a.i"]],
  238. }
  239. if crop_burning:
  240. categories[f"{code}.b"] = {
  241. "title": f"{crop} burning crop residues",
  242. "comment": f"{crop} burning crop residues",
  243. # "alternative_codes": [f"{code}.b".replace(".", "")],
  244. "info": {"gases": ["CH4", "N2O"]},
  245. }
  246. if rice_cultivation:
  247. categories[f"{code}.c"] = {
  248. "title": "Rice cultivation",
  249. "comment": "Rice cultivation",
  250. # "alternative_codes": [f"{code}.c".replace(".", "")],
  251. "info": {"gases": ["CH4"]},
  252. }
  253. # synthetic fertilisers
  254. codes_synthetic_fertilisers = ["1.B", "1.B.1", "1.B.2", "1.B.2.a", "1.B.2.b"]
  255. names = [
  256. "Synthetic fertilisers",
  257. "Direct emissions",
  258. "Indirect emissions",
  259. "Indirect emissions that volatilise",
  260. "Indirect emissions that leach",
  261. ]
  262. children_cats = [["1.B.1", "1.B.2"], None, ["1.B.2.a", "1.B.2.b"], None, None]
  263. for code, name, child_cat in zip(codes_synthetic_fertilisers, names, children_cats):
  264. categories[code] = {
  265. "title": name,
  266. "comment": name,
  267. # "alternative_codes": [code.replace(".", "")],
  268. "info": {"gases": ["N2O"]},
  269. }
  270. if child_cat:
  271. categories[code]["children"] = [child_cat]
  272. # 2. energy use
  273. names = [
  274. "Natural gas",
  275. "Electricity",
  276. "Coal",
  277. "Heat",
  278. "Petroleum",
  279. ]
  280. codes = children_2
  281. for name, code in zip(names, codes):
  282. categories[code] = {
  283. "title": name,
  284. "comment": name,
  285. # "alternative_codes": code.replace(".", ""),
  286. "info": {"gases": ["CH4", "N2O", "CO2"]},
  287. }
  288. # 3 livestock
  289. animals = [
  290. "Asses",
  291. "Camels",
  292. "Cattle, dairy",
  293. "Cattle, non-dairy",
  294. "Chickens, broilers",
  295. "Chickens, layers",
  296. "Goats",
  297. "Horses",
  298. "Mules and hinnies",
  299. "Sheep",
  300. "Llamas",
  301. "Chickens",
  302. "Poultry Birds",
  303. "Buffalo",
  304. "Ducks",
  305. "Swine, breeding",
  306. "Swine, market",
  307. "Turkeys",
  308. ]
  309. codes_animals = [f"3.{i}" for i in "ABCDEFGHIJKLMNOPQR"]
  310. enteric_fermentation = [
  311. "Asses",
  312. "Camels",
  313. "Cattle, dairy",
  314. "Cattle, non-dairy",
  315. "Goats",
  316. "Horses",
  317. "Sheep",
  318. "Mules and hinnies",
  319. "Buffalo",
  320. "Swine, breeding",
  321. "Swine, market",
  322. "Llamas",
  323. ]
  324. for animal, code in zip(animals, codes_animals):
  325. if animal in enteric_fermentation:
  326. gases = ["CH4"]
  327. animal_children = [f"{code}.{i}" for i in "1234"]
  328. categories[f"{code}.4"] = {
  329. "title": f"{animal} enteric fermentation",
  330. "comment": f"{animal} enteric fermentation",
  331. # "alternative_codes" : code.replace(".", ""),
  332. "info": {"gases": gases},
  333. }
  334. else:
  335. gases = ["N2O"]
  336. animal_children = [f"{code}.{i}" for i in "123"]
  337. categories[code] = {
  338. "title": animal,
  339. "comment": animal,
  340. # "alternative_codes" : code.replace(".", ""),
  341. "info": {"gases": gases},
  342. "children": [animal_children],
  343. }
  344. # manure management branch
  345. manure_management_children = [f"{code}.1.{i}" for i in "abc"]
  346. categories[f"{code}.1"] = {
  347. "title": f"{animal} manure management",
  348. "comment": f"{animal} manure management",
  349. # "alternative_codes" : code.replace(".", ""),
  350. "info": {"gases": gases},
  351. "children": [manure_management_children],
  352. }
  353. categories[f"{code}.1.a"] = {
  354. "title": f"{animal} decomposition of organic matter",
  355. "comment": f"{animal} decomposition of organic matter",
  356. # "alternative_codes" : code.replace(".", ""),
  357. "info": {"gases": "CH4"},
  358. }
  359. categories[f"{code}.1.b"] = {
  360. "title": f"{animal} manure management (Direct emissions N2O)",
  361. "comment": f"{animal} manure management (Direct emissions N2O)",
  362. # "alternative_codes" : code.replace(".", ""),
  363. "info": {"gases": "N2O"},
  364. }
  365. categories[f"{code}.1.c"] = {
  366. "title": f"{animal} manure management (Indirect emissions N2O)",
  367. "comment": f"{animal} manure management (Indirect emissions N2O)",
  368. # "alternative_codes" : code.replace(".", ""),
  369. "info": {"gases": "N2O"},
  370. }
  371. # manure left on pasture branch
  372. manure_left_on_pasture_children = [f"{code}.2.{i}" for i in "ab"]
  373. categories[f"{code}.2"] = {
  374. "title": f"{animal} manure left on pasture",
  375. "comment": f"{animal} manure left on pasture",
  376. # "alternative_codes" : code.replace(".", ""),
  377. "info": {"gases": "N2O"},
  378. "children": [manure_left_on_pasture_children],
  379. }
  380. categories[f"{code}.2.a"] = {
  381. "title": f"{animal} manure left on pasture (direct emissions N2O)",
  382. "comment": f"{animal} manure left on pasture (direct emissions N2O)",
  383. # "alternative_codes" : code.replace(".", ""),
  384. "info": {"gases": "N2O"},
  385. }
  386. categories[f"{code}.2.b"] = {
  387. "title": f"{animal} manure left on pasture (indirect emissions N2O)",
  388. "comment": f"{animal} manure left on pasture (indirect emissions N2O)",
  389. # "alternative_codes" : code.replace(".", ""),
  390. "info": {"gases": "N2O"},
  391. "children": [[f"{code}.2.b.i", f"{code}.2.b.ii"]],
  392. }
  393. categories[f"{code}.2.b.i"] = {
  394. "title": (
  395. f"{animal} manure left on pasture "
  396. f"(indirect emissions, N2O that leaches)"
  397. ),
  398. "comment": (
  399. f"{animal} manure left on pasture (indirect "
  400. f"emissions, N2O that leaches)"
  401. ),
  402. # "alternative_codes" : code.replace(".", ""),
  403. "info": {"gases": "N2O"},
  404. }
  405. categories[f"{code}.2.b.ii"] = {
  406. "title": (
  407. f"{animal} manure left on pasture "
  408. f"(indirect emissions, N2O that volatilises)"
  409. ),
  410. "comment": (
  411. f"{animal} manure left on pasture (indirect "
  412. f"emissions, N2O that volatilises)"
  413. ),
  414. # "alternative_codes" : code.replace(".", ""),
  415. "info": {"gases": "N2O"},
  416. }
  417. # manure applied branch
  418. manure_applied_children = [f"{code}.3.{i}" for i in "ab"]
  419. categories[f"{code}.3"] = {
  420. "title": f"{animal} manure applied",
  421. "comment": f"{animal} manure applied",
  422. # "alternative_codes" : code.replace(".", ""),
  423. "info": {"gases": "N2O"},
  424. "children": [manure_applied_children],
  425. }
  426. categories[f"{code}.3.a"] = {
  427. "title": f"{animal} manure applied (direct emissions N2O)",
  428. "comment": f"{animal} manure applied (direct emissions N2O)",
  429. # "alternative_codes" : code.replace(".", ""),
  430. "info": {"gases": "N2O"},
  431. }
  432. categories[f"{code}.3.b"] = {
  433. "title": f"{animal} manure applied (indirect emissions N2O)",
  434. "comment": f"{animal} manure applied (indirect emissions N2O)",
  435. # "alternative_codes" : code.replace(".", ""),
  436. "info": {"gases": "N2O"},
  437. "children": [[f"{code}.3.b.i", f"{code}.3.b.ii"]],
  438. }
  439. categories[f"{code}.3.b.i"] = {
  440. "title": (
  441. f"{animal} manure applied " f"(indirect emissions, N2O that leaches)"
  442. ),
  443. "comment": (
  444. f"{animal} manure applied (indirect " f"emissions, N2O that leaches)"
  445. ),
  446. # "alternative_codes" : code.replace(".", ""),
  447. "info": {"gases": "N2O"},
  448. }
  449. categories[f"{code}.3.b.ii"] = {
  450. "title": (
  451. f"{animal} manure applied "
  452. f"(indirect emissions, N2O that volatilises)"
  453. ),
  454. "comment": (
  455. f"{animal} manure applied (indirect "
  456. f"emissions, N2O that volatilises)"
  457. ),
  458. # "alternative_codes" : code.replace(".", ""),
  459. "info": {"gases": "N2O"},
  460. }
  461. # forests
  462. categories["4"] = {
  463. "title": "Carbon stock change in forests",
  464. "comment": "Carbon stock change in forests",
  465. "info": {"gases": "CO2"},
  466. "children": [["4.A", "4.B"]],
  467. }
  468. categories["4.A"] = {
  469. "title": "Forest land",
  470. "comment": "Forest land",
  471. "info": {"gases": "CO2"},
  472. }
  473. categories["4.B"] = {
  474. "title": "Net Forest conversion",
  475. "comment": "Net Forest conversion",
  476. "info": {"gases": "CO2"},
  477. }
  478. # drained organic soils
  479. categories["5"] = {
  480. "title": "Drained organic soils",
  481. "comment": "Drained organic soils",
  482. "info": {"gases": "CO2"},
  483. "children": [["5.A", "5.B"]],
  484. }
  485. categories["5.A"] = {
  486. "title": "Drained grassland",
  487. "comment": "Drained grassland",
  488. "info": {"gases": ["CO2", "N2O"]},
  489. }
  490. categories["5.B"] = {
  491. "title": "Drained cropland",
  492. "comment": "Drained cropland",
  493. "info": {"gases": ["CO2", "N2O"]},
  494. }
  495. # 6 Fires
  496. # Forest fires
  497. forest_fires_children = ["Humid tropical forests", "Other forests"]
  498. forest_fires_children_codes = ["6.A.1", "6.A.2"]
  499. for cat_name, code in zip(forest_fires_children, forest_fires_children_codes):
  500. categories[code] = {
  501. "title": cat_name,
  502. "comment": cat_name,
  503. "info": {"gases": ["CO2", "N2O", "CH4"]},
  504. }
  505. categories["6.A"] = {
  506. "title": "Forest fires",
  507. "comment": "Forest fires",
  508. "info": {"gases": ["CO2", "N2O", "CH4"]},
  509. "children": [forest_fires_children_codes],
  510. }
  511. # Savanna fires
  512. savanna_fires_children = [
  513. "Closed shrubland",
  514. "Grassland",
  515. "Open shrubland",
  516. "Savanna",
  517. "Woody savanna",
  518. ]
  519. savanna_fires_children_codes = ["6.B.1", "6.B.2", "6.B.3", "6.B.4", "6.B.5"]
  520. for cat_name, code in zip(savanna_fires_children, savanna_fires_children_codes):
  521. categories[code] = {
  522. "title": cat_name,
  523. "comment": cat_name,
  524. "info": {"gases": ["CO2", "N2O", "CH4"]},
  525. }
  526. categories["6.B"] = {
  527. "title": "Savanna fires",
  528. "comment": "Savanna fires",
  529. "info": {"gases": ["CO2", "N2O", "CH4"]},
  530. "children": [savanna_fires_children_codes],
  531. }
  532. # fires in organic soils
  533. categories["6.C"] = {
  534. "title": "Fires in organic soils",
  535. "comment": "Fires in organic soils",
  536. "info": {"gases": ["CO2", "N2O", "CH4"]},
  537. }
  538. # 6 fires
  539. categories["6"] = {
  540. "title": "Fires",
  541. "comment": "Fires",
  542. "info": {"gases": ["CO2", "N2O", "CH4"]},
  543. "children": [["6.A", "6.B", "6.C"]],
  544. }
  545. # 7 pre and post production
  546. pre_post_production_categories = [
  547. "Fertilizers Manufacturing",
  548. "Food Transport",
  549. "Food Retail",
  550. "Food Household Consumption",
  551. "Solid Food Waste",
  552. "Domestic Wastewater",
  553. "Industrial Wastewater",
  554. "Incineration",
  555. "Pre- and Post- Production",
  556. "Energy Use (Pre- and Post-Production)",
  557. "Agrifood Systems Waste Disposal",
  558. "Cold Chain F-Gas",
  559. "Pesticides Manufacturing",
  560. "Food Processing",
  561. "Food Packaging",
  562. ]
  563. pre_post_production_categories_codes = ["7." + i for i in "ABCDEFGHIJKLMNO"]
  564. pre_post_production_categories_gases = [
  565. ["CO2", "N2O", "KYOTOGHG (AR5GWP100)"],
  566. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)", "FGASES (AR5GWP100)"],
  567. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)", "FGASES (AR5GWP100)"],
  568. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)", "FGASES (AR5GWP100)"],
  569. ["KYOTOGHG (AR5GWP100)", "CH4"],
  570. ["KYOTOGHG (AR5GWP100)", "CH4", "N2O"],
  571. ["KYOTOGHG (AR5GWP100)", "CH4", "N2O"],
  572. ["CO2", "KYOTOGHG (AR5GWP100)"], # incineration
  573. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)", "FGASES (AR5GWP100)"],
  574. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)"],
  575. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)"],
  576. ["FGASES (AR5GWP100)"],
  577. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)"],
  578. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)", "FGASES (AR5GWP100)"],
  579. ["CO2", "CH4", "N2O", "KYOTOGHG (AR5GWP100)"],
  580. ]
  581. for cat_name, code, gases in zip(
  582. pre_post_production_categories,
  583. pre_post_production_categories_codes,
  584. pre_post_production_categories_gases,
  585. ):
  586. categories[code] = {
  587. "title": cat_name,
  588. "comment": cat_name,
  589. "info": {"gases": gases},
  590. }
  591. categories["7"] = {
  592. "title": "Pre and post agricultural production",
  593. "comment": "Pre and post agricultural production",
  594. "info": {
  595. "gases": [
  596. "CO2",
  597. "CH4",
  598. "N2O",
  599. "KYOTOGHG (AR5GWP100)",
  600. "FGASES (AR5GWP100)",
  601. ],
  602. },
  603. "children": [pre_post_production_categories_codes],
  604. }
  605. spec["categories"] = categories
  606. fao_cats = cc.HierarchicalCategorization.from_spec(spec.copy())
  607. # run print(fao_cats.show_as_tree())
  608. fao_cats.to_python("FAO.py")
  609. fao_cats.to_yaml("FAO.yaml")
  610. pass