dodo.py 8.6 KB

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