-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test that prescribing SST alters model evolution (#256)
This PR adds a test confirming that with the use of the namelist flag added in ai2cm/fv3gfs-fortran#173, setting the "ocean_surface_temperature" modifies the evolution of the model's prognostic variables (e.g. air temperature). In between ai2cm/fv3gfs-fortran#173 and ai2cm/fv3gfs-fortran#93, this functionality was broken (see the failing test associated with 5a6febb of this PR). In other words, since ai2cm/fv3gfs-fortran#93, Sfcprop%tsfco in the fortran model was modified within the physics driver prior to being used by any physics scheme; therefore when we set it via Python, it was immediately set to something else in the fortran before it could have any impact. The namelist parameter toggles the behavior back to what it was before ai2cm/fv3gfs-fortran#93, allowing us to prescribe the SST.
- Loading branch information
1 parent
1d04999
commit a66dae0
Showing
6 changed files
with
111 additions
and
25 deletions.
There are no files selected for viewing
Submodule external
updated
from 94b4ce to e3f2ab
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,74 @@ | ||
import unittest | ||
import os | ||
import numpy as np | ||
import fv3gfs.wrapper | ||
import fv3gfs.util | ||
from mpi4py import MPI | ||
from util import ( | ||
get_default_config, | ||
get_state_single_variable, | ||
main, | ||
replace_state_with_random_values, | ||
) | ||
|
||
|
||
test_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
def select_ocean_values(*fields): | ||
is_ocean = np.isclose(get_state_single_variable("land_sea_mask"), 0.0) | ||
return (field[is_ocean] for field in fields) | ||
|
||
|
||
class PrescribeSSTTests(unittest.TestCase): | ||
def __init__(self, *args, **kwargs): | ||
super(PrescribeSSTTests, self).__init__(*args, **kwargs) | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
MPI.COMM_WORLD.barrier() | ||
|
||
def test_prescribing_sst_changes_model_state(self): | ||
checkpoint_state = fv3gfs.wrapper.get_state(fv3gfs.wrapper.get_restart_names()) | ||
|
||
# If we do not set the sea surface temperature and | ||
# use_climatological_sst is set to .false., the sea surface temperature | ||
# will remain at what it was set to in the initial conditions for the | ||
# duration of the run. | ||
fv3gfs.wrapper.step() | ||
air_temperature_from_default_ocean_temperature = get_state_single_variable( | ||
"air_temperature" | ||
) | ||
|
||
fv3gfs.wrapper.set_state(checkpoint_state) | ||
replace_state_with_random_values(["ocean_surface_temperature"]) | ||
fv3gfs.wrapper.step() | ||
air_temperature_from_prescribed_ocean_temperature = get_state_single_variable( | ||
"air_temperature" | ||
) | ||
|
||
assert not np.allclose( | ||
air_temperature_from_default_ocean_temperature, | ||
air_temperature_from_prescribed_ocean_temperature, | ||
) | ||
|
||
def test_prescribing_sst_changes_surface_temperature_diagnostic(self): | ||
replaced_state = replace_state_with_random_values(["ocean_surface_temperature"]) | ||
prescribed_sst = replaced_state["ocean_surface_temperature"].view[:] | ||
fv3gfs.wrapper.step() | ||
surface_temperature_diagnostic = fv3gfs.wrapper.get_diagnostic_by_name( | ||
"tsfc", module_name="gfs_sfc" | ||
).view[:] | ||
|
||
result, expected = select_ocean_values( | ||
surface_temperature_diagnostic, prescribed_sst | ||
) | ||
np.testing.assert_allclose(result, expected) | ||
|
||
|
||
if __name__ == "__main__": | ||
config = get_default_config() | ||
config["namelist"]["gfs_physics_nml"]["use_climatological_sst"] = False | ||
main(test_dir, config) |
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