dodo.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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.py'],
  50. 'verbosity': 2,
  51. 'setup': ['setup_venv'],
  52. }
  53. def task_update_nc():
  54. """ Update list of NC submissions """
  55. return {
  56. 'targets': ['downloaded_data/UNFCCC/submissions-nc.csv'],
  57. 'actions': ['datalad run -m "Fetch NC submissions" '
  58. '-o downloaded_data/UNFCCC/submissions-nc.csv '
  59. './venv/bin/python code/UNFCCC_downloader/fetch_submissions_nc.py'],
  60. 'verbosity': 2,
  61. 'setup': ['setup_venv'],
  62. }
  63. def task_download_nc():
  64. """ Download NC submissions """
  65. return {
  66. #'file_dep': ['downloaded_data/UNFCCC/submissions-nc.csv'],
  67. # deactivate file_dep fow now as it will always run fetch submissions
  68. # before download
  69. 'actions': ['datalad run -m "Download NC submissions" '
  70. '-i downloaded_data/UNFCCC/submissions-nc.csv '
  71. './venv/bin/python code/UNFCCC_downloader/download_non-annexI.py --category=NC'],
  72. 'verbosity': 2,
  73. 'setup': ['setup_venv'],
  74. }
  75. # annexI data: one update call for all data types (as they are on one page)
  76. # but for each year separately.
  77. # downloading is per year and
  78. update_aI_config = {
  79. "year": get_var('year', None),
  80. "category": get_var('category', None),
  81. }
  82. def task_update_annexi():
  83. """ Update list of AnnexI submissions """
  84. return {
  85. 'targets': [f"downloaded_data/UNFCCC/submissions-annexI_{update_aI_config['year']}.csv"],
  86. 'actions': [f"datalad run -m 'Fetch AnnexI submissions for {update_aI_config['year']}' "
  87. "--explicit "
  88. f"-o downloaded_data/UNFCCC/submissions-annexI_{update_aI_config['year']}.csv "
  89. f"./venv/bin/python code/UNFCCC_downloader/fetch_submissions_annexI.py "
  90. f"--year={update_aI_config['year']}"],
  91. 'verbosity': 2,
  92. 'setup': ['setup_venv'],
  93. }
  94. def task_download_annexi():
  95. """ Download AnnexI submissions """
  96. return {
  97. #'file_dep': ['downloaded_data/UNFCCC/submissions-nc.csv'],
  98. # deactivate file_dep fow now as it will always run fetch submissions
  99. # before download
  100. 'actions': [f"datalad run -m 'Download AnnexI submissions for "
  101. f"{update_aI_config['category']}{update_aI_config['year']}' "
  102. f"-i downloaded_data/UNFCCC/submissions-annexI_{update_aI_config['year']}.csv "
  103. f"./venv/bin/python code/UNFCCC_downloader/download_annexI.py "
  104. f"--category={update_aI_config['category']} --year={update_aI_config['year']}"],
  105. 'verbosity': 2,
  106. 'setup': ['setup_venv'],
  107. }
  108. def task_download_ndc():
  109. """ Download NDC submissions """
  110. return {
  111. 'actions': ['datalad run -m "Download NDC submissions" '
  112. './venv/bin/python code/UNFCCC_downloader/download_ndc.py'],
  113. 'verbosity': 2,
  114. 'setup': ['setup_venv'],
  115. }
  116. # read UNFCCC submissions.
  117. # datalad run is called from within the read_UNFCCC_submission.py script
  118. read_config = {
  119. "country": get_var('country', None),
  120. "submission": get_var('submission', None),
  121. }
  122. def task_read_unfccc_submission():
  123. """ Read submission for a country (if code exists) (not for CRF)"""
  124. return {
  125. 'actions': [f"./venv/bin/python code/UNFCCC_reader/read_UNFCCC_submission.py "
  126. f"--country={read_config['country']} --submission={read_config['submission']}",
  127. f"./venv/bin/python code/UNFCCC_reader/folder_mapping.py "
  128. f"--folder=extracted_data/UNFCCC"
  129. ],
  130. 'verbosity': 2,
  131. 'setup': ['setup_venv'],
  132. }
  133. # read UNFCCC submissions.
  134. # datalad run is called from within the read_UNFCCC_submission.py script
  135. read_config_crf = {
  136. "country": get_var('country', None),
  137. "submission_year": get_var('submission_year', None),
  138. "submission_date": get_var('submission_date', None),
  139. "re_read": get_var('re_read', False),
  140. "countries": get_var('countries', None),
  141. }
  142. def task_read_unfccc_crf_submission():
  143. """ Read CRF submission for a country (will re-read if data already present)"""
  144. return {
  145. 'actions': [f"./venv/bin/python code/UNFCCC_CRF_reader/read_UNFCCC_CRF_submission_datalad.py "
  146. f"--country={read_config_crf['country']} "
  147. f"--submission_year={read_config_crf['submission_year']} "
  148. f"--submission_date={read_config_crf['submission_date']} "],
  149. 'verbosity': 2,
  150. 'setup': ['setup_venv'],
  151. }
  152. def task_read_new_unfccc_crf_for_year():
  153. """ Read CRF submission for all countries for given submission year. by default only reads
  154. data not present yet. Only reads the latest updated submission for each country."""
  155. actions = [f"./venv/bin/python code/UNFCCC_CRF_reader/read_new_UNFCCC_CRF_for_year_datalad.py "
  156. f"--submission_year={read_config_crf['submission_year']} "]
  157. if read_config_crf["countries"] is not None:
  158. actions[0] = actions[0] + f"--countries={read_config_crf['countries']} "
  159. if read_config_crf["re_read"]:
  160. actions[0] = actions[0] + "--re_read"
  161. return {
  162. #'basename': "Read_CRF_year",
  163. 'actions': actions,
  164. 'verbosity': 2,
  165. 'setup': ['setup_venv'],
  166. }
  167. def task_country_info():
  168. """ Print information on submissions and datasets
  169. available for given country"""
  170. return {
  171. 'actions': [f"./venv/bin/python code/UNFCCC_reader/country_info.py "
  172. f"--country={read_config['country']}"],
  173. 'verbosity': 2,
  174. 'setup': ['setup_venv'],
  175. }