diff --git a/payu/models/access.py b/payu/models/access.py index 8651d1e0..a542f5cf 100644 --- a/payu/models/access.py +++ b/payu/models/access.py @@ -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 @@ -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 diff --git a/payu/models/accessom2.py b/payu/models/accessom2.py index cfa8e930..b84d7185 100644 --- a/payu/models/accessom2.py +++ b/payu/models/accessom2.py @@ -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): @@ -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 + ) \ No newline at end of file diff --git a/payu/models/mom.py b/payu/models/mom.py index 6084407b..ace19183 100644 --- a/payu/models/mom.py +++ b/payu/models/mom.py @@ -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' + ) \ No newline at end of file