Goal: adapt bash script to python application
For variables where reconstructions are not available, the following have presented a good result applying distance weighted average interpolation, therefore being good candidates for nearest neighbour interpolation in python or creepfill.
interp_vars =[al, cnhk,i stl1, istl2, istl3, istl4, licd, lict, lmld, lmlt, lshf, ltlt, alnid, alnip, ci, src, skt, asn, rsn, slt1, slt2, slt3, slt4, tsn, aluvd, aluvp, lblt]
variables lsrh and sr have minimum and maximum as 0, therefore no change should applied.
the bash script where cdo commands were implemented to create masks for the interpolation:
make_masks.sh
#!/bin/sh
lp_path=/Documents/phd/data/pliomip3/LP/
input_mask_path=${lp_path}/input_masks
#making sure that missing value in the PRISM4D data is not 0
cdo -setmissval,-99999 ../LP_LSM_v1.0.nc lp.lsm.nc
cdo -setmissval,-99999 ../LP_icemask_v1.0.nc lp.ice.nc
#interpolating PRISM4 lsm to OpenIFS grid
cdo griddes ../ICMGGaackINIT > ../grid_icmgg.txt
cdo -f grb -copy -int -setgrid,../ICMGGaackINIT -remapdis,../grid_icmgg.txt lp.lsm.nc lp.lsm.rmp.grb
cdo -f grb -copy -int -setgrid,../ICMGGaackINIT -remapdis,../grid_icmgg.txt lp.ice.nc lp.ice.rmp.grb
#creating the mask where ocean is 1 and land is nan
cdo -setctomiss,2 -addc,1 lp.lsm.rmp.grb oce1.mask.grb
#creating the mask where land is 1 and ocean is nan
cdo -setctomiss,0 lp.lsm.rmp.grb land1.mask.grb
#saving openIFS land-sea and ice sheet masks
cdo -setmissval,-99999 -selcode,172 ../ICMGGaackINIT oifs.lsm.grb
cdo -setmissval,-99999 -selcode,141 ../ICMGGaackINIT oifs.ice.grb
#creating anomaly of the land sea mask
cdo -setrtoc,0.5,1,1 -setrtoc,0,0.5,0 oifs.lsm.grb oifs.lsm.mask.grb
cdo sub lp.lsm.rmp.grb oifs.lsm.mask.grb lsm.anom.grb
#creating added, drowned, gis and wais masks
cdo -setctomiss,2 -addc,1 -setrtoc,-1,0,0 lsm.anom.grb lsm.added.miss.grb
cdo -setctomiss,2 -addc,1 -setrtoc,-1,0,0 -mulc,-1 lsm.anom.grb lsm.drowned.miss.grb
#creating mask where the icesheet is reduced
cdo sub lp.ice.rmp.grb oifs.ice.grb icesheet.anom.grb
cdo setrtomiss,1.1,3 -addc,1 -lec,-9 -setmisstoc,0 icesheet.anom.grb lsm.reduced.icesheet.grb
and to change each variable according to the method:
change_icmgg_vars.sh
#!/bin/bash
# Extract all unique codes from the ICMGG files
codes=$(cdo showcode ../ICMGGaackINIT)
# Loop through each unique code
for code in $codes; do
# Saving openIFS land-sea and ice sheet masks
cdo -setmissval,-99999 -selcode,${code} ../ICMGGaackINIT oifs.var${code}.grb
# Interpolating drowned points
cdo -ifthen oce1.mask.grb oifs.var${code}.grb var${code}.oce.grb
cdo -setmisstodis,50 -mul var${code}.oce.grb lsm.drowned.miss.grb var${code}.oce.drowned.dwa.grb
cdo -setmisstoc,0 -ifthen oce1.mask.grb var${code}.oce.drowned.dwa.grb var${code}.oce.drowned.dwa.oce.grb
# Interpolating added and ice sheet points
cdo -ifthen land1.mask.grb oifs.var${code}.grb var${code}.land.grb
cdo -setmisstodis,50 -mul var${code}.land.grb lsm.added.miss.grb var${code}.land.added.grb
cdo -setmisstodis,50 -mul var${code}.land.added.grb lsm.reduced.icesheet.grb var${code}.land.added.is.grb
cdo -setmisstoc,0 -ifthen land1.mask.grb var${code}.land.added.is.grb var${code}.land.added.is.dwa.land.grb
# Adding both fields
cdo add var${code}.oce.drowned.dwa.oce.grb var${code}.land.added.is.dwa.land.grb var${code}.plio.grb
done
cdo merge var*.plio.grb oifs.plio.init.grb
cdo -addc,1 -mulc,0 ../ICMGGaackINIT icmgg_ones
cdo replace ../ICMGGaackINIT oifs.plio.init.grb ICMGGaackINIT_plio_variables
cdo mul ICMGGackINIT_plio_variables icmgg_ones ICMGGaackINIT_plio_variables_corrected
rm *var*.grb
DWA_NN_remap.pdf
Goal: adapt bash script to python application
For variables where reconstructions are not available, the following have presented a good result applying distance weighted average interpolation, therefore being good candidates for nearest neighbour interpolation in python or creepfill.
variables
lsrhandsrhave minimum and maximum as 0, therefore no change should applied.the bash script where cdo commands were implemented to create masks for the interpolation:
make_masks.shand to change each variable according to the method:
change_icmgg_vars.shDWA_NN_remap.pdf