diff --git a/cmor/mpiesm/scripts/calc_bounds_mpism.sh b/cmor/mpiesm/scripts/calc_bounds_mpism.sh new file mode 100644 index 0000000000000000000000000000000000000000..8b6bd5d71e9d20abd4d56d3aa9043025e9527b15 --- /dev/null +++ b/cmor/mpiesm/scripts/calc_bounds_mpism.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# +# Correct vertical axis for mPISM +# - in this case used to create +# gridinfo file serving as input +# for cdo cmor +# + +ifile=/work/bm0021/PalMod2/cmor/mpiesm/scripts/gridinfo_mPISM_L121.nc_source +ofile=/work/bm0021/PalMod2/cmor/mpiesm/scripts/gridinfo_mPISM_L121.nc + +function ncattget { ncks --trd -M -m ${3} | grep -E -i "^${2} attribute [0-9]+: ${1}" | cut -f 11- -d ' ' | sort ; } + + + +bnds_0="" +bnds_1="" +lev_val="" + +levs=$(ncks --trd -m -M $ifile | grep -E -i ": lev, size =" | cut -f 7 -d ' ' | uniq ;) +[[ ! -z "$levs" ]] && [[ $levs -eq 121 ]] && { [[ -z "$bnds_1" ]] || [[ -z "$bnds_0" ]]; } && { + lev=( $(ncks -s "%.2f " -Q -H -v lev $ifile | cut -d$'\n' -f1 ) 6050.00 ) + bnd_i=0 + echo Level interfaces read: ${lev[@]} + for i in ${lev[@]}; do + if [[ $bnd_i -eq 121 ]]; then continue; fi + if [[ $bnd_i -eq 0 ]]; then + #indp1=$((bnd_i+1)) + lev_val=$( awk "BEGIN { a = ${lev[$bnd_i]}; b = ${lev[$((bnd_i+1))]}; print (a+b)/2. }" ) + bnds_0=${lev[$bnd_i]} + bnds_1=${lev[$((bnd_i+1))]} + else + lev_val=${lev_val},$( awk "BEGIN { a = ${lev[$bnd_i]}; b = ${lev[$((bnd_i+1))]}; print (a+b)/2. }" ) + bnds_0=${bnds_0},${lev[$bnd_i]} + bnds_1=${bnds_1},${lev[$((bnd_i+1))]} + fi + bnd_i=$((bnd_i+1)) + done + echo "Layer midpoints[:]:" $lev_val + echo "Bounds[:,1]:" $bnds_0 + echo "Bounds[:,2]:" $bnds_1 +} +#exit 0 + +add_bounds() { + if [[ -z "$bnds_1" ]] || [[ -z "$bnds_0" ]]; then echo "ERROR: No bounds specified"; exit 0; fi + if [[ -z "$lev_val" ]]; then echo "ERROR: No layer midpoints specified"; exit 0; fi + echo + echo "---------------------------------------------------" + echo "$ifile" + echo "Setting lev and lev_bnds ..." + ncap2 -A -h -s "lev(:)={$lev_val};lev_bnds(:,0)={$bnds_0};lev_bnds(:,1)={$bnds_1};" $ifile $ofile && echo "Successful." || { echo "ERROR: Setting lev and lev_bnds failed!" && exit 0; } + echo + echo "Set the following lev_bnds:" + ncdump -v lev_bnds $ofile | grep -v "}" | grep -A 1000 "lev\_bnds =" + echo "Set the following lev:" + ncdump -v lev $ofile | grep -v "lev = 121" | grep -v "}" | grep -A 1000 "lev =" +} + +add_bounds + + +#ncap2 -A -h -s "depth_bnds(:,0)={$bnds_0};depth_bnds(:,1)={$bnds_1};" mrsol.nc mrsol.nc + + +#ncap2 -O -s "defdim(\"bnds\",2);depth_bnds[depth,bnds]=0.;depth_bnds(:,0)={$bnds_0};depth_bnds(:,1)={$bnds_1};" Emon_mrsol_2015.nc b.nc +#ncatted -O -a bounds,depth,c,c,"depth_bnds" b.nc +#/work/bm0021/cdo_incl_cmor/cdo_2019-07-01_cmor3_gcc/src/cdo cmor,Emon,i=cdocmorinfo,mt=ssp126_r1i1p1f1-HR/scripts/tables/MPI-ESM1-2-MiKlip_jsbach_CMIP6_mapping.txt,dr=./,vd=v20190710,cn=mrsol b.nc + + +#ncap2 -O -s "defdim(\"bnds\",2);depth_bnds[depth,bnds]=0.;depth_bnds(:,0)={$bnds_0};depth_bnds(:,1)={$bnds_1};" Emon_mrsol_2015.nc b.nc +#ncatted -O -a bounds,depth,c,c,"depth_bnds" b.nc +#/work/bm0021/cdo_incl_cmor/cdo_2019-07-01_cmor3_gcc/src/cdo cmor,Emon,i=cdocmorinfo,mt=ssp126_r1i1p1f1-HR/scripts/tables/MPI-ESM1-2-MiKlip_jsbach_CMIP6_mapping.txt,dr=./,vd=v20190710,cn=mrsol b.nc diff --git a/cmor/mpiesm/scripts/calc_nominal_resolution.py b/cmor/mpiesm/scripts/calc_nominal_resolution.py new file mode 100644 index 0000000000000000000000000000000000000000..cc6328a7fbcfac1dfc91dbae395f7ad3fd083a00 --- /dev/null +++ b/cmor/mpiesm/scripts/calc_nominal_resolution.py @@ -0,0 +1,16 @@ +### Set up conda environment +# module load python3 +# mamba create --prefix /work/bm0021/conda-envs-public/nominal_resolution -c pcmdi nominal_resolution xarray netCDF4 +### Load conda environment +# source activate /work/bm0021/conda-envs-public/nominal_resolution +### Calculate cell area +# cdo gridarea in.nc out.nc +### Calculate nominal resolution +import nominal_resolution, xarray +ds=xarray.open_dataset("out.nc") +a=nominal_resolution.mean_resolution(ds.cell_area.values.ravel(), ds.latitude_bnds.values.ravel().reshape((160000,4)), ds.longitude_bnds.values.ravel().reshape((160000,4)), convertdeg2rad=True, returnMaxDistance=False) +#>>> a +#20.951768033878334 +nominal_resolution.nominal_resolution(a) +#'25 km' +a=nominal_resolution.mean_resolution(ds.cell_area.values.ravel(), ds.latitude_bnds.values.ravel().reshape((160000,4)), ds.longitude_bnds.values.ravel().reshape((160000,4)), convertdeg2rad=True, returnMaxDistance=True) diff --git a/cmor/mpiesm/scripts/cdocmorinfo_mpism_CR b/cmor/mpiesm/scripts/cdocmorinfo_mpism_CR new file mode 100644 index 0000000000000000000000000000000000000000..2fe30f88c614e8364a1dea681eb517991ac8e5fa --- /dev/null +++ b/cmor/mpiesm/scripts/cdocmorinfo_mpism_CR @@ -0,0 +1,8 @@ +#NOMINAL_RESOLUTION read from external file +#For ice (mPISM) +CALENDAR="365day" +NOMINAL_RESOLUTION="25 km" +#Level/Depth Bounds +grid_info="/work/bm0021/PalMod2/cmor/mpiesm/scripts/gridinfo_mPISM_L121.nc" +switch_z=y +switch_xy=n diff --git a/cmor/mpiesm/scripts/gridinfo_mPISM_L121.nc b/cmor/mpiesm/scripts/gridinfo_mPISM_L121.nc new file mode 100644 index 0000000000000000000000000000000000000000..d6aa950cc8baf657a709a745503a1907e600cd6f Binary files /dev/null and b/cmor/mpiesm/scripts/gridinfo_mPISM_L121.nc differ diff --git a/cmor_tables/PalMod2_IdecAnt.json b/cmor_tables/PalMod2_IdecAnt.json index 25739a79fda59f7762d861f826f53af04e226e6d..10b6ac08099e10734b4e050945f1e4bfbe7140c3 100644 --- a/cmor_tables/PalMod2_IdecAnt.json +++ b/cmor_tables/PalMod2_IdecAnt.json @@ -9,7 +9,7 @@ "int_missing_value": "-999", "product": "model-output", "approx_interval": "3650.00000", - "generic_levels": "", + "generic_levels": "alevel", "Conventions": "CF-1.7 PalMod-2.0" }, "variable_entry": { @@ -94,7 +94,7 @@ "cell_measures": "area: areacellg", "long_name": "Temperature of Land Ice", "comment": "Land ice means glaciers, ice-caps and ice-sheets resting on bedrock and also includes ice-shelves.", - "dimensions": "longitude latitude isdepth time", + "dimensions": "longitude latitude alevel time", "out_name": "tlIs", "type": "real", "positive": "", diff --git a/cmor_tables/PalMod2_IdecGre.json b/cmor_tables/PalMod2_IdecGre.json index 476e40efd2a1a4cdf89d4eba5809cf73b46ee0b6..638549c27407ba32ebc22a05c1dd1454d7c3a89a 100644 --- a/cmor_tables/PalMod2_IdecGre.json +++ b/cmor_tables/PalMod2_IdecGre.json @@ -9,7 +9,7 @@ "int_missing_value": "-999", "product": "model-output", "approx_interval": "3650.00000", - "generic_levels": "", + "generic_levels": "alevel", "Conventions": "CF-1.7 PalMod-2.0" }, "variable_entry": { @@ -94,7 +94,7 @@ "cell_measures": "area: areacellg", "long_name": "Temperature of Land Ice", "comment": "Land ice means glaciers, ice-caps and ice-sheets resting on bedrock and also includes ice-shelves.", - "dimensions": "longitude latitude isdepth time", + "dimensions": "longitude latitude alevel time", "out_name": "tlIs", "type": "real", "positive": "", diff --git a/cmor_tables/PalMod2_coordinate.json b/cmor_tables/PalMod2_coordinate.json index 668050cb8466e55e630dabcbe9f59de22df9fccf..0d057413250bb8e26d1a2b473ea6b510bed480b3 100644 --- a/cmor_tables/PalMod2_coordinate.json +++ b/cmor_tables/PalMod2_coordinate.json @@ -700,6 +700,29 @@ "bounds_values": "", "generic_level_name": "" }, + "height_coord": { + "standard_name": "height", + "units": "m", + "axis": "Z", + "long_name": "Z-coordinate in Cartesian system", + "climatology": "", + "formula": "", + "must_have_bounds": "yes", + "out_name": "lev", + "positive": "up", + "requested": "", + "requested_bounds": "", + "stored_direction": "increasing", + "tolerance": "", + "type": "double", + "valid_max": "", + "valid_min": "", + "value": "", + "z_bounds_factors": "", + "z_factors": "", + "bounds_values": "", + "generic_level_name": "alevel" + }, "hybrid_height": { "standard_name": "atmosphere_hybrid_height_coordinate", "units": "m", @@ -769,29 +792,6 @@ "bounds_values": "", "generic_level_name": "" }, - "isdepth": { - "standard_name": "depth", - "units": "m", - "axis": "Z", - "long_name": "depth", - "climatology": "", - "formula": "", - "must_have_bounds": "yes", - "out_name": "depth", - "positive": "down", - "requested": "", - "requested_bounds": "", - "stored_direction": "increasing", - "tolerance": "", - "type": "double", - "valid_max": "200.0", - "valid_min": "0.0", - "value": "", - "z_bounds_factors": "", - "z_factors": "", - "bounds_values": "", - "generic_level_name": "" - }, "lambda550nm": { "standard_name": "radiation_wavelength", "units": "nm",