Question on soil moisture conversion
Added by Markus Mingel about 4 years ago
Hi all,
I would convert CMIP6 water content [kg m-2] to soil moisture fraction [m3 m-3]; all I need to do is divide the variable mrsol by the thickness of the layer in [mm]; this latter is retrieved from depth_bnds.
What I usually do is to split the layers and multiply by the thickness (I compute this in advance); I attach a sample file for testing:
cdo -splitlevel mrsol.nc TMP/soilm
- depth_bnds =
- 0, 0.065,
- 0.065, 0.319,
- 0.319, 1.232,
- 1.232, 4.134,
- 4.134, 9.834 ;
- thickness:
- (0.065 - 0) * 1000 = 65 mm
- (0.319 - 0.065) * 1000 = 254 mm
- (1.232 - 0.319) * 1000 = 913 mm
- (4.134 - 1.232) * 1000 = 2902 mm
- (9.834 - 4.134) * 1000 = 5700 mm
cdo -divc,65.0 -setunit,'m3 m-3' TMP/soilm000.03.nc TMP/soilm1.nc
cdo -divc,254.0 -setunit,'m3 m-3' TMP/soilm000.19.nc TMP/soilm2.nc
cdo -divc,913.0 -setunit,'m3 m-3' TMP/soilm000.78.nc TMP/soilm3.nc
cdo -divc,2902.0 -setunit,'m3 m-3' TMP/soilm002.68.nc TMP/soilm4.nc
cdo -divc,5700.0 -setunit,'m3 m-3' TMP/soilm006.98.nc TMP/soilm5.nc
cdo merge TMP/soilm1.nc TMP/soilm2.nc TMP/soilm3.nc TMP/soilm4.nc TMP/soilm5.nc soilm.nc
I wonder if is possible to automatically do that without splitting the levels and computing into advance the thickness of each layer?
Thank you in advance for help!
Markus
Replies (2)
RE: Question on soil moisture conversion - Added by Karin Meier-Fleischer about 4 years ago
Hi Marcus,
as far as I know there is no operator to do it for you, but a short shell script will do it.
#!/usr/bin/env ksh mkdir -p tmp_mrsol cdo -splitlevel mrsol.nc tmp_mrsol/soilm files=$(ls tmp_mrsol/soilm*.nc) for f in $files do dbnds=$(ncdump -v depth_bnds $f | sed -e '1,/depth_bnds =/d' -e '$d' -e 's/ //g' -e 's/,/ /g' -e 's/;//g' | tr -d \\n) set -A bnds $dbnds nbnds=$(echo ${bnds[*]} | wc -w) echo "depth_bnds = ${bnds[*]}" integer i=0, j=0 for ((i=0; i<$nbnds; ++i)) do j=$i+1 a=${bnds[$j]} b=$(echo "scale=10; ${bnds[$i]}*1.0" | bc -l) thick=$(echo "scale=10; ($a-$b)*1000" | bc -l) echo "($i,$j): a = $a b = $b (a - b) = $thick" i=$i+1 done cdo -divc,$thick -setunit,'m3 m-3' $f tmp_mrsol/tmp_${f##*/}.nc done cdo -O merge tmp_mrsol/tmp_soilm*.nc soilm.nc
To compare input file and computed output file:
cdo infon mrsol.nc -1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name 1 : 1975-01-01 06:00:00 0.03 73728 48857 : 0.0000 8.0742 49.707 : mrsol 2 : 1975-01-01 06:00:00 0.19 73728 48857 : 0.0000 34.425 196.41 : mrsol 3 : 1975-01-01 06:00:00 0.78 73728 48857 : 0.0000 105.50 754.97 : mrsol 4 : 1975-01-01 06:00:00 2.68 73728 48857 : 0.0000 185.63 2527.5 : mrsol 5 : 1975-01-01 06:00:00 6.98 73728 48857 : 0.0000 72.640 2650.5 : mrsol
cdo infon soilm.nc -1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name 1 : 1975-01-01 06:00:00 0.03 73728 48857 : 0.0000 0.12422 0.76473 : mrsol 2 : 1975-01-01 06:00:00 0.19 73728 48857 : 0.0000 0.13553 0.77329 : mrsol 3 : 1975-01-01 06:00:00 0.78 73728 48857 : 0.0000 0.11555 0.82692 : mrsol 4 : 1975-01-01 06:00:00 2.68 73728 48857 : 0.0000 0.063967 0.87096 : mrsol 5 : 1975-01-01 06:00:00 6.98 73728 48857 : 0.0000 0.012744 0.46500 : mrsol
-Karin
RE: Question on soil moisture conversion - Added by Markus Mingel about 4 years ago
Hi Karin,
thanks a lot, it works perfectly.
Markus