1
1
"""Specific Access-OM3 Model setup and post-processing"""
2
2
3
- import re
4
3
from collections import defaultdict
5
4
from pathlib import Path
6
5
from typing import Any
7
6
7
+ from netCDF4 import Dataset
8
8
from payu .models .cesm_cmeps import Runconfig
9
9
10
10
from model_config_tests .models .model import (
11
11
DEFAULT_RUNTIME_SECONDS ,
12
12
SCHEMA_VERSION_1_0_0 ,
13
13
Model ,
14
14
)
15
- from model_config_tests .util import DAY_IN_SECONDS
16
15
17
16
18
17
class AccessOm3 (Model ):
19
18
def __init__ (self , experiment ):
20
19
super ().__init__ (experiment )
21
- self .output_file = self .experiment .output000 / "ocean.stats"
22
20
21
+ # ACCESS-OM3 uses restarts for repro testing
22
+ self .output_0 = self .experiment .restart000
23
+ self .output_1 = self .experiment .restart001
24
+
25
+ self .mom_restart_pointer = self .output_0 / "rpointer.ocn"
23
26
self .runconfig = experiment .control_path / "nuopc.runconfig"
24
- self .mom_override = experiment .control_path / "MOM_override"
25
- self .ocean_config = experiment .control_path / "input.nml"
26
27
27
28
def set_model_runtime (
28
29
self , years : int = 0 , months : int = 0 , seconds : int = DEFAULT_RUNTIME_SECONDS
@@ -35,15 +36,6 @@ def set_model_runtime(
35
36
freq = "nseconds"
36
37
n = str (seconds )
37
38
38
- # Ensure that ocean.stats are written at the end of the run
39
- if seconds < DAY_IN_SECONDS :
40
- with open (self .mom_override , "a" ) as f :
41
- f .writelines (
42
- [
43
- f"\n #override TIMEUNIT = { n } " ,
44
- "\n #override ENERGYSAVEDAYS = 1.0" ,
45
- ]
46
- )
47
39
elif seconds == 0 :
48
40
freq = "nmonths"
49
41
n = str (12 * years + months )
@@ -61,36 +53,32 @@ def set_model_runtime(
61
53
62
54
def output_exists (self ) -> bool :
63
55
"""Check for existing output file"""
64
- return self .output_file .exists ()
56
+ return self .mom_restart_pointer .exists ()
65
57
66
58
def extract_checksums (
67
59
self , output_directory : Path = None , schema_version : str = None
68
60
) -> dict [str , Any ]:
69
61
"""Parse output file and create checksum using defined schema"""
70
62
if output_directory :
71
- output_filename = output_directory / "ocean.stats "
63
+ mom_restart_pointer = output_directory / "rpointer.ocn "
72
64
else :
73
- output_filename = self .output_file
74
-
75
- # ocean.stats is used for regression testing in MOM6's own test suite
76
- # See https://github.com/mom-ocean/MOM6/blob/2ab885eddfc47fc0c8c0bae46bc61531104428d5/.testing/Makefile#L495-L501
77
- # Rows in ocean.stats look like:
78
- # 0, 693135.000, 0, En 3.0745627134675957E-23, CFL 0.00000, ...
79
- # where the first three columns are Step, Day, Truncs and the remaining
80
- # columns include a label for what they are (e.g. En = Energy/Mass)
81
- # Header info is only included for new runs so can't be relied on
65
+ mom_restart_pointer = self .mom_restart_pointer
66
+
67
+ # MOM6 saves checksums for each variable in its restart files. Extract these
68
+ # attributes for each restart
82
69
output_checksums : dict [str , list [any ]] = defaultdict (list )
83
70
84
- with open (output_filename ) as f :
85
- lines = f .readlines ()
86
- # Skip header if it exists (for new runs)
87
- istart = 2 if "Step" in lines [0 ] else 0
88
- for line in lines [istart :]:
89
- for col in line .split ("," ):
90
- # Only keep columns with labels (ie not Step, Day, Truncs)
91
- col = re .split (" +" , col .strip ().rstrip ("\n " ))
92
- if len (col ) > 1 :
93
- output_checksums [col [0 ]].append (col [- 1 ])
71
+ mom_restarts = []
72
+ with open (mom_restart_pointer ) as f :
73
+ for restart in f .readlines ():
74
+ mom_restarts .append (mom_restart_pointer .parent / restart .rstrip ())
75
+
76
+ for mom_restart in mom_restarts :
77
+ rootgrp = Dataset (mom_restart , "r" )
78
+ for v in rootgrp .variables :
79
+ var = rootgrp [v ]
80
+ if "checksum" in var .ncattrs ():
81
+ output_checksums [var .long_name .strip ()].append (var .checksum .strip ())
94
82
95
83
if schema_version is None :
96
84
schema_version = self .default_schema_version
0 commit comments