|
1 | 1 | # eCLM static file generator |
2 | 2 |
|
| 3 | +[](https://github.com/HPSCTerrSys/eCLM_static-file-generator/actions/workflows/doc.yml) |
| 4 | + |
| 5 | +## Introduction |
| 6 | + |
3 | 7 | This repository shows how to generate curvilinear surface and domain fields for eCLM simulations. |
4 | 8 | The generator follows the official CLM-workflow but makes a few adaptions. |
5 | 9 |
|
6 | | -It is not necessary to clone [CTSM](https://github.com/ESCOMP/CTSM.git) and [cime](https://github.com/ESMCI/cime.git), as this generator is independent. |
7 | | -However, the basis is the CLM5.0 release and there might be newer developments in the official repositories. |
| 10 | +## Usage / Documentation |
8 | 11 |
|
9 | | -By sourcing the provided environment file |
| 12 | +If on [JSC HPC](https://www.fz-juelich.de/en/jsc/), start with sourcing the provided environment file and set the raw data path: |
10 | 13 |
|
11 | 14 | ``` |
12 | 15 | source jsc.2024_Intel.sh |
| 16 | +export CSMDATA="/p/scratch/cslts/shared_data/rlmod_eCLM/inputdata/" # this works for JSC users only |
13 | 17 | ``` |
14 | 18 |
|
15 | | -the necessary compilations in this repository can be performed consistently. It also contains the export of necessary paths for netCDF. |
16 | | -If you are on a [JSC](https://www.fz-juelich.de/en/ias/jsc) machine, it will be very useful to set this data path: |
17 | | - |
18 | | -``` |
19 | | -export CSMDATA="/p/largedata2/detectdata/CentralDB/projects/z04" |
20 | | -``` |
21 | | - |
22 | | -If not, you'll have to get the relevant raw data at the respective steps and either set `$CSMDATA` to a different path or replace it with your respective local directory. |
23 | | - |
24 | | -To create all static files needed to run eCLM, you first need to create a gridfile, then mapping and domain files and only then you can create surface and forcing files. |
25 | | -For this the grid has to be properly defined in one of the following formats: |
26 | | - |
27 | | -- SCRIP |
28 | | -- ESMF-Mesh |
29 | | -- CF-convention-file |
30 | | - |
31 | | -SCRIP is a very old format not maintained anymore but is still the most effective solution. |
32 | | -ESMF is able to basically handle any netCDF file that follows the CF-conventions version 1.6 and includes lat/lon values and corners. |
33 | | -This means that ESMF mesh files are also able to describe unstructured grids. |
34 | | - |
35 | | -**Hint:** Once a static file generation is started, it is best |
36 | | -practice to **not anymore copy or move the repository**. This ensures |
37 | | -tracability of absolute paths, e.g. absolute paths of map files saved |
38 | | -in the domain file as netCDF attributes. |
39 | | - |
40 | | -## Creation of gridfile |
41 | | - |
42 | | -First, we need to create a gridfile that describes our simulation domain. |
43 | | -These come in two resolutions: ~12 km resolution (EUR-R13B05) and ~3 km resolution (EUR-R13B07). |
44 | | -Choose one of these two grids if you want to use this with TSMP2. |
45 | | -In this guide the default is EUR-R13B05, meaning that you will end up with all low-resolution static files on the *icosahedral* grid if you do not modify any of the following commands or scripts. |
46 | | -For other purposes guidelines for the *rectilinear* and *curvilinear* grids are here as well. |
47 | | -A curvilinear grid is normally used for CLM5, and when you run eCLM stand-alone you might choose to use a curvilinear grid as well. |
48 | | - |
49 | | -The relevant scripts to create the grid files are in `./mkmapgrids/`. |
50 | | -The gridfile will contain arrays of longitudes and latitudes of the gridboxes' centres and corners. |
51 | | -The simulation domain is the EURO-CORDEX pan-European domain, which at high latitudes, for the Earth's canonical curvilinear grid, has significant convergence of the zonal dimension with increasing latitude. |
52 | | -Therefore we *rotate* the grid (of a same size) centred at the equator to the pan-European domain. |
53 | | - |
54 | | -Grid files are available on the JSC machines in the DETECT CentralDB below `/p/largedata2/detectdata/CentralDB/projects/z04/detect_grid_specs/grids/` (`$CSMDATA/detect_grid_specs/grids`). |
55 | | -This is part of a Git repository that is also available [here](https://gitlab.jsc.fz-juelich.de/detect/detect_z03_z04/detect_grid_specification). |
56 | | - |
57 | | -### Rectilinear grid |
58 | | - |
59 | | -You can create a SCRIP file from a *rectilinear grid* with [`mkscrip_rect.py`](mkmapgrids/mkscrip_rect.py). |
60 | | -The Python packages numpy, xarray and dask-expr need to be available. |
61 | | -They are loaded by the [environment file](jsc.2024_Intel.sh) (sourced above). |
62 | | -On machines without the modules from the environment file, you can install the Python packages with `pip3`, probably best in a [virtual environment](https://docs.python.org/3/library/venv.html), if they are not all available as a package in your operating system. |
63 | | -The script was modified from `mesh_maker.py` from the CTSM repository to accept 2D lon / lat. |
64 | | -The main caveat is that the resulting surface files are in 1D which makes them harder to handle. |
65 | | -The python script `mkscrip_rect.py` can create SCRIP files including the calculation of corners. |
66 | | -It takes command line arguments like this: |
67 | | - |
68 | | -``` |
69 | | -./mkscrip_rect.py --ifile EUR-regLonLat01deg_1204x548_grid_inclbrz_v2.nc --ofile EUR-regLonLat01deg_659792_grid_SCRIP.nc --oformat SCRIP |
70 | | -``` |
71 | | - |
72 | | -`--help` provides additional information. |
73 | | - |
74 | | -#### Rectilinear grid II: Python script for direct SCRIP-grid-file generation |
75 | | - |
76 | | -One can create a SCRIP file for a rectilinear script using the Python |
77 | | -script `mkmapgrids/mkscripgrid.py`. |
78 | | - |
79 | | -For its usage, in particular setting inputs, please refer to the |
80 | | -script itself. |
81 | | - |
82 | | -#### Rectilinear grid III: External Perl script from CTSM/CLM5 repo |
83 | | - |
84 | | -The following Perl script from CTSM/CLM5 provides an interface to |
85 | | -similar functionality as the Python script |
86 | | -`mkmapgrids/mkscripgrid.py`: |
87 | | - |
88 | | -https://github.com/ESCOMP/CTSM/blob/994e02983cf557410fe455b6bd64ee61ca50d488/tools/site_and_regional/mknoocnmap.pl |
89 | | - |
90 | | -### Curvilinear grid |
91 | | - |
92 | | -eCLM can be used with a *curvilinear grid*. |
93 | | - |
94 | | -You can, e.g., use the 450x438 gridfile including boundary relaxation zone, `EUR-11_450x438_grid_inclbrz13gp_v2.nc`, as the input file. |
95 | | -If you want a high-resolution curvilinear grid, use `EUR-0275_1600x1552_grid_inclbrz_v2.nc`. |
96 | | -However, in eCLM we use a slightly smaller domain, so you must truncate the files: |
97 | | - |
98 | | -``` |
99 | | -cd mkmapgrids/ |
100 | | -ncks -d rlat,3,434 -d rlon,3,446 $CSMDATA/detect_grid_specs/grids/EUR-11_450x438_grid_inclbrz13gp_v2.nc EUR-11_444x432_grid_inclbrz13gp_v2.nc |
101 | | -ncks -d rlat,3,1548 -d rlon,3,1596 $CSMDATA/detect_grid_specs/grids/EUR-0275_1600x1552_grid_inclbrz_v2.nc EUR-0275_1594x1546_grid_inclbrz_v2.nc |
102 | | -``` |
103 | | - |
104 | | -At the moment SCRIP generation from curvilinear grids can be done and is tested to work with the NCAR Command Language (NCL), even though it is [deprecated](https://www.ncl.ucar.edu/open_letter_to_ncl_users.shtml). |
105 | | -NCL can be installed through Conda. |
106 | | -If you have no Conda yet on your system, you can install it, including the conda-forge channel, following [this guide](https://github.com/conda-forge/miniforge?tab=readme-ov-file#unix-like-platforms-macos-linux--wsl). |
107 | | -Then follow [this guide](https://yonsci.github.io/yon_academic/portfolio/portfolio-9/#installing-ncl) to install NCL. |
108 | | -The repository contains the NCL-script [`mkscrip_curv.ncl`](mkmapgrids/mkscrip_curv.ncl) that can create a SCRIP file from a netCDF that contains the lat- and lon-center coordinates. |
109 | | -It is not necessary to provide the corners because the internal routine of NCL seems to calculate them correctly for the later steps. |
110 | | -Adapt the variable `f` in `mkscrip_curv.ncl` to your gridfile and execute: |
111 | | - |
112 | | -``` |
113 | | -conda activate NCL_environment |
114 | | -ncl mkscrip_curv.ncl |
115 | | -conda deactivate |
116 | | -conda deactivate |
117 | | -``` |
118 | | - |
119 | | -### Icosahedral grid |
120 | | - |
121 | | -The atmospheric model ICON runs on an *icosahedral grid*, sometimes called *triangular grid*. |
122 | | -The land model eCLM, when coupled to ICON (in TSMP2), also uses this grid. |
123 | | - |
124 | | -Check out https://zonda.ethz.ch/ for generating icosahedral input grids for `mkscrip_icos.py` (specified under option `--ifile`). |
125 | | - |
126 | | -Then convert your ICON gridfile to the SCRIP format with the python script [`mkscrip_icos.py`](mkmapgrids/mkscrip_icos.py): |
127 | | - |
128 | | -``` |
129 | | -./mkscrip_icos.py --ifile EUR-R13B05_199920_grid_inclbrz_v2.nc --ofile EUR-R13B05_199920_grid_SCRIP.nc |
130 | | -``` |
131 | | - |
132 | | -For [TSMP2](https://github.com/HPSCTerrSys/TSMP2), on a 0.11 degree (~12 km) resolution, you probably want to use the EUR-R13B05 grid including boundary relaxation zone, `EUR-R13B05_199920_grid_inclbrz_v2.nc`, as the input file. |
133 | | -If you want a high-resolution icosahedral grid, use `EUR-R13B07_2473796_grid_inclbrz_v1.nc`. |
134 | | - |
135 | | -Further information about the DETECT grid specification can be found [here](https://gitlab.jsc.fz-juelich.de/detect/detect_z03_z04/detect_grid_specification). |
136 | | - |
137 | | -## Creation of mapping files |
138 | | - |
139 | | -For the creation of the mapping files of CLM inputdata to our grid use `mkmapdata/runscript_mkmapdata.sh`. |
140 | | -Adjust the Slurm directives to your compute time project and partition. |
141 | | -Below the Slurm directives, modify `GRIDNAME` and `GRIDFILE` to your grid and previously created SCRIP file. |
142 | | -The script can be used on JURECA and JUWELS but it is advisable to use the large memory partitions for larger domains. |
143 | | - |
144 | | -The files are at JSC available below `$CSMDATA/lnd/clm2/mappingdata/grids/`. |
145 | | -If you don't have access to the CLM mappingdata you have to download it. |
146 | | - |
147 | | -There are two possible ways to download the grids |
148 | | - |
149 | | -1. Use: |
150 | | -``` |
151 | | -wget --no-check-certificate -i clm_mappingfiles.txt |
152 | | -``` |
153 | | - |
154 | | -2. Run `download_grids.sh` after adapting inputs (in particular the path `myraw`). |
155 | | - You need Subversion (`svn`) for this. |
156 | | -``` |
157 | | -./download_grids.sh |
158 | | -``` |
159 | | - |
160 | | -When all grids are downloaded, start the creation of the weights with |
161 | | -``` |
162 | | -sbatch runscript_mkmapdata.sh |
163 | | -``` |
164 | | - |
165 | | -This will create regridding and netCDF mapping files in the current |
166 | | -directory. |
167 | | - |
168 | | -### Icosahedral grid |
169 | | - |
170 | | -Experience has shown that conservative remapping does not always work for icosahedral grids (EUR-R13B05 and EUR-R13B07). |
171 | | -In that case `runscript_mkmapdata.sh` decides to create a mapping file that bilinearly interpolates fields. |
172 | | - |
173 | | -## Creation of domain files |
174 | | - |
175 | | -The CIME submodule under `./gen_domain_files/` generates the domain files for CLM. |
176 | | -This repository contains a simplified version of `gen_domain` which is easier to compile on JSC machines and you do not need the CIME repository. |
177 | | -Required modules are imkl, netCDF and netCDF-Fortran (all provided by `jsc.2024_Intel.sh`). |
178 | | -Then compile `src/gen_domain.F90` with |
179 | | - |
180 | | -``` |
181 | | -gfortran -o gen_domain src/gen_domain.F90 -mkl -I${INC_NETCDF} -lnetcdff -lnetcdf |
182 | | -``` |
183 | | - |
184 | | -If the Intel Math Kernel Library (MKL) is not available on your system, you can remove the `-mkl` flag without consequences for the output. |
185 | | -After the compilation you can execute `gen_domain` with $MAPFILE being one of the mapping files created in the step before (in `mkmapdata/`) and $GRIDNAME being a string with the name of your grid, e.g. `EUR-R13B05` for the ~12-km icosahedral grid. |
186 | | -The choice of $MAPFILE does not influence the lat- and longitude values in the domain file but can influence the land/sea mask. |
187 | | - |
188 | | -**Hint:** For better reproducibility, specify the absolute path of |
189 | | -`$MAPFILE`. The absolute path to the file can be printed using |
190 | | -`realpath $MAPFILE`. |
191 | | - |
192 | | -``` |
193 | | -./gen_domain -m $MAPFILE -o $GRIDNAME -l $GRIDNAME -u $USER |
194 | | -``` |
195 | | - |
196 | | -The created domain file will later be modified. |
197 | | - |
198 | | -## Creation of surface file |
199 | | - |
200 | | -The surface creation tool is found under `./mksurfdata/`. |
201 | | -The required modules Intel and netCDF-Fortran are loaded by `jsc.2024_Intel.sh`. |
202 | | - |
203 | | -First, compile `mksurfdata_map`: |
204 | | - |
205 | | -``` |
206 | | -cd mksurfdata/src |
207 | | -gmake |
208 | | -``` |
209 | | - |
210 | | -Then check that `mksurfdata_map` is available inside `./mksurfdata/`. |
211 | | - |
212 | | -After compilation execute |
213 | | - |
214 | | -``` |
215 | | -export GRIDNAME="EUR-R13B05" # in case of the low-resolution icosahedral grid |
216 | | -export CDATE="`date +%y%m%d`" # should match mapping files creation date |
217 | | -
|
218 | | -# generate surfdata |
219 | | -./mksurfdata.pl -r usrspec -usr_gname $GRIDNAME -usr_gdate $CDATE -l $CSMDATA -allownofile -y 2005 -hirespft |
220 | | -``` |
221 | | - |
222 | | -to create a real domain with hires pft. |
223 | | -Again, you need to have set $GRIDNAME, the date $CDATE in yymmdd format (matching the mapping files) and the path $CSMDATA where the raw data of CLM is stored. |
224 | | -You have to download the data from https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/lnd/clm2/rawdata/ if you have no access to JSC machines. |
225 | | -Also make sure that mksurfdata and mkmapdata have the same parent directory. |
226 | | - |
227 | | -At least in the original UCAR rawdata input files, not all variables are available (under the correct name). |
228 | | -Instead you can create the surface file with *mostly* constant values (apparently `SOIL_COLOR` is not homogeneous) with the following command. |
229 | | -In a later step we are anyway going to replace variables in this file that are specific for eCLM (TSMP2). |
230 | | - |
231 | | -``` |
232 | | -./mksurfdata.pl -r usrspec -usr_gname $GRIDNAME -usr_gdate $CDATE -l $CSMDATA -allownofile -y 2005 -hirespft -usr_mapdir="../mkmapdata/" -no-crop -pft_idx 13 -pft_frc 100 -soil_cly 60 -soil_col 10 -soil_fmx 0.5 -soil_snd 40 |
233 | | -``` |
234 | | - |
235 | | - |
236 | | -## Modification of the surface and domain file |
237 | | - |
238 | | -The created surface and domain file have negative longitudes that CLM5 does not accept and inherently has no landmask. To modify the longitudes and to add a landmask use `mod_domain.sh` after inserting the paths to your files. |
239 | | - |
240 | | -At least for TSMP2, further modification of the surface file is needed and not yet included in this (tested) workflow. |
241 | | -The necessary replacement routines can be found in the `dev_replace_tsmp2` branch in the [`mksurfdata/`](https://github.com/HPSCTerrSys/eCLM_static-file-generator/tree/dev_replace_tsmp2/mksurfdata) directory. |
242 | | - |
243 | | - |
244 | | -## Surface File: Use landcover GLC2000 and soil texture from SOILGRIDS |
245 | | - |
246 | | -Only for BGC mode! |
247 | | - |
248 | | -The following script updates landcover using GLC2000 and soils using SOILGRIDS. |
249 | | - |
250 | | -``` |
251 | | -./replace_surfdata.py |
252 | | -``` |
| 19 | +Otherwise you need to provide for the data and software environment yourself (as documented below). |
253 | 20 |
|
254 | | -Additionally, this script checks CLM gridcells to make sure the |
255 | | -percentages per landunit in each gridcell sum up to one. |
| 21 | +Then please check the [generated documentation](https://hpscterrsys.github.io/eCLM_static-file-generator/INDEX.html) online, [generate a static version](docs/README.md) yourself or browse it locally: `$VISUAL docs/users_guide/?_*.md` with `$VISUAL` your editor or viewer of choice. |
256 | 22 |
|
| 23 | +## License |
| 24 | +eCLM static file generator is open source software and is licensed under an [MIT License](https://github.com/HPSCTerrSys/eCLM_static-file-generator/blob/master/LICENSE). |
0 commit comments