test_conversion.py 21 KB

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