Skip to content

Commit

Permalink
Merge pull request #298 from Samweli/output_file_paths_fix
Browse files Browse the repository at this point in the history
Update processing output files paths creation
  • Loading branch information
Samweli authored Nov 28, 2023
2 parents 688b9e6 + aab1be4 commit 8d9e5b9
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/cplus_plugin/gui/qgis_cplus_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,9 @@ def run_highest_position_analysis(self):
f" [{dest_crs.authid()}]"
)

output_file = (
f"{self.scenario_directory}/"
f"{SCENARIO_OUTPUT_FILE_NAME}_{str(scenario.uuid)[:4]}.tif"
output_file = os.path.join(
self.scenario_directory,
f"{SCENARIO_OUTPUT_FILE_NAME}_{str(scenario.uuid)[:4]}.tif",
)

# Preparing the input rasters for the highest position
Expand Down Expand Up @@ -1101,8 +1101,8 @@ def run_pathways_analysis(self, models, priority_layers_groups, extent):

file_name = clean_filename(pathway.name.replace(" ", "_"))

output_file = (
f"{new_carbon_directory}/{file_name}_{str(uuid.uuid4())[:4]}.tif"
output_file = os.path.join(
new_carbon_directory, f"{file_name}_{str(uuid.uuid4())[:4]}.tif"
)

if suitability_index > 0:
Expand Down Expand Up @@ -1509,7 +1509,9 @@ def run_pathways_normalization(self, models, priority_layers_groups, extent):
FileUtils.create_new_dir(new_ims_directory)
file_name = clean_filename(pathway.name.replace(" ", "_"))

output_file = f"{new_ims_directory}/{file_name}_{str(uuid.uuid4())[:4]}.tif"
output_file = os.path.join(
new_ims_directory, f"{file_name}_{str(uuid.uuid4())[:4]}.tif"
)

pathway_layer = QgsRasterLayer(pathway.path, pathway.name)
provider = pathway_layer.dataProvider()
Expand Down Expand Up @@ -1673,7 +1675,9 @@ def run_models_analysis(self, models, priority_layers_groups, extent):
main_task.cancel()
return False

output_file = f"{new_ims_directory}/{file_name}_{str(uuid.uuid4())[:4]}.tif"
output_file = os.path.join(
new_ims_directory, f"{file_name}_{str(uuid.uuid4())[:4]}.tif"
)

# Due to the implementation models base class
# model only one of the following blocks will be executed,
Expand Down Expand Up @@ -1833,13 +1837,14 @@ def run_normalization_analysis(self, models, priority_layers_groups, extent):
main_task.cancel()
return False

basenames = []
layers = []
new_ims_directory = f"{self.scenario_directory}/normalized_ims"
FileUtils.create_new_dir(new_ims_directory)
normalized_ims_directory = f"{self.scenario_directory}/normalized_ims"
FileUtils.create_new_dir(normalized_ims_directory)
file_name = clean_filename(model.name.replace(" ", "_"))

output_file = f"{new_ims_directory}/{file_name}_{str(uuid.uuid4())[:4]}.tif"
output_file = os.path.join(
normalized_ims_directory, f"{file_name}_{str(uuid.uuid4())[:4]}.tif"
)

model_layer = QgsRasterLayer(model.path, model.name)
provider = model_layer.dataProvider()
Expand Down Expand Up @@ -2066,12 +2071,16 @@ def run_priority_analysis(self, models, priority_layers_groups, extent):
if basenames is []:
return

new_ims_directory = f"{self.scenario_directory}/weighted_ims"
weighted_ims_directory = f"{self.scenario_directory}/weighted_ims"

FileUtils.create_new_dir(new_ims_directory)
FileUtils.create_new_dir(weighted_ims_directory)

file_name = clean_filename(model.name.replace(" ", "_"))
output_file = f"{new_ims_directory}/{file_name}_{str(uuid.uuid4())[:4]}.tif"

output_file = os.path.join(
weighted_ims_directory, f"{file_name}_{str(uuid.uuid4())[:4]}.tif"
)

expression = " + ".join(basenames)

# Actual processing calculation
Expand Down

0 comments on commit 8d9e5b9

Please sign in to comment.