-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from alan-turing-institute/use-rsync-to-filte…
…r-years Update `run-pipeline-iteratively.sh to create local dir structure with subset of data
- Loading branch information
Showing
6 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
# Run this script from the root of the `group_run_*` directory | ||
|
||
# /datadrive/clim-recal-results/group_run_2024-09-26-15-11 | ||
# Manaually add in 1981 data from | ||
# /datadrive/clim-recal-results/group_run_2024-09-30-16-04/run_24-09-30_16-07 | ||
|
||
# Manaually add in 1982 data from | ||
# /datadrive/clim-recal-results/group_run_2024-10-07-12-31/run_24-10-07_12-37 | ||
|
||
|
||
combined_dir=./combined_output | ||
|
||
# combined_dir=/mnt/vmfileshare/ClimateData/processed_2024_09_26/combined_output | ||
|
||
mkdir -p $combined_dir | ||
|
||
# Get all output directories | ||
output_dirs=`find . -type d -name "run_*"` | ||
|
||
for output_dir in $output_dirs; do | ||
|
||
# The trailling slash on the `$output_dir` is required! | ||
rsync \ | ||
--recursive \ | ||
--verbose \ | ||
--ignore-existing \ | ||
$output_dir/ \ | ||
$combined_dir | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pathlib | ||
import re | ||
import sys | ||
|
||
# get input dir | ||
root_dir = sys.argv[1] | ||
root_dir = pathlib.Path(root_dir).resolve() | ||
print(f"root_dir={root_dir}") | ||
|
||
do_delete = False | ||
|
||
try: | ||
print(f"secound_arg={sys.argv[2]}") | ||
if sys.argv[2] == "--I-am-really-sure-I-want-to-delete-lots-of-files": | ||
do_delete = True | ||
except IndexError: | ||
pass | ||
|
||
# There is certaining a better, more pythonic way to do this | ||
# But I had already created and tested this regex, to work with ripgrep, before | ||
# finding that it was too hard to install repgrep within the docker image | ||
re_str = r"(\/resample\/(cpm|hads)\/.+\.nc|\/crops\/hads\/(?P<h_region>(Scotland|Glasgow|Manchester|London))\/(?P<h_var>(tasmin|tasmax|rainfall))\/crop_(?P=h_region)_(?P=h_var)_hads_\d{8}-\d{8}\.nc|\/crops\/cpm\/(?P<c_region>(Scotland|Glasgow|Manchester|London))\/(?P<c_var>(tasmin|tasmax|pr))\/(?P<emsb>(01|05|06|07|08))\/crop_(?P=c_region)_(?P=c_var)_cpm_(?P=emsb)_\d{8}-\d{8}\.nc)" | ||
|
||
find_valid_files = re.compile(re_str) | ||
|
||
i_kept = 0 | ||
i_deleted = 0 | ||
|
||
for root, dirs, files in root_dir.walk(top_down=True): | ||
for name in files: | ||
full_name = (root / name).resolve() | ||
|
||
if not find_valid_files.search(str(full_name)): | ||
# print(f"delete={full_name}") | ||
i_deleted += 1 | ||
if do_delete: | ||
full_name.unlink() | ||
else: | ||
# print(f"keep={full_name}") | ||
i_kept += 1 | ||
|
||
print(f"found {i_deleted} files could be deleted and {i_kept} that should be kept") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters