dodo.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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) """
  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. 'verbosity': 2,
  128. 'setup': ['setup_venv'],
  129. }
  130. def task_country_info():
  131. """ Print information on submissions and datasets
  132. available for given country"""
  133. return {
  134. 'actions': [f"./venv/bin/python code/UNFCCC_reader/country_info.py "
  135. f"--country={read_config['country']}"],
  136. 'verbosity': 2,
  137. 'setup': ['setup_venv'],
  138. }