Skip to content

Commit

Permalink
Use swell_static_files_user in more tasks
Browse files Browse the repository at this point in the history
See issue #360.
  • Loading branch information
ashiklom committed Jul 3, 2024
1 parent 9fcbb81 commit 7dea266
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/swell/tasks/get_geos_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def execute(self):
self.logger.info('Obtaining GEOS restarts for the coupled simulation')

self.swell_static_files = self.config.swell_static_files()
self.swell_static_files_user = self.config.swell_static_files_user(None)

# Create forecast_dir and INPUT
# ----------------------------
Expand All @@ -41,28 +42,36 @@ def execute(self):

# ----------------------------------------------------------------------------------------------

def initial_restarts(self, rst_path):

# GEOS forecast checkpoint files are created in advance
# TODO: check tile of restarts here for compatibility?
# -------------------------------------------------------------------
self.logger.info('GEOS restarts are copied from a previous forecast')

src = os.path.join(self.swell_static_files, 'geos', 'restarts', rst_path, '*_rst')
def _cp_initial_restarts(self, rst_path, static_files):
src = os.path.join(static_files, 'geos', 'restarts', rst_path, '*_rst')

for filepath in list(glob.glob(src)):
filename = os.path.basename(filepath)
copy_to_dst_dir(self.logger, filepath, self.forecast_dir(filename))

src = os.path.join(self.swell_static_files, 'geos', 'restarts', rst_path, 'tile.bin')
src = os.path.join(static_files, 'geos', 'restarts', rst_path, 'tile.bin')
copy_to_dst_dir(self.logger, src, self.forecast_dir('tile.bin'))

# Consider the case of multiple MOM restarts
# -------------------------------------------
src = os.path.join(self.swell_static_files, 'geos', 'restarts', rst_path, 'MOM.res*nc')
src = os.path.join(static_files, 'geos', 'restarts', rst_path, 'MOM.res*nc')

for filepath in list(glob.glob(src)):
filename = os.path.basename(filepath)
copy_to_dst_dir(self.logger, filepath, self.forecast_dir(['INPUT', filename]))

def initial_restarts(self, rst_path):

# GEOS forecast checkpoint files are created in advance
# TODO: check tile of restarts here for compatibility?
# -------------------------------------------------------------------
self.logger.info('GEOS restarts are copied from a previous forecast')

self._cp_initial_restarts(rst_path, self.swell_static_files)

if self.swell_static_files_user is not None:
self.logger.info(f'Overwriting some files with files from: {self.swell_static_files_user}')
self._cp_initial_restarts(rst_path, self.swell_static_files_user)


# --------------------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions src/swell/tasks/prep_geos_run_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ def execute(self):
"""

self.swell_static_files = self.config.swell_static_files()
self.swell_static_files_user = self.config.swell_static_files_user(None)
# TODO: exp. directory location requires better handling
self.geos_exp_dir = os.path.join(self.swell_static_files, 'geos', 'run_dirs',
self.config.geos_experiment_directory())
self.geos_exp_dir_user = None
if self.swell_static_files_user is not None:
self.geos_exp_dir_user = os.path.join(self.swell_static_files_user, 'geos', 'run_dirs',
self.config.geos_experiment_directory())
self.geos_source = self.config.existing_geos_gcm_source_path()

self.logger.info('Preparing GEOS Forecast directory')
Expand Down Expand Up @@ -359,6 +364,11 @@ def get_static(self):
# ---------------------------------
src_dirs.append(self.geos_exp_dir)
src_dirs.append(os.path.join(self.geos_exp_dir, 'RC'))
# NOTE: Put these after because later copy operations overwrite earlier
# ones, meaning that user files get higher priority than main files.
if self.geos_exp_dir_user is not None:
src_dirs.append(self.geos_exp_dir_user)
src_dirs.append(os.path.join(self.geos_exp_dir_user, 'RC'))
src_dirs.append(os.path.join(geos_install_path, 'bundleParser.py'))

for src_dir in src_dirs:
Expand Down
2 changes: 2 additions & 0 deletions src/swell/tasks/task_questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,8 @@ swell_static_files_user:
prompt: What is the path to the user provided Swell Static Files directory?
tasks:
- GenerateBClimatologyByLinking
- GetGeosRestart
- PrepGeosRunDir
type: string

total_processors:
Expand Down

0 comments on commit 7dea266

Please sign in to comment.