Skip to content

Commit 996f152

Browse files
committed
documentation and style for replace_surfdata.py script
1 parent 5de8289 commit 996f152

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,25 @@ In a later step we are anyway going to replace variables in this file that are s
232232
./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
233233
```
234234

235+
235236
## Modification of the surface and domain file
236237

237238
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.
238239

239240
At least for TSMP2, further modification of the surface file is needed and not yet included in this (tested) workflow.
240241
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.
241242

242-
Additional surface file processing is implemented in:
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.
243249

244250
```
245-
replace_surfdata.py # For BGC mode, updates landcover using GLC2000 and soils using SOILGRIDS.
251+
replace_surfdata.py
246252
```
253+
254+
Additionally, this script checks CLM gridcells to make sure the
255+
percentages per landunit in each gridcell sum up to one.
256+

mksurfdata/replace_surfdata.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import xarray as xr
22
import numpy as np
3-
import sys
3+
# import sys
44

55
file_clm5 = "/p/project1/cjibg36/jibg3674/eCLM_static-file-generator/surfdata_EUR-11_hist_78pfts_CMIP6_simyr2005_c251022.nc"
66
file_glc2000 = "/p/project1/cjibg36/jibg3674/TSMP_EUR-11/static.resource/08_LandCover/GLC2000_PFT_urban.nc"
@@ -14,47 +14,54 @@
1414
# print(open_clm5["PCT_CLAY"].dims, open_clm["PCT_CLAY"].dims)
1515
# print(open_clm5["PCT_CLAY"].shape, open_clm["PCT_CLAY"].shape)
1616

17-
open_clm5['PCT_CLAY'][:] = open_clm['PCT_CLAY'].values
18-
open_clm5['PCT_SAND'][:] = open_clm['PCT_SAND'].values
19-
open_clm5['ORGANIC'][:] = open_clm['ORGANIC'].values
17+
open_clm5["PCT_CLAY"][:] = open_clm["PCT_CLAY"].values
18+
open_clm5["PCT_SAND"][:] = open_clm["PCT_SAND"].values
19+
open_clm5["ORGANIC"][:] = open_clm["ORGANIC"].values
2020

2121
open_clm5["PCT_WETLAND"][:] = 0
22-
open_clm5['PCT_URBAN'][2,:,:] = open_glc2000['PCT_PFT'][19,:,:].values
23-
open_clm5['PCT_URBAN'][1,:,:] = 0
24-
open_clm5['PCT_GLACIER'][:,:] = open_glc2000['PCT_PFT'][18,:,:].values
25-
open_clm5['PCT_LAKE'][:,:] = open_glc2000['PCT_PFT'][17,:,:].values
22+
open_clm5["PCT_URBAN"][2, :, :] = open_glc2000["PCT_PFT"][19, :, :].values
23+
open_clm5["PCT_URBAN"][1, :, :] = 0
24+
open_clm5["PCT_GLACIER"][:, :] = open_glc2000["PCT_PFT"][18, :, :].values
25+
open_clm5["PCT_LAKE"][:, :] = open_glc2000["PCT_PFT"][17, :, :].values
2626

2727
open_clm5["PCT_CROP"][:, :] = open_glc2000["PCT_PFT"][15, :, :].values
28-
open_clm5["PCT_NATVEG"][:, :] = np.sum(open_glc2000["PCT_PFT"][0:15, :, :].values, axis=0)
28+
open_clm5["PCT_NATVEG"][:, :] = np.sum(
29+
open_glc2000["PCT_PFT"][0:15, :, :].values, axis=0
30+
)
2931
open_clm5["PCT_NAT_PFT"][0:15, :, :] = open_glc2000["PCT_PFT"][0:15, :, :].values
3032

31-
sum_patch = (
33+
sum_gridcell = (
3234
open_clm5["PCT_NATVEG"].values
3335
+ open_clm5["PCT_CROP"].values
3436
+ np.sum(open_clm5["PCT_URBAN"].values, axis=0)
3537
+ open_clm5["PCT_LAKE"].values
36-
+ open_clm5["PCT_GLACIER"].values)
37-
print("Min sum_patch:", np.nanmin(sum_patch))
38-
print("Max sum_patch:", np.nanmax(sum_patch))
38+
+ open_clm5["PCT_GLACIER"].values
39+
)
40+
print("Min sum_gridcell:", np.nanmin(sum_gridcell))
41+
print("Max sum_gridcell:", np.nanmax(sum_gridcell))
3942

4043
# Compute scaling factor, with safety margin
41-
scale = np.where(sum_patch > 0, 100 / sum_patch, 1.0)
44+
scale = np.where(sum_gridcell > 0, 100 / sum_gridcell, 1.0)
4245
for v in ["PCT_NATVEG", "PCT_CROP", "PCT_LAKE", "PCT_GLACIER", "PCT_URBAN"]:
4346
open_clm5[v].values *= scale
44-
print("New sum_patch (min, max):", np.nanmin(sum_patch * scale), np.nanmax(sum_patch * scale))
47+
print(
48+
"New sum_gridcell (min, max):",
49+
np.nanmin(sum_gridcell * scale),
50+
np.nanmax(sum_gridcell * scale),
51+
)
4552

4653

4754
pctspec = (
48-
open_clm5["PCT_LAKE"].values +
49-
open_clm5["PCT_WETLAND"].values +
50-
open_clm5["PCT_GLACIER"].values +
51-
np.sum(open_clm5["PCT_URBAN"].values, axis=0)
55+
open_clm5["PCT_LAKE"].values
56+
+ open_clm5["PCT_WETLAND"].values
57+
+ open_clm5["PCT_GLACIER"].values
58+
+ np.sum(open_clm5["PCT_URBAN"].values, axis=0)
5259
)
5360
print("Max pctspec:", np.nanmax(pctspec))
5461

55-
natpft = open_clm5["PCT_NAT_PFT"].values
62+
natpft = open_clm5["PCT_NAT_PFT"].values
5663
sum_natpft = np.sum(natpft, axis=0)
57-
sum_crop = np.sum(open_clm5["PCT_CFT"].values, axis=0)
64+
sum_crop = np.sum(open_clm5["PCT_CFT"].values, axis=0)
5865
print("Min sum_natpft:", np.nanmin(sum_natpft))
5966
print("Max sum_natpft:", np.nanmax(sum_natpft))
6067
print("Min sum_crop:", np.nanmin(sum_crop))
@@ -67,14 +74,15 @@
6774
mask_zero = sum_natpft == 0
6875
open_clm5["PCT_NAT_PFT"].values[0, mask_zero] = 100.0
6976

70-
print("New sum_natpft (min, max):",
71-
np.nanmin(np.sum(open_clm5["PCT_NAT_PFT"].values, axis=0)),
72-
np.nanmax(np.sum(open_clm5["PCT_NAT_PFT"].values, axis=0)))
77+
print(
78+
"New sum_natpft (min, max):",
79+
np.nanmin(np.sum(open_clm5["PCT_NAT_PFT"].values, axis=0)),
80+
np.nanmax(np.sum(open_clm5["PCT_NAT_PFT"].values, axis=0)),
81+
)
7382

7483
open_clm5.to_netcdf(file_dest)
7584
print(f"Saved modified surfdata to:\n{file_dest}")
7685

7786
open_clm5.close()
7887
open_glc2000.close()
7988
open_clm.close()
80-

0 commit comments

Comments
 (0)