Skip to content

Commit

Permalink
Create directories before running tasks in parallel
Browse files Browse the repository at this point in the history
To avoid conflicts when making directories in parallel.
  • Loading branch information
ghislainv committed Jun 17, 2024
1 parent f97d9dd commit 4fc0102
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
17 changes: 17 additions & 0 deletions deforisk_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,20 @@ def get_all_models(self):
all_models.append("mw_" + str(win_size))
return all_models

def create_far_directory(self, period):
"""Create MW directories."""
workdir = self.args["workdir"]
rmj.make_dir(opj(workdir, "outputs",
"far_models",
period))

def create_mw_directory(self, period):
"""Create MW directories."""
workdir = self.args["workdir"]
rmj.make_dir(opj(workdir, "outputs",
"rmj_moving_window",
period))

def create_validation_directories(self, period):
"""Create validation directories."""
workdir = self.args["workdir"]
Expand Down Expand Up @@ -691,6 +705,7 @@ def far_predict(self):
periods = self.get_pred_far_periods()
# Tasks with loops on dates and models
for period in periods:
self.create_far_directory(period)
date = self.get_date(period)
for model in models:
description = self.task_description(
Expand Down Expand Up @@ -736,6 +751,7 @@ def mw_calibrate(self):
periods = self.get_mod_mw_periods()
# Loop on window sizes
for period in periods:
self.create_mw_directory(period)
for win_size in win_sizes:
model = f"mv_{win_size}"
description = self.task_description(
Expand All @@ -757,6 +773,7 @@ def mw_predict(self):
win_sizes = self.get_win_sizes()
periods = self.get_pred_mw_periods()
for period in periods:
self.create_mw_directory(period)
date = self.get_date(period)
for wsize in win_sizes:
model = f"mv_{wsize}"
Expand Down
4 changes: 2 additions & 2 deletions deforisk_plugin_dialog_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</rect>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab_get_var">
<attribute name="title">
Expand Down Expand Up @@ -604,7 +604,7 @@
<string>Variable selection</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="tristate">
<bool>false</bool>
Expand Down
3 changes: 0 additions & 3 deletions far_functions/far_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ def run(self):
# Set working directory
os.chdir(self.workdir)

# Create directory
far.make_dir(self.outdir)

# Compute time interval from years
time_interval = self.get_time_interval()

Expand Down
3 changes: 0 additions & 3 deletions rmj_functions/mw_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ def run(self):
# Set working directory
os.chdir(self.workdir)

# Output directory
rmj.make_dir(self.outdir)

# Distance to forest edge threshold
fcc_file = opj(self.DATA, "fcc123.tif")
ofile = opj(self.outdir, "dist_edge_threshold.csv")
Expand Down
3 changes: 0 additions & 3 deletions rmj_functions/mw_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def run(self):
# Set working directory
os.chdir(self.workdir)

# Create directory
rmj.make_dir(self.outdir)

# Compute time interval from years
time_interval = self.get_time_interval()

Expand Down

0 comments on commit 4fc0102

Please sign in to comment.