Skip to content

Commit 242949c

Browse files
authored
Merge pull request #194 from ISISComputingGroup/Walk_all_files_in_sensor_folder_AND_specify_num_of_header_lines
Changed to convert all files in a list of sensors and allow specifying of number of header lines for temperature files
2 parents 176ec37 + 3003f39 commit 242949c

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

workflow_support_scripts/convert_temp_calib_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
dir_path = os.path.dirname(os.path.realpath(__file__))
1313

1414

15-
def convert(original_file_name, output_folder, root):
15+
def convert(original_file_name, output_folder, root, num_of_header_lines=1):
1616
"""
1717
Converts .dat calibration files to .txt files and writes them to the output file
1818
:param original_file_name (str): The name of the file to be converted
@@ -24,6 +24,6 @@ def convert(original_file_name, output_folder, root):
2424
with open(os.path.join(root, original_file_name), mode='r', encoding='utf-8') as original_file, \
2525
open(os.path.join(output_folder, output_file_name), mode='w+', encoding='utf-8') as output_file:
2626
# Strip first 3 lines from file
27-
utility.strip_header(3, original_file)
27+
utility.strip_header(num_of_header_lines, original_file)
2828
# Go through rest of lines and add correct format to output file
2929
utility.format_output_file(original_file, output_file, 0, 1)

workflow_support_scripts/file_converter.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
dir_path = os.path.dirname(os.path.realpath(__file__))
1111

1212

13-
def get_input_output_folders() -> Tuple[str, str]:
13+
def get_arguments() -> Tuple[str, str, int]:
1414
"""
1515
Get the input and output folders from the command line
1616
:return: input_folder, output_folder
1717
"""
1818
parser = argparse.ArgumentParser(description='Get the input and output folder')
1919
parser.add_argument('-i', "--input", dest="input_folder", type=str, help='The input folder', required=True)
2020
parser.add_argument('-o', "--output", dest="output_folder", type=str, help='The output folder', required=True)
21+
parser.add_argument('-thl', "--temp_header_lines", dest="num_of_temp_header_lines", type=int, help='The number of header lines to strip from temp files', required=False, default=1)
2122
args = parser.parse_args()
22-
return os.path.join(dir_path, args.input_folder), os.path.join(dir_path, args.output_folder)
23+
return os.path.join(dir_path, args.input_folder), os.path.join(dir_path, args.output_folder), args.num_of_temp_header_lines
2324

2425

2526
class FileConverter:
@@ -109,7 +110,7 @@ def convert_file(root, original_file_name) -> None:
109110
convert_curve_files.convert(original_file_name, output_folder, root)
110111
# If the file is in .dat format
111112
if original_file_name.endswith(FileTypes.ORIGINAL_DAT_FILE_EXTENSION):
112-
convert_temp_calib_files.convert(original_file_name, output_folder, root)
113+
convert_temp_calib_files.convert(original_file_name, output_folder, root, num_of_temp_header_lines)
113114

114115
def convert_all_files(self) -> None:
115116
"""
@@ -119,15 +120,11 @@ def convert_all_files(self) -> None:
119120
for root, _, files in os.walk(self.input_dir):
120121
for original_file_name in files:
121122
self.convert_file(root, original_file_name)
122-
# We've found the file to convert so don't need to look at any other in the directory
123-
break
124-
else:
125-
print(f"Could not find file to convert in {root}")
126123

127124

128125
if __name__ == "__main__":
129126
# Get the input and output folders from the command line
130-
input_folder, output_folder = get_input_output_folders()
127+
input_folder, output_folder, num_of_temp_header_lines = get_arguments()
131128
# Create Instance of FileConverter
132129
file_converter = FileConverter(input_folder, output_folder)
133130
# Check input folder exists

0 commit comments

Comments
 (0)