-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_transform.sh
More file actions
executable file
·50 lines (40 loc) · 1.21 KB
/
Copy pathdata_transform.sh
File metadata and controls
executable file
·50 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Initialize variables
input_dir=""
output_dir=""
# Determine the directory of the script
script_dir=$(dirname "$0")
# Function to display usage
usage() {
echo "Usage: $0 -i <input_directory> -o <output_directory>"
exit 1
}
# Parse command-line options
while getopts 'i:o:' flag; do
case "${flag}" in
i) input_dir=${OPTARG} ;;
o) output_dir=${OPTARG} ;;
*) usage ;;
esac
done
# Check if input and output directories are provided
if [ -z "$input_dir" ] || [ -z "$output_dir" ]; then
echo "Error: Input and output directories must be specified."
usage
fi
# Exporting variables and functions to be available in parallel subshell
export input_dir
export output_dir
export script_dir
# Defining the command to be parallelized as a function
process_file() {
bil_file="$1"
if [[ -f "$bil_file" ]]; then
base_name=$(basename "$bil_file" .bil)
metadata_file="${bil_file}.hdr"
"$script_dir/data_transform.py" bil2npy "$bil_file" --metadata "$metadata_file" --output_dir "$output_dir"
fi
}
export -f process_file
# Find all .bil files and pass them to GNU Parallel, specifying 4 cores
find "$input_dir" -name "*.bil" | parallel -j 4 process_file