test_conversion.py 22 KB

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