dodo.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. # define tasks for UNFCCC data repository
  2. from doit import get_var
  3. # TODO: task for folder mapping
  4. # create virtual environment
  5. def task_setup_venv():
  6. """Create virtual environment"""
  7. return {
  8. 'file_dep': ['requirements_dev.txt', 'setup.cfg', 'pyproject.toml'],
  9. 'actions': ['python3 -m venv venv',
  10. './venv/bin/pip install --upgrade pip wheel',
  11. #'./venv/bin/pip install -Ur UNFCCC_GHG_data/requirements.txt',
  12. './venv/bin/pip install --upgrade --upgrade-strategy '
  13. 'eager -e .[dev]',
  14. 'touch venv',],
  15. 'targets': ['venv'],
  16. 'verbosity': 2,
  17. }
  18. # Task to create the mapping files which map folder names to ISO 3-letter country codes
  19. read_config_folder = {
  20. "folder": get_var('folder', None),
  21. }
  22. def task_map_folders():
  23. """
  24. Create or update the folder mapping in the given folder
  25. """
  26. return {
  27. 'actions': [f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  28. f"--folder={read_config_folder['folder']}"],
  29. 'verbosity': 2,
  30. 'setup': ['setup_venv'],
  31. }
  32. # Tasks for getting submissions and downloading them
  33. def task_update_bur():
  34. """ Update list of BUR submissions """
  35. return {
  36. 'targets': ['downloaded_data/UNFCCC/submissions-bur.csv'],
  37. 'actions': ['datalad run -m "Fetch BUR submissions" '
  38. '-o downloaded_data/UNFCCC/submissions-bur.csv '
  39. './venv/bin/python UNFCCC_GHG_data/UNFCCC_downloader/fetch_submissions_bur.py'],
  40. 'verbosity': 2,
  41. 'setup': ['setup_venv'],
  42. }
  43. def task_download_bur():
  44. """ Download BUR submissions """
  45. return {
  46. #'file_dep': ['downloaded_data/UNFCCC/submissions-bur.csv'],
  47. # deactivate file_dep fow now as it will always run fetch submissions
  48. # before download
  49. 'actions': ['datalad run -m "Download BUR submissions" '
  50. '-i downloaded_data/UNFCCC/submissions-bur.csv '
  51. './venv/bin/python UNFCCC_GHG_data/UNFCCC_downloader/download_non-annexI.py --category=BUR',
  52. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  53. f"--folder=downloaded_data/UNFCCC"
  54. ],
  55. 'verbosity': 2,
  56. 'setup': ['setup_venv'],
  57. }
  58. def task_update_nc():
  59. """ Update list of NC submissions """
  60. return {
  61. 'targets': ['downloaded_data/UNFCCC/submissions-nc.csv'],
  62. 'actions': ['datalad run -m "Fetch NC submissions" '
  63. '-o downloaded_data/UNFCCC/submissions-nc.csv '
  64. './venv/bin/python UNFCCC_GHG_data/UNFCCC_downloader/fetch_submissions_nc.py'],
  65. 'verbosity': 2,
  66. 'setup': ['setup_venv'],
  67. }
  68. def task_download_nc():
  69. """ Download NC submissions """
  70. return {
  71. #'file_dep': ['downloaded_data/UNFCCC/submissions-nc.csv'],
  72. # deactivate file_dep fow now as it will always run fetch submissions
  73. # before download
  74. 'actions': ['datalad run -m "Download NC submissions" '
  75. '-i downloaded_data/UNFCCC/submissions-nc.csv '
  76. './venv/bin/python UNFCCC_GHG_data/UNFCCC_downloader/download_non-annexI.py --category=NC',
  77. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  78. f"--folder=downloaded_data/UNFCCC"
  79. ],
  80. 'verbosity': 2,
  81. 'setup': ['setup_venv'],
  82. }
  83. # annexI data: one update call for all data types (as they are on one page)
  84. # but for each year separately.
  85. # downloading is per year and
  86. update_aI_config = {
  87. "year": get_var('year', None),
  88. "category": get_var('category', None),
  89. }
  90. def task_update_annexi():
  91. """ Update list of AnnexI submissions """
  92. return {
  93. 'targets': [f"downloaded_data/UNFCCC/submissions-annexI_{update_aI_config['year']}.csv"],
  94. 'actions': [f"datalad run -m 'Fetch AnnexI submissions for {update_aI_config['year']}' "
  95. "--explicit "
  96. f"-o downloaded_data/UNFCCC/submissions-annexI_{update_aI_config['year']}.csv "
  97. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_downloader/fetch_submissions_annexI.py "
  98. f"--year={update_aI_config['year']}"],
  99. 'verbosity': 2,
  100. 'setup': ['setup_venv'],
  101. }
  102. def task_download_annexi():
  103. """ Download AnnexI submissions """
  104. return {
  105. #'file_dep': ['downloaded_data/UNFCCC/submissions-nc.csv'],
  106. # deactivate file_dep fow now as it will always run fetch submissions
  107. # before download
  108. 'actions': [f"datalad run -m 'Download AnnexI submissions for "
  109. f"{update_aI_config['category']}{update_aI_config['year']}' "
  110. f"-i downloaded_data/UNFCCC/submissions-annexI_{update_aI_config['year']}.csv "
  111. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_downloader/download_annexI.py "
  112. f"--category={update_aI_config['category']} --year={update_aI_config['year']}",
  113. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  114. f"--folder=downloaded_data/UNFCCC"
  115. ],
  116. 'verbosity': 2,
  117. 'setup': ['setup_venv'],
  118. }
  119. def task_download_ndc():
  120. """ Download NDC submissions """
  121. return {
  122. 'actions': ['datalad run -m "Download NDC submissions" '
  123. './venv/bin/python UNFCCC_GHG_data/UNFCCC_downloader/download_ndc.py',
  124. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  125. f"--folder=downloaded_data/UNFCCC"
  126. ],
  127. 'verbosity': 2,
  128. 'setup': ['setup_venv'],
  129. }
  130. # read UNFCCC submissions.
  131. # datalad run is called from within the read_UNFCCC_submission.py script
  132. read_config = {
  133. "country": get_var('country', None),
  134. "submission": get_var('submission', None),
  135. }
  136. # TODO: make individual task for non-UNFCCC submissions
  137. def task_read_unfccc_submission():
  138. """ Read submission for a country (if UNFCCC_GHG_data exists) (not for CRF)"""
  139. return {
  140. 'actions': [f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/read_UNFCCC_submission.py "
  141. f"--country={read_config['country']} --submission={read_config['submission']}",
  142. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  143. f"--folder=extracted_data/UNFCCC"
  144. ],
  145. 'verbosity': 2,
  146. 'setup': ['setup_venv'],
  147. }
  148. # read UNFCCC submissions.
  149. # datalad run is called from within the read_UNFCCC_submission.py script
  150. read_config_crf = {
  151. "country": get_var('country', None),
  152. "submission_year": get_var('submission_year', None),
  153. "submission_date": get_var('submission_date', None),
  154. "re_read": get_var('re_read', False),
  155. "countries": get_var('countries', None),
  156. }
  157. def task_read_unfccc_crf_submission():
  158. """ Read CRF submission for a country """
  159. actions = [
  160. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_CRF_reader/read_UNFCCC_CRF_submission_datalad.py "
  161. f"--country={read_config_crf['country']} "
  162. f"--submission_year={read_config_crf['submission_year']} "
  163. f"--submission_date={read_config_crf['submission_date']} ",
  164. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  165. f"--folder=extracted_data/UNFCCC"
  166. ]
  167. if read_config_crf["re_read"] == "True":
  168. actions[0] = actions[0] + " --re_read"
  169. return {
  170. 'actions': actions,
  171. 'verbosity': 2,
  172. 'setup': ['setup_venv'],
  173. }
  174. def task_read_new_unfccc_crf_for_year():
  175. """ Read CRF submission for all countries for given submission year. by default only reads
  176. data not present yet. Only reads the latest updated submission for each country."""
  177. actions = [f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_CRF_reader/read_new_UNFCCC_CRF_for_year_datalad.py "
  178. f"--submission_year={read_config_crf['submission_year']} ",
  179. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  180. f"--folder=extracted_data/UNFCCC"
  181. ]
  182. # specifying countries is currently disabled duo to problems with command line
  183. # list arguments
  184. #if read_config_crf["countries"] is not None:
  185. # actions[0] = actions[0] + f"--countries={read_config_crf['countries']} "
  186. if read_config_crf["re_read"] == "True":
  187. actions[0] = actions[0] + " --re_read"
  188. return {
  189. #'basename': "Read_CRF_year",
  190. 'actions': actions,
  191. 'verbosity': 2,
  192. 'setup': ['setup_venv'],
  193. }
  194. # tasks for DI reader
  195. # datalad run is called from within the read_UNFCCC_DI_for_country.py script
  196. read_config_di = {
  197. "country": get_var('country', None),
  198. "date": get_var('date', None),
  199. #"countries": get_var('countries', None),
  200. }
  201. def task_read_unfccc_di_for_country():
  202. """ Read DI data for a country """
  203. actions = [
  204. f"./venv/bin/python "
  205. f"UNFCCC_GHG_data/UNFCCC_DI_reader/read_UNFCCC_DI_for_country_datalad.py "
  206. f"--country={read_config_di['country']}",
  207. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  208. f"--folder=extracted_data/UNFCCC"
  209. ]
  210. return {
  211. 'actions': actions,
  212. 'verbosity': 2,
  213. 'setup': ['setup_venv'],
  214. }
  215. def task_process_unfccc_di_for_country():
  216. """ Process DI data for a country """
  217. actions = [
  218. f"./venv/bin/python "
  219. f"UNFCCC_GHG_data/UNFCCC_DI_reader/process_UNFCCC_DI_for_country_datalad.py "
  220. f"--country={read_config_di['country']} --date={read_config_di['date']}",
  221. f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/folder_mapping.py "
  222. f"--folder=extracted_data/UNFCCC"
  223. ]
  224. return {
  225. 'actions': actions,
  226. 'verbosity': 2,
  227. 'setup': ['setup_venv'],
  228. }
  229. # general tasks
  230. def task_country_info():
  231. """ Print information on submissions and datasets
  232. available for given country"""
  233. return {
  234. 'actions': [f"./venv/bin/python UNFCCC_GHG_data/UNFCCC_reader/country_info.py "
  235. f"--country={read_config['country']}"],
  236. 'verbosity': 2,
  237. 'setup': ['setup_venv'],
  238. }