Skip to content

Commit

Permalink
Fix #59: copy attenuation results accross dives
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelmassot committed Feb 14, 2022
1 parent 8a8ef44 commit cf8c832
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/correct_images/corrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@


# -----------------------------------------
def copy_file_if_exists(original_file: Path, dest_dir: Path):
"""Copy a file if it exists.
Parameters
----------
original_file : Path
Source file to copy from
dest_dir : Path
Destination directory to copy the file to
"""
if not original_file.exists():
return
fname = original_file.name
dest_file = dest_dir / fname
original_file.copy(dest_file)


class Corrector:
Expand Down Expand Up @@ -245,6 +260,21 @@ def parse(self, path_list, correct_config_list):
if self.correction_method == "colour_correction":
self.get_altitude_and_depth_maps()
self.generate_attenuation_correction_parameters()

for i in range(len(path_list)): # for each dive
path = get_processed_folder(path_list[i])
attn_dir = Path(self.attenuation_parameters_folder)
relative_folder = attn_dir.relative_to(self.path_processed)
dest_dir = path / relative_folder
if dest_dir == attn_dir:
# Do not copy over the original files
continue
copy_file_if_exists(self.attenuation_params_filepath, dest_dir)
copy_file_if_exists(self.correction_gains_filepath, dest_dir)
copy_file_if_exists(self.corrected_mean_filepath, dest_dir)
copy_file_if_exists(self.corrected_std_filepath, dest_dir)
copy_file_if_exists(self.raw_mean_filepath, dest_dir)
copy_file_if_exists(self.raw_std_filepath, dest_dir)
elif self.correction_method == "manual_balance":
Console.info("run process for manual_balance...")

Expand Down Expand Up @@ -671,7 +701,7 @@ def generate_attenuation_correction_parameters(self):
tmp_idxs = np.where(idxs == idx_bin)[0]
Console.info(
" Bin",
format(idx_bin, '02d'),
format(idx_bin, "02d"),
"(",
round(hist_bins[idx_bin], 1),
"m < x <",
Expand Down

0 comments on commit cf8c832

Please sign in to comment.