Skip to content

Commit

Permalink
add readme expert_only and new sites
Browse files Browse the repository at this point in the history
  • Loading branch information
huitang-earth committed Jun 10, 2020
1 parent ebb2432 commit 88e5e7e
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 2 deletions.
75 changes: 74 additions & 1 deletion README_fates_emerald_api_expert_only
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
To be added soon.
$CTSMROOT/README_fates_emerald_api_expert_only 03/06/2020

#################################################################################
# This document explains how to update the model codes and
# how to create atmospheric forcing and inputdata for new sites
# (No technical support will be promised, use at your own risk!)
# See also Yeliz's notes: https://ctsm-docs.readthedocs.io/en/latest/ for additional details
#################################################################################

######## Two important things to watch out first!!!
######## Two important things to watch out first!!!
######## Two important things to watch out first!!!
(1) Module environment on your supercomputer: DON'T load any module beforehand, except "StdEvn"!
(2) Git version control:
CLM-FATES have very complex and sperate repository system:
-> ctsm: always create your own branch, do not touch master!
-> cime: remember to create your own branch in cime folder also, to record all the changes you make.
-> fates: remember to create your own branch in fates folder also, to record all the changes you make.
If you do not create your own branch for "cime" and "fates", when you run "./manage_externals/checkout_externals", your previous "cime" and "fates" will be overwritten.


######## Download ctsm and update ctsm-fates (Only important steps are illustrated here!!!)
**** If you are already using fates_emerald_api, skip this! ****
e.g.:
git remote add ctsm_ncar https://github.com/ESCOMP/CTSM.git # set a remote name for NCAR CTSM git repository
git fetch ctsm_ncar # get the most recent updates of CTSM
git merge ctsm_ncar/master # update your current branch with the newest CTSM version
git merge ctsm_ncar/fates_next_api # update your current branch with the newest CLM-FATES interface

##To update fates, you need to go to fates folder
e.g.:
git remote add NGEET_fates https://github.com/NGEET/fates.git
git fetch NGEET_fates # get the most recent updates of FATES
git merge NGEET_fates.git/master # update your current branch with the newest FATES

######## Adapt ctsm/cime to specific machine (e.g., SAGA and FRAM)
**** If you are already using fates_emerald_api, skip this! ****
Following file need to be modified
..../cime/config/cesm/machines/config_batch.xml
..../cime/config/cesm/machines/config_compilers.xml
..../cime/config/cesm/machines/config_machines.xml

See example here, you need look for the setup
https://github.com/NordicESMhub/cime/blob/cime5.6.10_noresm2_1_rel_06/config/cesm/machines/config_compilers.xml
https://github.com/NordicESMhub/cime/blob/cime5.6.10_noresm2_1_rel_06/config/cesm/machines/config_machines.xml
https://github.com/NordicESMhub/cime/blob/cime5.6.10_noresm2_1_rel_06/config/cesm/machines/config_batch.xml


**** If you want to set up new sites, please follow the following steps ****
######## Make script grids (see "prepare_inputdata.sh" in ./tools)
######## Make domain file (see "prepare_inputdata.sh" in ./tools)
######## Make mapping file (see "prepare_inputdata.sh" in ./tools)
######## Make surface data file (see "prepare_inputdata.sh" in ./tools)
######## Make and modify FATES parameter file:
## Use existing tools:
./src/fates/tools/FatesPFTIndexSwapper.py # Select PFTs interested.
./src/fates/tools/modify_fates_paramfile.py # Modify PFT parameters
## To use these tools, netcdf and python modules need to be loaded.
module load netCDF-Fortran/4.4.4-intel-2018b
module load Python/3.6.6-intel-2018b
./FatesPFTIndexSwapper.py --pft-indices=2,6,9,10 --fin=****.nc --fout=****.nc
## The default FATES parameter file is in ./src/fates/parameter_files
## To create a netcdf parameter file: ncgen -o ****.nc fates_params_default.cdl
######## Make atmospheric forcing for new sites (see "prepare_atm_forcing_****.ncl" in ./tools)

######## Set each sites as a unique grid type. The following file need to be modified:
~/ctsm/cime/config/cesm/config_grids.xml
~/ctsm/cime/src/components/data_comps/datm/cime_config/namelist_definition_datm.xml
~/ctsm/bld/namelist_files/namelist_defaults_clm4_5.xml

######## Set new atmospheric forcing for the sites
~/ctsm/cime/src/components/data_comps/datm/cime_config/config_component.xml (for different climate forcing)
~/ctsm/cime_config/config_component.xml (for different climate forcing)

43 changes: 42 additions & 1 deletion bld/namelist_files/namelist_defaults_clm4_5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,24 @@ lnd/clm2/surfdata_map/fates_platform/BOR2/surfdata_BOR2_simyr2000.nc</fsurdat>
lnd/clm2/surfdata_map/fates_platform/BOR3/surfdata_BOR3_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_BOR4" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/BOR4/surfdata_BOR4_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_LYG" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/LYG/surfdata_LYG_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_BUO" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/BUO/surfdata_BUO_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_HAV" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/HAV/surfdata_HAV_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_SKO" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/SKO/surfdata_SKO_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_VIKE" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/VIKE/surfdata_VIKE_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_JOAS" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/JOAS/surfdata_JOAS_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_LIAH" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/LIAH/surfdata_LIAH_simyr2000.nc</fsurdat>
<fsurdat hgrid="1x1_FINN" sim_year="2000" use_crop=".false." irrigate=".true.">
lnd/clm2/surfdata_map/fates_platform/FINN/surfdata_FINN_simyr2000.nc</fsurdat>



<!-- for pre-industrial simulations - year 1850 without crop -->
<fsurdat hgrid="48x96" sim_year="1850" use_crop=".false." irrigate=".true.">
Expand Down Expand Up @@ -1155,6 +1173,14 @@ lnd/clm2/surfdata_map/release-clm5.0.30/surfdata_0.9x1.25_SSP5-3.4_78pfts_CMIP6_
<ndepmapalgo use_cn=".true." hgrid="1x1_BOR2" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_BOR3" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_BOR4" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_LYG" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_BUO" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_HAV" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_SKO" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_VIKE" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_JOAS" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_LIAH" >nn</ndepmapalgo>
<ndepmapalgo use_cn=".true." hgrid="1x1_FINN" >nn</ndepmapalgo>

<!-- Soilm moisture streams namelist defaults -->
<!-- This is if you want to prescribe the soil moisture from input datasets rather than model it -->
Expand Down Expand Up @@ -1204,7 +1230,14 @@ lnd/clm2/surfdata_map/release-clm5.0.30/surfdata_0.9x1.25_SSP5-3.4_78pfts_CMIP6_
<lai_mapalgo hgrid="1x1_BOR2" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_BOR3" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_BOR4" >nn</lai_mapalgo>

<lai_mapalgo hgrid="1x1_LYG" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_BUO" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_HAV" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_SKO" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_VIKE" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_JOAS" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_LIAH" >nn</lai_mapalgo>
<lai_mapalgo hgrid="1x1_FINN" >nn</lai_mapalgo>

<!-- lightning streams namelist defaults -->

Expand Down Expand Up @@ -1303,6 +1336,14 @@ lnd/clm2/surfdata_map/release-clm5.0.30/surfdata_0.9x1.25_SSP5-3.4_78pfts_CMIP6_
<popdensmapalgo use_cn=".true." hgrid="1x1_BOR2" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_BOR3" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_BOR4" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_LYG" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_BUO" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_HAV" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_SKO" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_VIKE" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_JOAS" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_LIAH" >nn</popdensmapalgo>
<popdensmapalgo use_cn=".true." hgrid="1x1_FINN" >nn</popdensmapalgo>

<!-- Urban time varying streams namelist defaults -->
<stream_year_first_urbantv phys="clm5_0" sim_year_range="1850-2100" >2015</stream_year_first_urbantv>
Expand Down
1 change: 1 addition & 0 deletions tools/mksurfdata_map/src/mkdomainMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ logical function domain_read_map(domain, fname)

! Read domain file and compute stuff as needed


call check_ret(nf_open(fname, 0, ncid), subname)

! Assume unstructured grid
Expand Down
159 changes: 159 additions & 0 deletions tools/prepare_atm_forcing_gswp3.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/popRemap.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"

begin

;######### SeedClim Sites
; plot_lat=(/61.0243,60.8231,60.8328,60.9335,60.8203,60.8760,61.0866,60.5445,61.0355,60.8803,60.6652,60.6901/)
; plot_lon=(/8.12343,7.27596,7.17561,6.41504,8.70466,7.17666,6.63028,6.51468,9.07876,7.16982,6.33738,5.96487/)
; plot_name=(/"ALP1","ALP2","ALP3","ALP4","SUB1","SUB2","SUB3","SUB4","BOR1","BOR2","BOR3","BOR4"/)

;######### Landpress Sites
; plot_lat=(/60.70084,65.83677,64.779,65.79602/)
; plot_lon=(/5.092566,12.224506,11.2193,12.219299/)
; plot_name=(/"LYG","BUO","HAV","SKO"/)

;######### Three-D Sites
plot_lat=(/60.88019,60.86183,60.85994/)
plot_lon=(/7.16990,7.16800,7.19504/)
plot_name=(/"VIKE","JOAS","LIAH"/)

;######### Finnmark Site
; plot_lat=(/69.341088/)
; plot_lon=(/25.293524/)
; plot_name=(/"FINN"/)

mon = ispan(0,11,1)
mon@units = "month"
month =cd_string(mon,"%N")
print(month)

do p=0,2,1
clim_output = "/cluster/shared/noresm/inputdata/atm/datm7/fates_platform/"+plot_name(p)+"/"
clim_input = "/cluster/shared/noresm/inputdata/atm/datm7/atm_forcing.datm7.GSWP3.0.5d.v1.c170516/"
system("mkdir -p "+ clim_output)
xfloor=plot_lon(p)-0.005
xceil =plot_lon(p)+0.005
yfloor=plot_lat(p)-0.005
yceil =plot_lat(p)+0.005
print(yceil)
print(xceil)

do year=1901,2010,1
do m=0,11,1

frsds=addfile(clim_input+"/Solar/clmforc.GSWP3.c2011.0.5x0.5.Solr."+year+"-"+month(m)+".nc","r")
fprec=addfile(clim_input+"/Precip/clmforc.GSWP3.c2011.0.5x0.5.Prec."+year+"-"+month(m)+".nc","r")
ftphw=addfile(clim_input+"/TPHWL/clmforc.GSWP3.c2011.0.5x0.5.TPQWL."+year+"-"+month(m)+".nc","r")

rsds=frsds->FSDS(:,:,:)
prec=fprec->PRECTmms(:,:,:)
psrf=ftphw->PSRF(:,:,:)
tbot=ftphw->TBOT(:,:,:)
wind=ftphw->WIND(:,:,:)
qbot=ftphw->QBOT(:,:,:)
flds=ftphw->FLDS(:,:,:)

lon=frsds->LONGXY(0,:)
lat=frsds->LATIXY(:,0)
time=frsds->time(:)
edgew =frsds->EDGEW
edgee =frsds->EDGEE
edges =frsds->EDGES
edgen =frsds->EDGEN
longxy =frsds->LONGXY
latixy =frsds->LATIXY

loni=ind_nearest_coord(plot_lon(p), lon, 0)
latj=ind_nearest_coord(plot_lat(p), lat, 0)
print(loni)
print(latj)

;########## Creat forcing in netcdf format

system("rm -f "+clim_output+"clm1pt_"+plot_name(p)+"_"+year+"-"+month(m)+".nc") ; remove if exists
fclim = addfile(clim_output+"clm1pt_"+plot_name(p)+"_"+year+"-"+month(m)+".nc","c")
ntim = dimsizes(time) ; get dimension sizes
nlat = 1
nlon = 1
nscalar = 1

setfileoption(fclim,"DefineMode",True)

fAtt = True ; assign file attributes
fAtt@case_title = "GSWP3v1: norway "
fAtt@conventions = "CF-1.0"
fAtt@title = "CLM single point datm input data"
fAtt@history = "Original data from GSWP3v1 data"
fAtt@creation_date = systemfunc ("date")
fileattdef( fclim, fAtt ) ; copy file attributes

dimNames = (/"scalar","lon","lat","time"/)
dimSizes = (/ nscalar, nlon, nlat, -1 /)
dimUnlim = (/ False, False, False, True/)
filedimdef(fclim,dimNames,dimSizes,dimUnlim)

filevardef(fclim, "EDGEW" ,typeof(edgew),getvardims(edgew))
filevardef(fclim, "EDGEE" ,typeof(edgee),getvardims(edgee))
filevardef(fclim, "EDGES" ,typeof(edges),getvardims(edges))
filevardef(fclim, "EDGEN" ,typeof(edgen),getvardims(edgen))
filevardef(fclim, "LONGXY" ,typeof(longxy) ,getvardims(longxy))
filevardef(fclim, "LATIXY" ,typeof(latixy) ,getvardims(latixy))
filevardef(fclim, "time",typeof(time),getvardims(time))
filevardef(fclim, "FSDS",typeof(rsds),getvardims(rsds))
filevardef(fclim, "PRECTmms",typeof(prec),getvardims(prec))
filevardef(fclim, "TBOT",typeof(tbot),getvardims(tbot))
filevardef(fclim, "WIND",typeof(wind),getvardims(wind))
filevardef(fclim, "PSRF",typeof(psrf),getvardims(psrf))
filevardef(fclim, "QBOT",typeof(qbot),getvardims(qbot))
filevardef(fclim, "FLDS",typeof(flds),getvardims(flds))

filevarattdef(fclim,"EDGEW",edgew)
filevarattdef(fclim,"EDGEE",edgee)
filevarattdef(fclim,"EDGES",edges)
filevarattdef(fclim,"EDGEN",edgen)
filevarattdef(fclim,"LONGXY",longxy)
filevarattdef(fclim,"LATIXY",latixy)
filevarattdef(fclim,"time",time)
filevarattdef(fclim,"FSDS",rsds)
filevarattdef(fclim,"PRECTmms",prec)
filevarattdef(fclim,"TBOT",tbot)
filevarattdef(fclim,"WIND",wind)
filevarattdef(fclim,"PSRF",psrf)
filevarattdef(fclim,"QBOT",qbot)
filevarattdef(fclim,"FLDS",flds)

setfileoption(fclim,"DefineMode",False)

print(time)
fclim->time = (/time/) ; "(/", "/)" syntax tells NCL to only output the data values to the predefined locations on the file.
fclim->EDGEW = (/xfloor/)
fclim->EDGEE = (/xceil/)
fclim->EDGES = (/yfloor/)
fclim->EDGEN = (/yceil/)
fclim->LONGXY = (/plot_lon(p)/)
fclim->LATIXY = (/plot_lat(p)/)
fclim->FSDS = (/rsds(:,latj,loni)/)
fclim->PRECTmms = (/prec(:,latj,loni)/) ; !!!! time variable can be modified in the attributes of the variable is also copied. make sure to use (/ /) to only copy data.
fclim->TBOT = (/tbot(:,latj,loni)/)
fclim->WIND = (/wind(:,latj,loni)/)
fclim->PSRF = (/psrf(:,latj,loni)/)
fclim->QBOT = (/qbot(:,latj,loni)/)
fclim->FLDS = (/flds(:,latj,loni)/)

delete(time)
delete(rsds)
delete(prec)
delete(tbot)
delete(qbot)
delete(wind)
delete(psrf)
delete(flds)

end do
end do
end do
end

Loading

0 comments on commit 88e5e7e

Please sign in to comment.