Skip to content

Commit

Permalink
Merge pull request #465 from ACCESS-NRI/464-esm-date-based-restart-pr…
Browse files Browse the repository at this point in the history
…uning

Adding date based pruning for ESM
  • Loading branch information
blimlim authored Jul 28, 2024
2 parents eab6a8a + b56de4b commit a763ea1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
9 changes: 9 additions & 0 deletions payu/models/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Local
from payu.fsops import make_symlink
from payu.models.model import Model
from payu.models.mom import get_restart_datetime_using_mom_submodel
import payu.calendar as cal


Expand Down Expand Up @@ -226,6 +227,14 @@ def archive(self):
o2i_dst = os.path.join(cice5.restart_path, 'o2i.nc')
shutil.copy2(o2i_src, o2i_dst)

def get_restart_datetime(self, restart_path):
"""Given a restart path, parse the restart files and
return a cftime datetime (for date-based restart pruning)"""
return get_restart_datetime_using_mom_submodel(
model=self,
restart_path=restart_path
)

def set_model_pathnames(self):
pass

Expand Down
14 changes: 6 additions & 8 deletions payu/models/accessom2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import shutil

from payu.models.model import Model
from payu.models.mom import get_restart_datetime_using_mom_submodel


class AccessOm2(Model):
Expand Down Expand Up @@ -90,11 +91,8 @@ def collate(self):
def get_restart_datetime(self, restart_path):
"""Given a restart path, parse the restart files and
return a cftime datetime (for date-based restart pruning)"""
for model in self.expt.models:
if model.model_type == 'mom':
mom_restart_path = os.path.join(restart_path, model.name)
return model.get_restart_datetime(mom_restart_path)

raise NotImplementedError(
'Cannot find mom sub-model: access-om2 date-based restart pruning '
'requires the mom sub-model to determine restart dates')
# Use mom submodel to determine restart datetimes
return get_restart_datetime_using_mom_submodel(
model=self,
restart_path=restart_path
)
16 changes: 16 additions & 0 deletions payu/models/mom.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,19 @@ def create_mask_table(self, input_nml):
land_cells = int(fmask.readline())

return land_cells


def get_restart_datetime_using_mom_submodel(model, restart_path):
"""Given a model object and a restart path, check for
a MOM sub-model and use it's restart files to find a cftime datetime
(for date-based restart pruning)"""
for sub_model in model.expt.models:
if sub_model.model_type == 'mom' :
mom_restart_path = os.path.join(restart_path, sub_model.name)
return sub_model.get_restart_datetime(mom_restart_path)

raise NotImplementedError(
f'Cannot find mom sub-model: {model.model_type} date-based '
'restart pruning requires the mom sub-model to '
'determine restart dates'
)

0 comments on commit a763ea1

Please sign in to comment.