Skip to content

Commit

Permalink
Bug correction: avoid launching far_predict several times
Browse files Browse the repository at this point in the history
We use a main (empty) task including subtasks for rho
interpolation. When this main task is finished, far_predict is run.
  • Loading branch information
ghislainv committed Jun 17, 2024
1 parent 3e38cfc commit f97d9dd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions deforisk_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ def set_workdir(self, iso, years, fcc_source, seed=None):
"""Set working directory."""
years = years.replace(" ", "").replace(",", "_")
random.seed(seed)
rand_num = random.randint(1, 9999)
folder_name = f"{iso}_{years}_{fcc_source}_{rand_num:04}"
rand_int = random.randint(1, 9999)
folder_name = f"{iso}_{years}_{fcc_source}_{rand_int:04}"
if platform.system() == "Windows":
workdir = os.path.join(os.environ["HOMEDRIVE"],
os.environ["HOMEPATH"],
Expand Down Expand Up @@ -710,6 +710,9 @@ def far_predict_after_rho_interp(self):
"""Interpolate rho."""
self.catch_arguments()
periods = self.get_interp_far_periods()
# Main empty task
description = self.task_description("FarInterpolateRho")
main_task = EmptyTask(description)
# Interpolate rho
for period in periods:
description = self.task_description(
Expand All @@ -720,10 +723,11 @@ def far_predict_after_rho_interp(self):
workdir=self.args["workdir"],
period=period,
csize_interpolate=self.args["csize_interp"])
# Execute far_predict after task_rho
task.taskCompleted.connect(self.far_predict)
# Add first task to task manager
self.tm.addTask(task)
main_task.addSubTask(task)
# Execute far_predict after rho interpolation
main_task.taskCompleted.connect(self.far_predict)
# Add main task to task manager
self.tm.addTask(main_task)

def mw_calibrate(self):
"""Compute distance threshold and local deforestation rate."""
Expand Down

0 comments on commit f97d9dd

Please sign in to comment.