-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCM_remap.sh
76 lines (66 loc) · 2.6 KB
/
GCM_remap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# This script has been used to interpolate CMPI5 and CMIP6 monthly output from the atmopsheric models.
# To run the script:
# source GCM_remap.sh <file_to_interpolate> <name_of_the_output> <destination_mask> <source_mask>
#! /bin/bash
datanc=$1
outfile=$2
maskdestnc=$3
masknc=$4
function usage(){
echo
echo "Usage: $(basename $0) data_file.nc outfilename destination_mask.nc data_file_mask.nc"
echo
echo "Conservative remapping for land and sea points"
echo
}
if test ${#} -lt 3; then
usage
exit
fi
# Define wheather to use land-sea correction or not. If yes - $masknc needs to be provided
if [ -z "$4" ]; then
LSMASK=0
else
LSMASK=1
fi
# If SHARP_CHANGE=1, the treshold land fraction is 0.5 for changing between land and sea, otherwise is 0.999
SHARP_CHANGE=0
# If LSMASK=1, then GAP_FILL needs to be defined. If =1, then nearest neigbours interpolation for gap filling will be applied,
# othewise by default unconstrained remapping will be applied.
# GAP_FILL=0
# Global destination grid map - creating weights
cdo -P 4 gencon,${maskdestnc} -seltimestep,1 ${datanc} weights.nc
# Make input landmask binary if $4 has been given
if test "${LSMASK}" -eq 1; then
if test "${SHARP_CHANGE}" -eq 1; then
# Change at 0.5 land fraction
cdo -setrtoc,-1,0.5,0 -setrtoc,0.5,2,1 ${masknc} maskland.nc
cdo mulc,0.5 -setmisstoc,1 -setrtoc,-0.5,0.5,2 maskland.nc masksea.nc
else
# Change at 0.999 land fraction
cdo -setrtoc,-1,0.999,0 -setrtoc,0.999,2,1 ${masknc} maskland.nc
cdo mulc,-1 -setrtoc,0.001,2,0 -setrtoc,-1,0.001,-1 ${masknc} masksea.nc
fi
fi
if test "${LSMASK}" -eq 1; then
cdo div ${datanc} -setctomiss,0 maskland.nc land.nc
cdo div ${datanc} -setctomiss,0 masksea.nc sea.nc
cdo -P 4 gencon,${maskdestnc} land.nc weight_land.nc
cdo -P 4 gencon,${maskdestnc} sea.nc weight_sea.nc
cdo remap,${maskdestnc},weight_land.nc land.nc landr.nc
cdo remap,${maskdestnc},weight_sea.nc sea.nc sear.nc
cdo ifthenelse -setmisstoc,0 ${maskdestnc} landr.nc sear.nc merged.nc
if test "${GAP_FILL}" -eq 1; then
# Fill the gaps between land and sea by nearest neigbours
cdo setmisstonn landr.nc landrfilled.nc
cdo setmisstonn sear.nc searfilled.nc
cdo ifthenelse -setmisstoc,0 ${maskdestnc} landrfilled.nc searfilled.nc ${outfile}
else
# Fill the gaps between land and sea with unconstrained remapping (doremap preferred option)
cdo setmisstoc,1 -setrtoc,-9999999,9999999,0 merged.nc gaps.nc
cdo remap,${maskdestnc},weights.nc ${datanc} unconstrained.nc
cdo ifthenelse gaps.nc unconstrained.nc merged.nc ${outfile}
fi
else
cdo remap,${maskdestnc},weights.nc ${datanc} ${outfile}
fi