Skip to content

Commit

Permalink
Numerous improvements to the script
Browse files Browse the repository at this point in the history
  • Loading branch information
ggermain committed Jan 30, 2025
1 parent a8c756d commit d523bd1
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions acis_thermal_check/apps/copy_model_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from argparse import ArgumentParser
from pathlib import Path

model_choices = ["dpa", "dea", "psmc", "fp"]
model_choices = ["dpa", "dea", "psmc", "acisfp"]

base_path = Path("/proj/web-cxc/htdocs/acis")
load_path = Path("/data/acis/LoadReviews")
Expand All @@ -13,11 +13,6 @@
def main():
parser = ArgumentParser()
parser.set_defaults()
parser.add_argument(
"model",
type=str,
help="The model to copy",
)
parser.add_argument(
"location",
type=str,
Expand Down Expand Up @@ -48,22 +43,52 @@ def main():
if not load_dir.exists():
raise ValueError(f"Load directory {load_dir} does not exist")

if args.model not in model_choices:
raise ValueError(f"Model {args.model} is not a valid model!")

location = Path(args.location)
if not location.exists():
raise ValueError(f"Model location {location} does not exist!")
raise ValueError(f"Model location \"{location}\" does not exist!")

rst_file = location / "index.rst"
if not rst_file.exists():
raise ValueError(f"Model index file \"{rst_file}\" does not exist!")

with open(rst_file, "r") as f:
lines = f.readlines()

found_model_type = False
for line in lines:
words = line.strip().split()
if "Temperatures Check" in line and len(words) == 3:
model = words[0].lower()
found_model_type = True
break

if not found_model_type:
raise ValueError(f"Could not determine model from files in \"{location}\"!")

if model not in model_choices:
raise ValueError(f"Model \"{model}\" is not a valid model! Choices are {model_choices}")

print(f"Files to be copied are from a \"{model}\" model run.")

model_str = "FP" if model == "acisfp" else model.upper()

copy_path = (
base_path
/ f"{args.model.upper()}_thermPredic"
/ f"{model_str}_thermPredic"
/ load_week
/ f"ofls{load_letter}"
)
if not copy_path.exists() and not args.dry_run:
copy_path.mkdir(parents=True)
if args.dry_run:
print(f"Would copy {location} to {copy_path}.")
prefix = "Would copy"
else:
shutil.copytree(location, copy_path, dirs_exist_ok=args.overwrite)
prefix = "Copied contents of"
try:
shutil.copytree(location, copy_path, dirs_exist_ok=args.overwrite)
except FileExistsError:
raise IOError(f"Files already exist in {copy_path} and --overwrite is not specified!")
print(f"{prefix} {location} to {copy_path}.")

if __name__ == "__main__":
main()

0 comments on commit d523bd1

Please sign in to comment.