From 4c6834dbc47671ffe97999a55d20c7ccd6a4955e Mon Sep 17 00:00:00 2001
From: Martin Schupfner <k204212@levante0.lvt.dkrz.de>
Date: Wed, 18 Jan 2023 15:36:06 +0100
Subject: [PATCH] Updated mpiesm scripts and config for methane experiments

- conf: fixed problem and typos for fx variables
- mpiom: reworked the fx variable processing for all workflow steps
- runpp / cmor_ctl / test*: added additional offset parameter for initial year
- ssp119 cdocmorinfo: updated parent attributes
---
 .../conf/PalMod2_requested_vars_AllExpTK.conf |  8 +++++--
 .../palmod2_aggregation_MPI-ESM1-2_mpiom.h    | 16 +++++++------
 ...lmod2_cmor-rewrite_MPI-ESM1-2_mpiom_auto.h |  4 ++--
 ...palmod2_diagnostic_MPI-ESM1-2_mpiom_auto.h |  2 +-
 .../ssp119-future-methane_r1i1p1f1-CR.runpp   |  5 ++--
 ...119-future-methane_r1i1p1f1-CR_cdocmorinfo | 10 ++------
 cmor/mpiesm/scripts/test_methane              | 22 +++++++++---------
 ...cribed-glac1d-methane_r1i1p1f1-CR.cmor_ctl | 22 +++++++++---------
 ...rescribed-glac1d-methane_r1i1p1f1-CR.runpp | 23 +++++++++++--------
 9 files changed, 58 insertions(+), 54 deletions(-)

diff --git a/cmor/mpiesm/scripts/conf/PalMod2_requested_vars_AllExpTK.conf b/cmor/mpiesm/scripts/conf/PalMod2_requested_vars_AllExpTK.conf
index 07fcb8a..22267e0 100755
--- a/cmor/mpiesm/scripts/conf/PalMod2_requested_vars_AllExpTK.conf
+++ b/cmor/mpiesm/scripts/conf/PalMod2_requested_vars_AllExpTK.conf
@@ -37,7 +37,11 @@ echammonplev19  : interpolation = True
 echammonafter   : afterburner   = True
 jsbachdecfx     : input         = True
 echamdecfx      : input         = True
-mpiom           : gridfile      = False # basin file does not exist for GR30
+mpiom           : basin         = False # basin file does not exist for GR30
+mpiom           : basin         = slice: first_step
+mpiom           : gridfile      = True
+mpiom           : gridfile      = slice: first_step
+mpiom           : fx            = True
 Omon            : areacello     = True
 Ofx             : areacello     = True
 ################
@@ -66,6 +70,6 @@ SImon           : sithick       = False # variable missing in mpiom_data_2d_mm s
 # Land
 #################
 Lmon            : rivo          = False # no hd_higres_mon stream
-fx              : areacellar    = False # no hd_higres_mon stream
+fx              : areacellr     = False # no hd_higres_mon stream
 #Emon            : herbivoreCH4  = False # variable missing for SSP* experiments
 #<---- Specify your settings for Experiment AllExp here
diff --git a/cmor/mpiesm/scripts/palmod2_aggregation_MPI-ESM1-2_mpiom.h b/cmor/mpiesm/scripts/palmod2_aggregation_MPI-ESM1-2_mpiom.h
index 86ad909..6f8e730 100644
--- a/cmor/mpiesm/scripts/palmod2_aggregation_MPI-ESM1-2_mpiom.h
+++ b/cmor/mpiesm/scripts/palmod2_aggregation_MPI-ESM1-2_mpiom.h
@@ -2,7 +2,15 @@
 # MPIOM ########################
 ################################
 
-#--mpiom: fx
+#--mpiom: fx and masks
+{ ( { if_requested $member $ocemod mpiom fx $chunk || if_requested $member $ocemod mpiom gridfile $chunk ; } || continue
+    find_file "$rawsdir" "*_mpiom_fx_*" ifile
+    ln -sf $ifile $sdir/mpiom_fx.nc || echo ERROR fx file
+    # In case these land-sea-masks change with time, this needs an update...
+    $cdo selname,amsuo,amsue $ifile $sdir/grid_mpiom_fx.nc || echo ERROR grid file
+)&; }>>$err.mpiom.fx 2>&1
+
+#--mpiom: basin
 #{ ( if [[ ! -s $sdir/${RAW_EXP_IDS[$y]}_mpiom_basin.nc ]]; then
 #  cp /pool/data/MPIOM/input/r0010/GR30/GR30_basin.nc $sdir/${RAW_EXP_IDS[$y]}_mpiom_basin.nc || echo ERROR
 #else
@@ -33,12 +41,6 @@
   $cdo selname,global_moc,atlantic_moc,indopacific_moc ${cdochain-} $ifile ${sdir}/out_aggr/msftmz_Omon_$period.nc || echo ERROR
 )&; }>>$err.msftmz.Omon 2>&1
 
-#--mpiom: fx
-# In case these land-sea-masks change with time, this needs an update...
-{ (if_requested $member $ocemod mpiom gridfile $chunk || continue
-  $cdo selname,amsuo,amsue $sdir/${RAW_EXP_IDS[$y]}_${ocemod}_fx_${period}*.nc $sdir/grid_mpiom_fx.nc || echo ERROR
-)&; }>>$err.mpiom.gridfile 2>&1
-
 # sftof
 { ( { if_requested $member $ocemod Odec sftof $chunk || if_requested $member $ocemod Ofx sftof $chunk ; } || continue
   find_file "$sdir" "*_mpiom_data_2d_mm_${period}*.nc" ifile >> $err.find_file.Odec 2>&1
diff --git a/cmor/mpiesm/scripts/palmod2_cmor-rewrite_MPI-ESM1-2_mpiom_auto.h b/cmor/mpiesm/scripts/palmod2_cmor-rewrite_MPI-ESM1-2_mpiom_auto.h
index ce06818..be62a6d 100644
--- a/cmor/mpiesm/scripts/palmod2_cmor-rewrite_MPI-ESM1-2_mpiom_auto.h
+++ b/cmor/mpiesm/scripts/palmod2_cmor-rewrite_MPI-ESM1-2_mpiom_auto.h
@@ -44,7 +44,7 @@ done
 
 #-- CMOR-rewrite for mpiom (ESM: MPI-ESM1-2) Ofx
 cn='thkcello'
-find_file "$sdir" "*_mpiom_data_3d_mm_${period}*.nc" ifile >> $err.find_file.Ofx 2>&1
+find_file "$sdir" "mpiom_fx.nc" ifile >> $err.find_file.Ofx 2>&1
 for var in $cn; do
   { (if_requested $member $ocemod Ofx $var $chunk || continue
   mkdir -p $dr/$submodel/Ofx_${var}
@@ -55,7 +55,7 @@ done
 
 #-- CMOR-rewrite for mpiom (ESM: MPI-ESM1-2) Ofx
 cn='deptho'
-find_file "$sdir" "*_mpiom_fx_${period}*" ifile >> $err.find_file.Ofx 2>&1
+find_file "$sdir" "mpiom_fx.nc" ifile >> $err.find_file.Ofx 2>&1
 for var in $cn; do
   { (if_requested $member $ocemod Ofx $var $chunk || continue
   mkdir -p $dr/$submodel/Ofx_${var}
diff --git a/cmor/mpiesm/scripts/palmod2_diagnostic_MPI-ESM1-2_mpiom_auto.h b/cmor/mpiesm/scripts/palmod2_diagnostic_MPI-ESM1-2_mpiom_auto.h
index 666b41f..e0a1fc7 100644
--- a/cmor/mpiesm/scripts/palmod2_diagnostic_MPI-ESM1-2_mpiom_auto.h
+++ b/cmor/mpiesm/scripts/palmod2_diagnostic_MPI-ESM1-2_mpiom_auto.h
@@ -11,7 +11,7 @@
 #-- Diagnostic for mpiom (ESM: MPI-ESM1-2) variable volcello / table Ofx
 # Editor Note: codes:87,197
 { (if_requested $member $ocemod Ofx volcello $chunk && {
-  find_file -e            "$sdir" "*_mpiom_data_3d_mm_${period}*.nc" ifile1
+  find_file -e            "$sdir" "mpiom_fx.nc" ifile1
   find_file -e            "$sdir" "Ofx_areacello.nc" ifile2
   $cdo -f nc -O \
     expr,'volcello=areacello*thkcello;' \
diff --git a/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR.runpp b/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR.runpp
index 5e117a3..ee5adc8 100755
--- a/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR.runpp
+++ b/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR.runpp
@@ -45,7 +45,7 @@ alias ncatted=/sw/spack-levante/nco-5.0.6-3xkdth/bin/ncatted
 #Root directory of all scripts, outdata, logs etc
 EXP_ID=ssp119-future-methane_r1i1p1f1-CR
 EXP_DIR_TRUNK=/work/kd1292/k204212/palmod_TK/ssp119-future-methane_r1i1p1f1-CR
-EXP_DIR_TRUNK=/work/bk1192/k204212/palmod_TK/test_ssp119-future-methane_r1i1p1f1-CR
+#EXP_DIR_TRUNK=/work/bk1192/k204212/palmod_TK/ssp119-future-methane_r1i1p1f1-CR
 
 #initial files for aggregation
 INPUT_DIR_TRUNK=/work/bm1030/from_Mistral/bm1030/m300020/mpiesm-palmod_tk_r10186_megan_next/experiments
@@ -111,6 +111,7 @@ srfmod_dec_chunk="???9123124"
 srfmod_input_dec_chunk="???0123124"
 ocemod_dec_chunk="???0123124"
 icemod_dec_chunk="???0123124"
+ocemod_fxyear=5900
 
 #InfoTable(s)
 # Define here the "cdocmorinfo"-File or "eum"-Files
@@ -135,7 +136,7 @@ errdir_diag=${errdir}_diag
 errdir_agg=${errdir}_agg
 
 #initial and final year of the experiment
-iniyeararr=($((5600+spinup))) # 1850-3049, after the 300y spinup
+iniyeararr=($((5900+spinup))) # 1850-3049, after the 300y spinup
 finyeararr=(7099)
 iniyear=1850
 finyear=3049
diff --git a/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR_cdocmorinfo b/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR_cdocmorinfo
index 71d5da2..3fdc2ac 100644
--- a/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR_cdocmorinfo
+++ b/cmor/mpiesm/scripts/ssp119-future-methane_r1i1p1f1-CR_cdocmorinfo
@@ -27,20 +27,14 @@ REQUIRED_TIME_UNITS="days since 1-1-1 00:00:00"
 #  else use BRANCH_DATES to give the dates in YYYYMMDD,YYYYMMDD format
 #BRANCH_TIME_IN_PARENT=
 #BRANCH_TIME_IN_CHILD=
-#
-# todo: set BRANCH_DATES
-#
-BRANCH_DATES=238010101,18500101
+BRANCH_DATES=248010101,18500101
 BRANCH_METHOD="standard"
 #PARENT_MIP_ERA=none              #ONLY CMIP6
 PARENT_ACTIVITY_ID=PalMod2
-PARENT_EXPERIMENT="transient deglaciation with GLAC-1D ice sheets, methane preliminary"
+PARENT_EXPERIMENT="transient deglaciation with GLAC-1D ice sheets, with methane cycle"
 PARENT_EXPERIMENT_ID=transient-deglaciation-prescribed-glac1d-methane
 PARENT_SOURCE_ID=MPI-ESM1-2-CR-CH4
 PARENT_TIME_UNITS="days since 1-1-1 00:00:00"
-#
-# todo: set PARENT_VARIANT_LABEL
-#
 PARENT_VARIANT_LABEL=r1i1p1f1
 SUB_EXPERIMENT_ID=none
 SUB_EXPERIMENT=none
diff --git a/cmor/mpiesm/scripts/test_methane b/cmor/mpiesm/scripts/test_methane
index 5633856..602c8cf 100755
--- a/cmor/mpiesm/scripts/test_methane
+++ b/cmor/mpiesm/scripts/test_methane
@@ -10,19 +10,19 @@
 n_subsim=4
 #initial and final year of the experiment
 spinup=1000
-iniyeararr=( $(( 3000 + spinup )) 2000 2000 2000 )
-finyeararr=( 8999 8999 8999 5999 )
-iniyear=$(( 1 + spinup ))
-finyear=24000
+iniyeararr=($((3000+spinup)) 2000 2000 2000)
+finyeararr=(8999 8999 8999 5999)
+iniyearoffset=2000 # offset by 2000 years so time axis is comparable to MK's transient-glaciation experiments
+iniyear=$(( $iniyearoffset + 1 ))
+finyear=$(( 24000 + $iniyearoffset - $spinup ))
 #offset compared to startyear
-inioffsetarr=(-2999 4001 11001 18001)
-
+inioffsetarr=( $(( -2999 + $iniyearoffset )) $(( 4001 + $iniyearoffset )) $(( 11001 + $iniyearoffset )) $(( 18001 + $iniyearoffset )) ) # 24000-1 BP
 # Time axis (24000-1 BP)
-##     exp time       total yrs   new exp time   offset
-#a - 24000-18001 BP - 6000 yrs -     1- 6000 -   - 2999
-#b - 18000-11001 BP - 7000 yrs -  6001-13000 -     4001
-#c - 11000- 4001 BP - 7000 yrs - 13001-20000 -    11001
-#d -  4000-    1 BP - 4000 yrs - 20001-24000 -    18001
+##     exp time       total yrs   new exp time   offset    with iniyearoffset     with iniyearoffset and spinup
+#a - 24000-18001 BP - 6000 yrs -     1- 6000 -   - 2999       2001 -  8000          2001 -  7000
+#b - 18000-11001 BP - 7000 yrs -  6001-13000 -     4001       8001 - 15000          7001 - 14000
+#c - 11000- 4001 BP - 7000 yrs - 13001-20000 -    11001      15001 - 22000         14001 - 21000
+#d -  4000-    1 BP - 4000 yrs - 20001-24000 -    18001      22001 - 26000         21001 - 25000
 
 # Chunksize
 #  Note that there are prerequisites concerning the chunksize:
diff --git a/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.cmor_ctl b/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.cmor_ctl
index 10e3646..ca76611 100755
--- a/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.cmor_ctl
+++ b/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.cmor_ctl
@@ -10,19 +10,19 @@
 n_subsim=4
 #initial and final year of the experiment
 spinup=1000
-iniyeararr=( $(( 3000 + spinup )) 2000 2000 2000 )
-finyeararr=( 8999 8999 8999 5999 )
-iniyear=$(( 1 + spinup ))
-finyear=24000
+iniyeararr=($((3000+spinup)) 2000 2000 2000)
+finyeararr=(8999 8999 8999 5999)
+iniyearoffset=2000 # offset by 2000 years so time axis is comparable to MK's transient-glaciation experiments
+iniyear=$(( $iniyearoffset + 1 ))
+finyear=$(( 24000 + $iniyearoffset - $spinup ))
 #offset compared to startyear
-inioffsetarr=(-2999 4001 11001 18001)
-
+inioffsetarr=( $(( -2999 + $iniyearoffset )) $(( 4001 + $iniyearoffset )) $(( 11001 + $iniyearoffset )) $(( 18001 + $iniyearoffset )) ) # 24000-1 BP
 # Time axis (24000-1 BP)
-##     exp time       total yrs   new exp time   offset
-#a - 24000-18001 BP - 6000 yrs -     1- 6000 -   - 2999
-#b - 18000-11001 BP - 7000 yrs -  6001-13000 -     4001
-#c - 11000- 4001 BP - 7000 yrs - 13001-20000 -    11001
-#d -  4000-    1 BP - 4000 yrs - 20001-24000 -    18001
+##     exp time       total yrs   new exp time   offset    with iniyearoffset     with iniyearoffset and spinup
+#a - 24000-18001 BP - 6000 yrs -     1- 6000 -   - 2999       2001 -  8000          2001 -  7000
+#b - 18000-11001 BP - 7000 yrs -  6001-13000 -     4001       8001 - 15000          7001 - 14000
+#c - 11000- 4001 BP - 7000 yrs - 13001-20000 -    11001      15001 - 22000         14001 - 21000
+#d -  4000-    1 BP - 4000 yrs - 20001-24000 -    18001      22001 - 26000         21001 - 25000
 
 # Chunksize
 #  Note that there are prerequisites concerning the chunksize:
diff --git a/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.runpp b/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.runpp
index 9c212c5..18425fc 100755
--- a/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.runpp
+++ b/cmor/mpiesm/scripts/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR.runpp
@@ -44,8 +44,8 @@ alias ncatted=/sw/spack-levante/nco-5.0.6-3xkdth/bin/ncatted
 
 #Root directory of all scripts, outdata, logs etc
 EXP_ID=transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR
-#EXP_DIR_TRUNK=/work/kd1292/k204212/palmod_TK/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR
-EXP_DIR_TRUNK=/work/bk1192/k204212/palmod_TK/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR
+EXP_DIR_TRUNK=/work/kd1292/k204212/palmod_TK/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR
+#EXP_DIR_TRUNK=/work/bk1192/k204212/palmod_TK/transient-deglaciation-prescribed-glac1d-methane_r1i1p1f1-CR
 
 #initial files for aggregation
 INPUT_DIR_TRUNK=/work/bk1192/WG2/WP2.3/transient_deglaciation_2022/
@@ -109,6 +109,7 @@ srfmod_dec_chunk="???0123124"
 srfmod_input_dec_chunk="???1123124"
 ocemod_dec_chunk="???1123124"
 icemod_dec_chunk="???1123124"
+ocemod_fxyear=3000
 
 #InfoTable(s)
 # Define here the "cdocmorinfo"-File or "eum"-Files
@@ -135,16 +136,17 @@ errdir_agg=${errdir}_agg
 #initial and final year of the experiment
 iniyeararr=($((3000+spinup)) 2000 2000 2000) # 24000-1 BP
 finyeararr=(8999 8999 8999 5999)
-iniyear=1
-finyear=$(( 24000 - $spinup ))
+iniyearoffset=2000 # offset by 2000 years so time axis is comparable to MK's transient-glaciation experiments
+iniyear=$(( $iniyearoffset + 1 ))
+finyear=$(( 24000 + $iniyearoffset - $spinup ))
 #offset compared to startyear
-inioffsetarr=(-2999 4001 11001 18001) # 24000-1 BP
+inioffsetarr=( $(( -2999 + $iniyearoffset )) $(( 4001 + $iniyearoffset )) $(( 11001 + $iniyearoffset )) $(( 18001 + $iniyearoffset )) ) # 24000-1 BP
 # Time axis (24000-1 BP)
-##     exp time       total yrs   new exp time   offset
-#a - 24000-18001 BP - 6000 yrs -     1- 6000 -   - 2999
-#b - 18000-11001 BP - 7000 yrs -  6001-13000 -     4001
-#c - 11000- 4001 BP - 7000 yrs - 13001-20000 -    11001
-#d -  4000-    1 BP - 4000 yrs - 20001-24000 -    18001
+##     exp time       total yrs   new exp time   offset    with iniyearoffset     with iniyearoffset and spinup
+#a - 24000-18001 BP - 6000 yrs -     1- 6000 -   - 2999       2001 -  8000          2001 -  7000
+#b - 18000-11001 BP - 7000 yrs -  6001-13000 -     4001       8001 - 15000          7001 - 14000
+#c - 11000- 4001 BP - 7000 yrs - 13001-20000 -    11001      15001 - 22000         14001 - 21000
+#d -  4000-    1 BP - 4000 yrs - 20001-24000 -    18001      22001 - 26000         21001 - 25000
 
 # /work/bk1192/WG2/WP2.3/transient_deglaciation_2020 contains a transient deglaciation experiment,
 # from 24900 yrs BP to 0 BP (present = 1950CE). For technical reasons it is split into 4 parts:
@@ -384,6 +386,7 @@ function run_agg
             mkdir -p ${sdir}/out_aggr
 
             # Create softlinks to raw model output
+            echo "... creating links from '$rawsdir' for $period, $submodel"
             ln -sf $rawsdir/*_${period}* $sdir/ 2>/dev/null 1>&2 || { echo "ERROR creating links for $period ${RAW_EXP_IDS[$y]} $submodel" && exit 1 ; }
 
             # Load and run the aggr ScriptFragment
-- 
GitLab