Skip to content

Commit

Permalink
Merge pull request #1358 from dcdenu4/bugfix/1260-pollination-duplica…
Browse files Browse the repository at this point in the history
…te-task

I. #1260 avoid adding duplicate kernel task.
  • Loading branch information
phargogh authored Aug 1, 2023
2 parents 2999bfc + 9d7f403 commit b9e15a9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/natcap/invest/pollination.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ def execute(args):
pollinator_abundance_task_map = {}
floral_resources_index_path_map = {}
floral_resources_index_task_map = {}
alpha_kernel_map = {}
for species in scenario_variables['species_list']:
# calculate foraging_effectiveness[species]
# FE(x, s) = sum_j [RA(l(x), j) * fa(s, j)]
Expand Down Expand Up @@ -762,11 +763,17 @@ def execute(args):
intermediate_output_dir, _KERNEL_FILE_PATTERN % (
alpha, file_suffix))

alpha_kernel_raster_task = task_graph.add_task(
task_name=f'decay_kernel_raster_{alpha}',
func=utils.exponential_decay_kernel_raster,
args=(alpha, kernel_path),
target_path_list=[kernel_path])
# to avoid creating duplicate kernel rasters check to see if an
# adequate kernel task has already been submitted
try:
alpha_kernel_raster_task = alpha_kernel_map[kernel_path]
except:
alpha_kernel_raster_task = task_graph.add_task(
task_name=f'decay_kernel_raster_{alpha}',
func=utils.exponential_decay_kernel_raster,
args=(alpha, kernel_path),
target_path_list=[kernel_path])
alpha_kernel_map[kernel_path] = alpha_kernel_raster_task

# convolve FE with alpha_s
floral_resources_index_path = os.path.join(
Expand Down

0 comments on commit b9e15a9

Please sign in to comment.