test_conversion.py 22 KB

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