Skip to content

Commit 1f2616f

Browse files
authored
Merge pull request #203 from xylar/pass_graph_info_through_initial_state
Switch global ocean forward steps to use graph.info from initial state, not mesh
2 parents e8f02e7 + 810c225 commit 1f2616f

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

compass/ocean/tests/global_ocean/forward.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,32 @@ def __init__(self, test_case, mesh, init, time_integrator, name='forward',
8888
mesh_package = mesh.mesh_step.package
8989
mesh_package_contents = list(contents(mesh_package))
9090
mesh_namelists = ['namelist.forward',
91-
'namelist.{}'.format(time_integrator.lower())]
91+
f'namelist.{time_integrator.lower()}']
9292
for mesh_namelist in mesh_namelists:
9393
if mesh_namelist in mesh_package_contents:
9494
self.add_namelist_file(mesh_package, mesh_namelist)
9595

9696
mesh_streams = ['streams.forward',
97-
'streams.{}'.format(time_integrator.lower())]
97+
f'streams.{time_integrator.lower()}']
9898
for mesh_stream in mesh_streams:
9999
if mesh_stream in mesh_package_contents:
100100
self.add_streams_file(mesh_package, mesh_stream)
101101

102-
mesh_path = mesh.mesh_step.path
103-
104102
if mesh.with_ice_shelf_cavities:
105-
initial_state_target = '{}/ssh_adjustment/adjusted_init.nc'.format(
106-
init.path)
103+
initial_state_target = \
104+
f'{init.path}/ssh_adjustment/adjusted_init.nc'
107105
else:
108-
initial_state_target = '{}/initial_state/initial_state.nc'.format(
109-
init.path)
106+
initial_state_target = \
107+
f'{init.path}/initial_state/initial_state.nc'
110108
self.add_input_file(filename='init.nc',
111109
work_dir_target=initial_state_target)
112110
self.add_input_file(
113111
filename='forcing_data.nc',
114-
work_dir_target='{}/initial_state/init_mode_forcing_data.nc'
115-
''.format(init.path))
112+
work_dir_target=f'{init.path}/initial_state/'
113+
f'init_mode_forcing_data.nc')
116114
self.add_input_file(
117115
filename='graph.info',
118-
work_dir_target='{}/culled_graph.info'.format(mesh_path))
116+
work_dir_target=f'{init.path}/initial_state/graph.info')
119117

120118
self.add_model_as_input()
121119

@@ -223,7 +221,6 @@ def get_forward_subdir(init_subdir, time_integrator, name):
223221
elif time_integrator == 'RK4':
224222
subdir = os.path.join(init_subdir, time_integrator, name)
225223
else:
226-
raise ValueError('Unexpected time integrator {}'.format(
227-
time_integrator))
224+
raise ValueError(f'Unexpected time integrator {time_integrator}')
228225

229226
return subdir

compass/ocean/tests/global_ocean/init/initial_state.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def __init__(self, test_case, mesh, initial_condition, with_bgc):
3838
Whether to include biogeochemistry (BGC) in the initial condition
3939
"""
4040
if initial_condition not in ['PHC', 'EN4_1900']:
41-
raise ValueError('Unknown initial_condition {}'.format(
42-
initial_condition))
41+
raise ValueError(f'Unknown initial_condition {initial_condition}')
4342

4443
super().__init__(test_case=test_case, name='initial_state')
4544
self.mesh = mesh
@@ -51,7 +50,7 @@ def __init__(self, test_case, mesh, initial_condition, with_bgc):
5150
# generate the namelist, replacing a few default options
5251
self.add_namelist_file(package, 'namelist.init', mode='init')
5352
self.add_namelist_file(
54-
package, 'namelist.{}'.format(initial_condition.lower()),
53+
package, f'namelist.{initial_condition.lower()}',
5554
mode='init')
5655
if mesh.with_ice_shelf_cavities:
5756
self.add_namelist_file(package, 'namelist.wisc', mode='init')
@@ -115,25 +114,25 @@ def __init__(self, test_case, mesh, initial_condition, with_bgc):
115114

116115
self.add_input_file(
117116
filename='mesh.nc',
118-
work_dir_target='{}/culled_mesh.nc'.format(mesh_path))
117+
work_dir_target=f'{mesh_path}/culled_mesh.nc')
119118

120119
self.add_input_file(
121120
filename='critical_passages.nc',
122-
work_dir_target='{}/critical_passages_mask_final.nc'.format(
123-
mesh_path))
121+
work_dir_target=f'{mesh_path}/critical_passages_mask_final.nc')
124122

125123
self.add_input_file(
126124
filename='graph.info',
127-
work_dir_target='{}/culled_graph.info'.format(mesh_path))
125+
work_dir_target=f'{mesh_path}/culled_graph.info')
128126

129127
if mesh.with_ice_shelf_cavities:
130128
self.add_input_file(
131129
filename='land_ice_mask.nc',
132-
work_dir_target='{}/land_ice_mask.nc'.format(mesh_path))
130+
work_dir_target=f'{mesh_path}/land_ice_mask.nc')
133131

134132
self.add_model_as_input()
135133

136-
for file in ['initial_state.nc', 'init_mode_forcing_data.nc']:
134+
for file in ['initial_state.nc', 'init_mode_forcing_data.nc',
135+
'graph.info']:
137136
self.add_output_file(filename=file)
138137

139138
def setup(self):

0 commit comments

Comments
 (0)