test_conversion.py 24 KB

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