Skip to content

Commit

Permalink
Clean-up to pass pre-commit checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlevy1981 committed Sep 7, 2024
1 parent ac076aa commit 2b36874
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions cesm_scripts/generate_cupid_config_file.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
#!/usr/bin/env python3
from __future__ import annotations

#import packages
import yaml
from standard_script_setup import *
import os

import yaml
from CIME.case import Case
from standard_script_setup import * # noqa: F401,F403

#Create variable for the caseroot environment variable
# Create variable for the caseroot environment variable
caseroot = os.getcwd()
#Open the config.yml file and create a dictionary with safe_load from the yaml package
with open('config_template.yml') as f:
# Open the config.yml file and create a dictionary with safe_load from the yaml package
with open("config_template.yml") as f:
my_dict = yaml.safe_load(f)

# get environment cesm case variables
with Case(caseroot, read_only=False, record=True) as case:
cime_case = case.get_value('CASE')
#create variable to access cesm_output_dir
outdir = case.get_value('DOUT_S_ROOT')
cime_case = case.get_value("CASE")
# create variable to access cesm_output_dir
outdir = case.get_value("DOUT_S_ROOT")

my_dict['global_params']['case_name'] = cime_case
my_dict['timeseries']['case_name'] = cime_case
my_dict["global_params"]["case_name"] = cime_case
my_dict["timeseries"]["case_name"] = cime_case

#create variable user to access the user environment variable
user = os.environ['USER']
#replace USER with the environment variable
#my_dict['data_sources']['nb_path_root'] = f'/glade/u/home/{user}/CUPiD/examples/nblibrary'
# create variable user to access the user environment variable
user = os.environ["USER"]
# replace USER with the environment variable
# my_dict['data_sources']['nb_path_root'] = f'/glade/u/home/{user}/CUPiD/examples/nblibrary'

#replace with environment variable
my_dict['global_params']['CESM_output_dir'] = outdir
# replace with environment variable
my_dict["global_params"]["CESM_output_dir"] = outdir

#create new file, make it writeable
with open('config.yml', "w") as f:
#write a comment
# create new file, make it writeable
with open("config.yml", "w") as f:
# write a comment
f.write("# sample comment\n")
#enter in each element of the dictionary into the new file
yaml.dump(my_dict, f)
# enter in each element of the dictionary into the new file
yaml.dump(my_dict, f)

0 comments on commit 2b36874

Please sign in to comment.