test_conversion.py 21 KB

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