Skip to content

Commit 389f628

Browse files
authored
eCLM preprocessing (#16)
* add eclm prepro * update .gitignore * add debugmode for pre * not loading enviroment in pre.job * add eCLM_static-file-generator as submodule
1 parent cc324b6 commit 389f628

File tree

8 files changed

+153
-4
lines changed

8 files changed

+153
-4
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
# logs
2+
ctl/logs
3+
# run directories
14
run/
5+
# data directories
6+
dta/restart
7+
dta/simres
8+
dta/forcing

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
path = dta/geo/parflow
3535
url = https://icg4geo.icg.kfa-juelich.de/ExternalReposPublic/tsmp2-static-files/extpar_parflow_cordex-eur-11u.git
3636
branch = master
37+
[submodule "src/eCLM_atmforcing"]
38+
path = src/eCLM_atmforcing
39+
url = https://github.com/HPSCTerrSys/eCLM_static-file-generator.git

ctl/control_tsmp2.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ partition="" # compute partition
4444
account="" # SET compute account. $BUDGET_ACCOUNTS / slts is used, if not set.
4545

4646
# wallclock
47-
pre_wallclock=00:05:00
47+
pre_wallclock=00:35:00
4848
sim_wallclock=00:25:00 # needs to be format hh:mm:ss
4949
pos_wallclock=00:05:00
5050
vis_wallclock=00:05:00
@@ -140,6 +140,8 @@ datep1=$(date -u -d -I "+${startdate} + ${simlength}")
140140
datem1=$(date -u -d -I "+${startdate} - ${simlength}")
141141
simlensec=$(( $(date -u -d "${datep1}" +%s)-$(date -u -d "${startdate}" +%s) ))
142142
simlenhr=$(($simlensec/3600 | bc -l))
143+
simlenmon=$(( (10#$(date -u -d "${datep1}" +%Y)-10#$(date -u -d "${startdate}" +%Y))*12 + \
144+
10#$(date -u -d "${datep1}" +%m)-10#$(date -u -d "${startdate}" +%m) ))
143145
dateymd=$(date -u -d "${startdate}" +%Y%m%d)
144146
dateshort=$(date -u -d "${startdate}" +%Y%m%d%H%M%S)
145147

@@ -168,7 +170,18 @@ jobprestring="${jobgenstring} \
168170
--ntasks=${npnode}"
169171

170172
# Submit to pre.job
171-
submit_pre=$(sbatch ${jobprestring} ${ctl_dir}/pre_ctl/pre.job 2>&1)
173+
if (! ${debugmode}) ; then
174+
# Submit to sim.job
175+
submit_pre=$(sbatch ${jobprestring} ${ctl_dir}/pre_ctl/pre.job 2>&1)
176+
echo $submit_pre" for preprocessing"
177+
else
178+
# Set lpre run & cleanup to false and source pre.job
179+
lpre[1]=false
180+
lpre[2]=false
181+
lprestr="${lpre[@]}"
182+
source ${ctl_dir}/pre_ctl/pre.job
183+
fi
184+
172185
echo $submit_pre" for preprocessing"
173186

174187
# get jobid

ctl/pre_ctl/pre.job

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ IFS=' ' read -r -a lvis <<< "$lvisstr"
1818
###
1919
# source environment
2020
###
21-
source ${tsmp2_env} # should be changed to pre-processing env.
21+
#source ${tsmp2_env} # chang pre-processing env. according to comp. model
2222

2323
###
2424
# Start config, run, cleanup

ctl/pre_ctl/pre_cleanup.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,26 @@ pre_cleanup(){
66

77
echo "Start Pre-processing cleanup"
88

9-
} # pre_cleanup
9+
####################
10+
# CLM
11+
####################
12+
if [[ "${modelid}" == *clm* ]]; then
13+
14+
echo "clean-up clm forcing"
15+
16+
for idate in ${listfrcfile[@]}; do
17+
ifile=${pre_dir}/${idate}/${idate}.nc
18+
cp ${ifile} ${eclmfrc_dir}
19+
done
20+
unset ifile
21+
22+
fi
1023

24+
# move logs
25+
mkdir -p ${eclmfrc_dir}/log/
26+
mv ${log_dir}/${SLURM_JOB_NAME}_${SLURM_JOB_ID}.{err,out} ${eclmfrc_dir}/log/.
27+
28+
# remove working directory
29+
rm -rf ${pre_dir:?}
30+
31+
} # pre_cleanup

ctl/pre_ctl/pre_config.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,72 @@ pre_config(){
66

77
echo "Start Pre-processing Config"
88

9+
####################
10+
# General
11+
####################
12+
13+
# create a new simulation run directory
14+
echo "pre_dir: "$pre_dir
15+
if [ -e "${pre_dir}" ]; then
16+
mv ${pre_dir} ${pre_dir}_bku$(date '+%Y%m%d%H%M%S')
17+
fi
18+
mkdir -p $pre_dir
19+
20+
# change to run directory
21+
cd ${pre_dir}
22+
23+
####################
24+
# CLM
25+
####################
26+
if [[ "${modelid}" == *clm* ]]; then
27+
28+
echo "start create clm forcing"
29+
30+
# directories
31+
lsmforcgensrc_dir=${ctl_dir}/../src/eCLM_atmforcing/mkforcing
32+
eclmfrc_dir=${frc_dir}/eclm/forcing/
33+
cdsapi_dtadir=${ctl_dir}/../src/eCLM_atmforcing/mkforcing/cdsapidwn
34+
35+
# check if forcing files already exists
36+
unset listfrcfile
37+
if [ ! -e "${eclmfrc_dir}/$(date -u -d "${startdate}" +%Y-%m).nc" ]; then
38+
listfrcfile+=("$(date -u -d "${startdate}" +%Y-%m)")
39+
fi
40+
if [[ "${simlenmon}" -ge 1 ]]; then
41+
for imon in $(seq 1 $simlenmon);do
42+
dateloop=$(date -u -d "${startdate} +${imon} month" +%Y-%m)
43+
if [ ! -e "${eclmfrc_dir}/${dateloop}.nc" ]; then
44+
listfrcfile+=("${dateloop}")
45+
fi
46+
done
47+
fi
48+
49+
echo "List of forcing files: "${listfrcfile[@]}
50+
51+
fi
52+
53+
54+
if ${debugmode}; then
55+
56+
# create job submission script (pre.job)
57+
echo "#!/usr/bin/env bash" > pre.job
58+
echo "#SBATCH ${jobprestring//[$'\t\r\n']}" >> pre.job
59+
60+
# add modelid, which is needed
61+
echo "" >> pre.job
62+
echo "modelid=${modelid}" >> pre.job
63+
echo "lsmforcgensrc_dir=${lsmforcgensrc_dir}" >> pre.job
64+
echo "cdsapi_dtadir=${cdsapi_dtadir}" >> pre.job
65+
echo "listfrcfile=(${listfrcfile[*]})" >> pre.job
66+
67+
# cat pre run script into submission script
68+
cat ${ctl_dir}/pre_ctl/pre_run.sh | tail -n +2 >> pre.job # start from line 2
69+
70+
sed -i "s/pre_run(){//" pre.job
71+
sed -i "s/} # pre_run//" pre.job
72+
sed -i "s#${log_dir}#${pre_dir}#g" pre.job
73+
74+
fi # debugmode
75+
976
} # pre_config
1077

ctl/pre_ctl/pre_run.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,42 @@ pre_run(){
66

77
echo "Start Pre-processing run"
88

9+
####################
10+
# CLM
11+
####################
12+
if [[ "${modelid}" == *clm* ]]; then
13+
14+
echo "Start processing clm"
15+
16+
module use $OTHERSTAGES
17+
module load Stages/2022 NVHPC/22.9 ParaStationMPI/5.5.0-1 CDO/2.0.2 NCO
18+
19+
20+
# list contain dates needed for forcing
21+
for yyyymm in "${listfrcfile[@]}"; do
22+
year="${yyyymm%%-*}"
23+
month="${yyyymm#*-}"
24+
mkdir -p $yyyymm # temporary directory for scripts
25+
26+
# extract data from ERA5 meteocloud
27+
srun --exclusive -n 1 ${lsmforcgensrc_dir}/extract_ERA5_meteocloud.sh iyear=$year imonth=$month \
28+
outdir=${pre_dir}/${yyyymm} #quiet=y
29+
30+
# # needs to be done in advance
31+
# # download from CDSAPI needs
32+
# python ${lsmforcgensrc_dir}/download_ERA5_input.py $year $month ${pre_dir}/${yyyymm}
33+
34+
# link cdsapi data for preparation script
35+
ln -s ${cdsapi_dtadir}/download_era5_${year}_$month.zip ${yyyymm}/
36+
37+
# preparation script
38+
srun --exclusive -n 1 ${lsmforcgensrc_dir}/prepare_ERA5_input.sh pathdata=${pre_dir}/${yyyymm} \
39+
iyear=$year imonth=$month wrkdir=${yyyymm}
40+
41+
done
42+
unset yyyymm year month
43+
44+
fi
45+
946
} # pre_run
1047

src/eCLM_atmforcing

Submodule eCLM_atmforcing added at 858634d

0 commit comments

Comments
 (0)