Practical Atmosphere
Practical Atmosphere
Exercises
CESM Tutorial 2022
cd /glade/p/cesm/tutorial/cesm2.1_tutorial2022/cime/scripts
Create a case with your choice of casename (cesm naming convention would be f.e21.F2000.f19_f19.cntl )
Note: the COMPSET F2000climo is scientifically validated ONLY on the 1deg grid (f09).
We are running 2deg (f19) for expedience.
Control
(Control Case:
Case continued
Setup) continued
• Setup and Build Hint: calling ./preview_namelists from RUNDIR before build command
generates the user_nl_* files and allows you to do mods while your build is queued/running
• Add a history file (h1) to be written every 3 hours, with approximately one file per
model month (30 days), containing instantaneous fields 2D (lat/lon) fields. Use these or
choose your own:
TS,PS,Z500,U850,U200,T850,T500,T200,CLDLOW,PRECT,LHFLX,SHFLX,FLNT,FLNS
Recall atm namelist variables: fincl1, nhtfrq, mfilt
• While you’re waiting, decide which of the next exercise you want to do
Unless you’re changing the compset (Exercise 1), you can do the the workflow up through
the build just like this page with new casenames for each exercise. These slide titles are in
gray boxes so you can search quickly through the document for them.
• Check completion of build
cat CaseStatus (should show ‘case.build success’)
ls /glade/scratch/$USER/$CASENAME/bld/cesm.exe (should exist)
• Submit
You might need: xmlchange JOB_QUEUE= whatever_you_need_to_use
For answer to adding the history file variables, see CNTL Cheatsheet
Comparing Control to Experiments
Once you have completed an exercise, come back to this page for a guide to a quick
comparison. Again, the titles in gray boxes are to return to for each case.
h a t d if fe r ences do
Think: W a n y o u se e • Use scripts from Wednesday’s
e c t? C
you exp
nin g f u l d if ferences diagnostics lab to compare fields
me a st e xpect • Run the AMWG mean diagnostics for a
do y o u ju
already? Or s o m e thing* is more comprehensive comparison
h a t *
to check t it sh o uld be? (needs at least 14 months of data so
ca u s e
different be can't do today)
• A quick comparison of two (finished) cases: create & view an ncfile containing the diffs
You might need to load modules: module load ncview; module load netcdf
cd /glade/scratch/$USER/archive
If you want to make it easier, use your case names in the following settings so you can copy and use the ncdiff lines)
set CNTL = f2000; set CASE1 = fhist These lines can be
mouse-copied but
ncdiff $CASE1/atm/hist/$CASE1.*.nc \ Note: Confirm fields in your h1 files
unfortunately must be
$CNTL/atm/hist/$CNTL.*.nc \ done one line at a time are instantaneous: use ncdump to
$CASE1/atm/hist/diff_${CASE1}_${CNTL}.nc compare to h0 files from cases done
Use ncview to browse variables in this file that contains only the diffs. on the previous days. Look at meta
ncview $CASE1/atm/hist/diff_${CASE1}_${CNTL}.nc data variable descriptions of
averaged: (cell_methods = "time: mean ")
Optional: Shortcuts & Scripts
1) Changing directories quickly: Setting environment variables and aliases can make your work easier.
Command line envvars in: csh or tcsh shells bash shell
set CASENAME = f2000 export VAR='my value'
set CASEDIR = ~/cases/$CASENAME export VAR=$MY_OTHER_VAR
I set the following in my .tcshrc file, to invoke cdr from the casedir in order to go to the rundir
set scr = /glade/scratch/$USER ; alias cdr 'cd $scr/$CASENAME/run'
set case = ~/cases/$CASENAME; ; alias cdc 'cd $case'
2) Working during the build: Calling ./preview_namelist from RUNDIR before build command generates the
user_nl_* files and allows you to do mods while your build is queued/running
Or back at home, if you’re building interactively, redirect output from the case.build into a file, and run the job in the
background in order to keep working while the cntl builds,
csh: qcmd -A $PROJ -- ./case.build >& ! out.build &
To find job number: jobs To bring jobs to fore/background fg %N or bg %N
bash: qcmd -A $PROJ -- ./case.build 1> out.build 2>&1
3) Put the workflow commands in a shell script instead of using the command line
• Advantages of a script
• An exact record of the commands used to make each case
• Easy reproducibility and ability to make small changes for another case
• Disadvantages of a script
• Necessary to understand a scripting language (example is in c-shell)
• When the construction of a case requires editing or adding a file, you might have the script stop before the
edit and resume afterward. (Note that mine is built to make this as easy as possible).
• If you want to use a script: copy mine for the control case /glade/u/home/bundy/cases/f2000.csh
to your casename in your directory, open it in an editor, read and understand it and make the necessary
modifications to use it for your cases
• Since this is a more advanced method, there are no more instructions for doing it this way.
CNTL Cheatsheet
1) create, setup,
set CASENAME = f2000
set CASEDIR = /glade/u/home/$USER/cases/$CASENAME
set RUNDIR = /glade/scratch/$USER/$CASENAME/run
cd /glade/p/cesm/tutorial/cesm2.1_tutorial2022/cime/scripts/
./create_newcase --case $CASEDIR --res f19_f19_mg17 --compset F2000climo --run-unsupported
cd $CASEDIR
./case.setup
./preview_namelists [Optional] Generates the user_nl_* files to edit while waiting for build
2) start build in the background
qcmd -A $PROJ -- ./case.build You might not need the -A $PROJ option right now
3) Meanwhile make namelist modifications, in a new shell or by redirecting output & suspending above with ">&! out.build &"
note in csh, >> appends to an existing file in case there are already settings there
set nl_file = user_nl_cam
echo "NHTFRQ(2) = -3">> $nl_file
echo "MFILT(2) = 240">> $nl_file
echo "FINCL2 = 'TS:I','PS:I', 'U850:I','T850:I','PRECT:I','LHFLX:I','SHFLX:I','FLNT:I','FLNS:I'">> $nl_file
echo "">> $nl_file
./preview_namelists
Calling preview_namelists checks your addition before putting the build into the queue.
If it stalls, something is wrong with your namelist! Try deleting extra spaces at ends of lines, extra lines
4) Wait on build to finish Commands below check what's going on
qstat -u [your user name]
jobs
cat CaseStatus
5) Run
./case.submit
qstat
Monitor output while running: tail -f /glade/scratch/$USER/$CASENAME/run/atm.log*
Exercise 1: Historical
boundary conditions and forcings
CAM is capable of running over historical periods with time-varying sea
surface temperatures (SSTs) as well as anthropogenic and natural forcings.
Kennedy J.J., Rayner, N.A., Smith, R.O., Saunby, M. and Parker, D.E. (2011b). Reassessing biases and
other uncertainties in sea-surface temperature observations since 1850 part 1: measurement and sampling
errors. J. Geophys. Res., 116, D14103, doi:10.1029/2010JD015218
More information about the AMIP protocol and HadSST data sets:
• https://climatedataguide.ucar.edu/climate-data/sst-data-hadisst-v11
• https://pcmdi.llnl.gov/mips/amip/
• Taylor, K.E., D. Williamson and F. Zwiers, 2000: "The sea surface temperature and sea ice concentration
boundary conditions for AMIP II simulations" PCMDI Report 60, Program for Climate Model Diagnosis and
Intercomparison, Lawrence Livermore National Laboratory,
(Exercise 1): Finding a COMPSET
If you want to run a different configuration from what you’ve learned here, it is
important to learn how to find and/or modify a compset.
Task: Using the tools above and/or web searches below, find a CESM compset with an
active atmosphere version cam6.0, that uses historical forcing data including sea
surface temperatures. If you find several candidates, look at the components option
and/or webpage to decide. Is it scientifically validated? For what resolutions?
More explanation (and some more options) can be found in the docs
https://www.cesm.ucar.edu/models/cesm2/config/compsets.html
https://ncar.github.io/CAM/doc/build/html/users_guide/atmospheric-configurations.html
(Exercise 1): Setting up Historical
Once you have found your compset, create, configure, build and run, with a casename of your
choice (eg. fhist), using the same history file output as in the control (see slides with gray-box
titles for reference)
• How can you check that there is a difference between the set up of this and your control?
• How can you check that it is running the way you intended: using ssts & ghg forcings from
time-varying, historical files?
• What year is the model running?
Mouse-copy all of the FOUR lines of this command into ONE line in your shell
Check your changes by viewing a netcdf file containing the diffs (new – old)
hint: ncdiff old.nc new.nc diff.nc, ncview diff.nc (make sure to check all values!)
(Exercise 2a) Cheatsheet
1) Follow control case set up through the build and namelist modifications but with a new casename.
set CASENAME = f2000.oro; run create_newcase, case.setup, preview_namelists
2) Find name & path of boundary dataset. Look in xml file first
grep -i sst env*.xml | grep -i file
Returns a lot hence the | (pipe) into grep. Decide to change the one that is a filename
env_run.xml: <entry id="SSTICE_DATA_FILENAME" value="$DIN_LOC_ROOT/atm/cam/sst/sst_HadOIBl_bc_1.9x2.5_2000climo_c180511.nc">
3) Make a local copy of the sst file in your CASE directory
How to know find DIN_LOC_ROOT? Probably set in an xml file somewhere but we can find the whole path by searching the resolved
grep sst_Had CaseDocs/*_in
Returns: CaseDocs/ice_in: stream_fldfilename = "/glade/p/cesmdata/cseg/inputdata/atm/cam/sst/sst_HadOIBl_bc_1.9x2.5_2000climo_c180511.nc"
set file_orig = sst_HadOIBl_bc_1.9x2.5_2000climo_c180511.nc
cp /glade/p/cesmdata/cseg/inputdata/atm/cam/sst/$file_orig .
4-5) Modify file with NCOs and check using NCVIEW (see previous slide)
set file_new = $file_orig:t:r.warmtcp.nc
ncap2 -O -s 'lat2d[lat,lon]=lat ; lon2d[lat,lon]=lon' \
-s 'omask=(lat2d >= -10. && lat2d <= 10.) && (lon2d >= 180. && lon2d <= 240.)'\
-s 'SST_cpl=(SST_cpl+omask*2.)' $file_orig $file_new
ncdiff -v SST_cpl $file_orig $file_new SST_cpl_diff.nc
ncview SST_cpl_diff.nc
6) Get the namelist change into the actual namelists and check the resolved namelists
./xmlchange SSTICE_DATA_FILENAME="$CASEDIR/$file_new"
./preview_namelists
grep sst $RUNDIR/*_in Note: these don't show up in *usr_nl*, but are in the final input
7) Build. Check that the correct files is being used
cat CaseStatus | grep build
if build successful ./case.submit
while running grep warmtcp $RUNDIR/*.log*
after running grep warmtcp /glade/scratch/$USER/archive/$CASENAME/logs/atm.log*
Exercise 3: Code Change
• Examine the mean effects of delaying the initiation of convection by
increasing the minimum required convective available potential energy
(CAPE) to initiate convection over land;
Copy fortran code file that controls deep convection calculation (Zhang and McFarlane, 1995) to local
code modification directory for the atmosphere
cd $CASEDIR
cp /glade/p/cesm/tutorial/cesm2.1_tutorial2022/components/cam/src/physics/cam/zm_conv.F90 \
SourceMods/src.cam
physpkg.F90:phys_run1()
1. call convect_shallow_tend(state, ptend,…)
convect_shallow.F90:subroutine convect_shallow_tend(state,
ptend,…) Intents show that the interface can only modify ptend, not
intent(in) state state. The ptend is returned from the parameterization method
intent(out) ptend
Ø The existing parameterizations can serve as examples to follow, but some have
better code than others!
(Exercise 4): Code Change
Reading documentation
If you want to replace an existing parameterization, you may need to first
learn what is already in CAM, in order to find the correct search terms.
This doesn't tell you much more than the name of the new scheme in CAM5
and what it replaces, but it's a start.
http://www.cesm.ucar.edu/models/cesm1.0/cam/docs/description/cam5_desc.pdf
4.3 Shallow Convection Scheme
Shallow convection scheme in CAM5 is from Park and Bretherton [2009]
that is a replacemnt of Hack [1994b]…
(Exercise 4): Code Change
Browsing the source code
The source code is under the $rootdir (recall where you go to call create_newcase).
This exercise mostly makes changes to code in the physics/cam subdirectory but I'll point out
control/ as a useful directory, holding physical constants, interpolation routines and, indeed,
the top level module for the CAM model component, cam_comp.F90
You can find a lot by looking through source code files. For our shallow convection example, notice
there is a file called models/atm/cam/src/physics/cam/convect_shallow.F90
Looking at, you can see there are different convection options (
! The following namelist variable (shallow_scheme) controls which shallow conv package is used.
! 'Hack' = Hack shallow convection (default)
! 'UW' = UW shallow convection by Sungsu Park and Christopher S. Bretherton
! 'off' = No shallow convection
(Exercise 4): Code Change-
Optional tools to search CAM code
Ø UNIX commands find and grep can do the job
Ø However, CAM source code is
•in a complicated directory structure and
•any particular model build uses only a subset of the source code (eg. dycores)
So we have tools that use find and grep within this directory structure
Ø These tools are available with this tutorial although their use is optional;
If you want to use them in the future, copy them to your home machine before you go
grepccm string searches for string in all files in the directories used by this particular model build
findccm filename searches for a file named filename in all the directories used by this model build
Ø For now, copy /glade/u/home/bundy/bin/grepccm and make executable
cp ~bundy/bin/grepccm ~; chmod 755 ~/grepccm
cp ~bundy/bin/findccm ~; chmod 755 ~/findccm
Once you’ve completed these ‘toy’ exercises, you will be free to expand upon
them or start using your own work.
(Exercise 4)
Add a new (fake) parameterization
To create a new file, you need to place valid source code in SourceMods/src.cam
My advice is to copy an existing interface & parameterization to a new name,
and remove most of the code to create a 'stub' parameterization.
Code that is newer to the model might have better coding practices… or might not.
Whenever you create a new file, you need to force the build process to notice it:
% cd /glade/scratch/$USER/$CASENAME/bld/atm/obj
% rm Depends
% rm Srcfiles
% cd $CASEROOT
% case.build
Check that the new file was compiled by looking at timestamp of .mod/.o files in bld dir
% ls -ltr /glade/scratch/$USER/$CASENAME/bld/atm/obj/
You should see param, param_interface files and timestamp of physpkg.* should be later than original build.
(Exercise 4): Add a parameterization
What’s next?
After completing these ‘toy’ exercises, you may want to:
• have the new param add a field to the history file (addfld/outfld)
• do something with the physics buffer (pbuf) in the new parameterization
• write code in param.F90 to do something more. Check that it's working.
• make a modification of your choice to an existing parameterizations
• … your choice
Although outdated, this provides details of how the CAM routines are called, the data
structures (state, ptend), the array dimensions (chunks and columns), and descriptions of
subcolumns and radiative constituents.
• Unit testing
http://www.cesm.ucar.edu/events/ws.2014/Presentations/SEWG/santos.pdf