forked from payu-org/payu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request payu-org#376 from jo-basevi/375-date-based-restart…
…-MOM-mixin Fix date-based restart pruning breaking on empty restart dirs
- Loading branch information
Showing
7 changed files
with
85 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Mixin class for MOM and MOM6 drivers | ||
:copyright: Copyright 2011 Marshall Ward, see AUTHORS for details | ||
:license: Apache License, Version 2.0, see LICENSE for details | ||
""" | ||
|
||
import os | ||
|
||
import cftime | ||
|
||
|
||
class MomMixin: | ||
|
||
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)""" | ||
# Check for ocean_solo.res file | ||
ocean_solo_path = os.path.join(restart_path, 'ocean_solo.res') | ||
if not os.path.exists(ocean_solo_path): | ||
raise FileNotFoundError( | ||
'Cannot find ocean_solo.res file, which is required for ' | ||
'date-based restart pruning') | ||
|
||
with open(ocean_solo_path, 'r') as ocean_solo: | ||
lines = ocean_solo.readlines() | ||
|
||
calendar_int = int(lines[0].split()[0]) | ||
cftime_calendars = { | ||
1: "360_day", | ||
2: "julian", | ||
3: "proleptic_gregorian", | ||
4: "noleap" | ||
} | ||
calendar = cftime_calendars[calendar_int] | ||
|
||
last_date_line = lines[-1].split() | ||
date_values = [int(i) for i in last_date_line[:6]] | ||
year, month, day, hour, minute, second = date_values | ||
return cftime.datetime(year, month, day, hour, minute, second, | ||
calendar=calendar) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters