test_conversion.py 21 KB

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