Skip to content

Commit

Permalink
Make e3sm_to_cmip task
Browse files Browse the repository at this point in the history
  • Loading branch information
forsyth2 committed Sep 5, 2023
1 parent d98b901 commit 5e73961
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 60 deletions.
96 changes: 96 additions & 0 deletions zppy/templates/e3sm_to_cmip.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash
{% include 'slurm_header.sh' %}
{{ environment_commands }}

# Turn on debug output if needed
debug={{ debug }}
if [[ "${debug,,}" == "true" ]]; then
set -x
fi

# Script dir
cd {{ scriptDir }}

# Get jobid
id=${SLURM_JOBID}

# Update status file
STARTTIME=$(date +%s)
echo "RUNNING ${id}" > {{ prefix }}.status

# Create temporary workdir
workdir=`mktemp -d tmp.${id}.XXXX`
cd ${workdir}

# Create symbolic links to input files
input={{ input }}/{{ input_subdir }}
for (( year={{ yr_start }}; year<={{ yr_end }}; year++ ))
do
YYYY=`printf "%04d" ${year}`
for file in ${input}/{{ case }}.{{ input_files }}.${YYYY}-*.nc
do
ln -s ${file} .
done
done





tmp_dir=tmp_{{ prefix }}

# Generate CMIP ts
cat > default_metadata.json << EOF
{% include cmip_metadata %}
EOF
{
export cmortables_dir={{ cmor_tables_prefix }}/cmip6-cmor-tables/Tables
input_dir={{ output }}/post/{{ component }}/{{ grid }}/ts/{{ frequency }}/{{ '%dyr' % (ypf) }}
dest_cmip={{ output }}/post/{{ component }}/{{ grid }}/cmip_ts/{{ frequency }}
mkdir -p ${dest_cmip}
srun -N 1 e3sm_to_cmip \
--output-path \
${dest_cmip}/${tmp_dir} \
{% if input_files.split(".")[0] == 'clm2' or input_files.split(".")[0] == 'elm' -%}
--var-list \
'mrsos, mrso, mrfso, mrros, mrro, prveg, evspsblveg, evspsblsoi, tran, tsl, lai, cLitter, cProduct, cSoilFast, cSoilMedium, cSoilSlow, fFire, fHarvest, cVeg, nbp, gpp, ra, rh' \
--realm \
lnd \
{% endif -%}
{% if input_files.split(".")[0] == 'cam' or input_files.split(".")[0] == 'eam' -%}
--var-list \
'pr, tas, rsds, rlds, rsus' \
--realm \
atm \
{% endif -%}
--input-path \
${input_dir}\
--user-metadata \
{{ scriptDir }}/${workdir}/default_metadata.json \
--num-proc \
12 \
--tables-path \
${cmortables_dir}

if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (1)' > {{ prefix }}.status
exit 1
fi

# Move output ts files to final destination
mv ${dest_cmip}/${tmp_dir}/CMIP6/CMIP/*/*/*/*/*/*/*/*/*.nc ${dest_cmip}
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (2)' > {{ prefix }}.status
exit 2
fi

rm -r ${dest_cmip}/${tmp_dir}

}
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (3)' > {{ prefix }}.status
exit 3
fi
60 changes: 0 additions & 60 deletions zppy/templates/ts.bash
Original file line number Diff line number Diff line change
Expand Up @@ -136,66 +136,6 @@ if [ $? != 0 ]; then
exit 3
fi
{%- if ts_fmt != 'ts_only' %}
tmp_dir=tmp_{{ prefix }}
# Generate CMIP ts
cat > default_metadata.json << EOF
{% include cmip_metadata %}
EOF
{
export cmortables_dir={{ cmor_tables_prefix }}/cmip6-cmor-tables/Tables
input_dir={{ output }}/post/{{ component }}/{{ grid }}/ts/{{ frequency }}/{{ '%dyr' % (ypf) }}
dest_cmip={{ output }}/post/{{ component }}/{{ grid }}/cmip_ts/{{ frequency }}
mkdir -p ${dest_cmip}
srun -N 1 e3sm_to_cmip \
--output-path \
${dest_cmip}/${tmp_dir} \
{% if input_files.split(".")[0] == 'clm2' or input_files.split(".")[0] == 'elm' -%}
--var-list \
'mrsos, mrso, mrfso, mrros, mrro, prveg, evspsblveg, evspsblsoi, tran, tsl, lai, cLitter, cProduct, cSoilFast, cSoilMedium, cSoilSlow, fFire, fHarvest, cVeg, nbp, gpp, ra, rh' \
--realm \
lnd \
{% endif -%}
{% if input_files.split(".")[0] == 'cam' or input_files.split(".")[0] == 'eam' -%}
--var-list \
'pr, tas, rsds, rlds, rsus' \
--realm \
atm \
{% endif -%}
--input-path \
${input_dir}\
--user-metadata \
{{ scriptDir }}/${workdir}/default_metadata.json \
--num-proc \
12 \
--tables-path \
${cmortables_dir}
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (4)' > {{ prefix }}.status
exit 4
fi
# Move output ts files to final destination
mv ${dest_cmip}/${tmp_dir}/CMIP6/CMIP/*/*/*/*/*/*/*/*/*.nc ${dest_cmip}
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (5)' > {{ prefix }}.status
exit 5
fi
rm -r ${dest_cmip}/${tmp_dir}
}
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (6)' > {{ prefix }}.status
exit 6
fi
{%- endif %}
# Delete temporary workdir
cd ..
if [[ "${debug,,}" != "true" ]]; then
Expand Down

0 comments on commit 5e73961

Please sign in to comment.