script_interp_vert_ocean_restart.bash 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. set -evx
  3. #
  4. # This script interpolates vertically ocean restarts, extrapolates horizontally,
  5. # fills up empty seas with climatologies, extrapolate vertically.
  6. #
  7. # History : Virginie Guemas - Initial version 2012
  8. # Virginie Guemas - ORAS4 + vertical extrapolation +
  9. # commenting and clarifying - March 2014
  10. #
  11. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. # Arguments
  13. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. type='oras4' # 'glorys' / 'metoffice' : if you add another type, you'll have
  15. # to adapt the list of variables this restart contains below.
  16. # Look for the variable $type in the script.
  17. fillinrot='TRUE' # Extrapolate or not the rotational rotn / rotb
  18. # TRUE increases subtantially the interpolation time
  19. # FALSE has negligible effects ( u, v, t, s are initialized )
  20. restart_in=$1 # Input restart file name without the .nc extension
  21. meshmaskin='/cfu/autosubmit/con_files/mesh_mask_nemo.nemovar_O1L42_new.nc'
  22. # Meshmask of the input reanalysis. Example:
  23. #'/cfu/autosubmit/con_files/mesh_mask_nemo.glorys2v1_O25L75.nc'
  24. confout='ORCA1L46' # output configuration
  25. vertgridout='/cfu/autosubmit/con_files/mesh_mask_nemo.Ec3.0_O1L46.nc'
  26. # Meshmask of the output restart, i.e. model and grid to be used in
  27. # climate prediction
  28. Ptoextrap='/cfu/pub/scripts/prep_restarts/auxfiles/masks/Tofill_ecearth.v3.0.ORCA1L46.extrap.oras4.restarts.nc'
  29. # Locations of the points where to extrapolate horizontally the restarts after
  30. # interpolation = 1 in the netcdf file, 0 everywhere else. Locations available
  31. # for the tmask, umask, vmask and fmask grid. If you don't know about those
  32. # four variables read about the NEMO documentation about the grid.
  33. # To obtain the Ptoextrap netcdf file, it is necessary to run once this script
  34. # without extrapolation and filling of the empty seas and compare the output
  35. # restart with the output meshmask. To do so, set 0 everywhere in Ptoextrap
  36. # and use build_Tofill.bash afterwards.
  37. Ptofillclim='/cfu/pub/scripts/prep_restarts/auxfiles/masks/Tofill_ecearth.v3.0.ORCA1L46.clim.nc'
  38. # Locations of the empty seas that need to be filled up with a climatology after
  39. # interpolation = 1 in the netcdf file, 0 everywhere else. Locations available
  40. # for the tmask, umask, vmask and fmask grid. If you don't know about those
  41. # four variables read about the NEMO documentation about the grid.
  42. # To obtain the Ptofillclim netcdf file, it is necessary to run once this script
  43. # without extrapolation and filling of the empty seas and compare the output
  44. # restart with the output meshmask. To do so, set 0 everywhere in Ptofillclim
  45. # and use build_Tofill.bash afterwards.
  46. mon=$3 # Month of the restart on 2 digits MM
  47. restart_out=$2 # Output restart file name without the .nc extension
  48. cfutools='/home/vguemas/CFU_tools_new'
  49. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. case $type in
  51. 'glorys')
  52. # List of 3d variables = that need to be vertically interpolated
  53. listvarsinterp=( 'en' 'avt' 'avmt' 'avmu' 'avmv' 'dissl' 'ub' 'vb' 'tb' 'sb' 'rotb' 'hdivb' 'un' 'vn' 'tn' 'sn' 'rotn' 'hdivn' 'rhop' )
  54. # List of 2d variables = that only need extrapolation
  55. listvarsextrap=( 'gcx' 'gcxb' 'gcxbfs' 'gru' 'grv' 'gsu' 'gsv' 'gtu' 'gtv' 'ssh_m' 'sshb' 'sshn' 'sss_m' 'sst_m' 'ssu_m' 'ssv_m' )
  56. # List of 0d variables = that need to be copied to the output restart
  57. varscopy='nn_fsbc,rdt,rdttra1'
  58. ;;
  59. 'oras4')
  60. listvarsinterp=( 'en' 'ub' 'vb' 'tb' 'sb' 'rotb' 'hdivb' 'un' 'vn' 'tn' 'sn' 'rotn' 'hdivn' )
  61. listvarsextrap=('gcx' 'gcxb' 'sshb' 'sshn' )
  62. varscopy='rdt,rdttra1,ndastp,adatrj'
  63. ;;
  64. esac
  65. source ${cfutools}/prep_restarts/library/library.bash
  66. if [[ $fillinrot == 'FALSE' ]] ; then
  67. cp ${Ptoextrap} Ptoextrap.nc
  68. ncks -v fmask Ptoextrap.nc tmp1.nc
  69. cdo mulc,0 tmp1.nc tmp2.nc
  70. ncks -A tmp2.nc Ptoextrap.nc
  71. rm -f tmp1.nc tmp2.nc
  72. Ptoextrap='Ptoextrap.nc'
  73. fi
  74. # Copy the 0d variables from the input restart to the output restart
  75. ncks -O -v $varscopy ${restart_in}.nc ${restart_out}.nc
  76. ncks -A -v nav_lon,nav_lat $meshmaskin ${restart_out}.nc
  77. ncks -A -v nav_lev $vertgridout ${restart_out}.nc
  78. # Vertical interpolation + horizontal extrapolation at each level + filling empty seas + vertical extrapolation
  79. cdo vertsum -selvar,tmask,vmask,umask,fmask $meshmaskin mask2din.nc
  80. for var in ${listvarsinterp[@]} ; do
  81. case $var in
  82. 'avmu'|'un'|'ub') mask='umask' ; varlon='glamu' ; varlat='gphiu' ; fill='umask' ;;
  83. 'avmv'|'vn'|'vb') mask='vmask' ; varlon='glamv' ; varlat='gphiv' ; fill='vmask' ;;
  84. 'rotb'|'rotn') mask='fmask' ; varlon='glamf' ; varlat='gphif' ; fill='fmask' ;;
  85. 'avt'|'avmt'|'en'|'dissl'|'hdivb'|'hdivn'|'rhop'|'sn'|'tn'|'sb'|'tb') mask='tmask' ; varlon='glamt' ; varlat='gphit' ; fill='tmask' ;;
  86. esac
  87. # The vertical interpolation is performed below
  88. python ${cfutools}/interpolation/interp_vert.py ${restart_in}.nc $var $meshmaskin e3t_0 mask2din.nc $mask $vertgridout e3t_0 gdept_0 ${var}_${restart_out}_int.nc
  89. # The function extrap extrapolates horizontally and fill in the empty seas with a climatology
  90. extrap ${var}_${restart_out}_int.nc ${var} ${meshmaskin} ${varlon} ${varlat} ${Ptoextrap} ${Ptofillclim} ${fill} ${var}_${restart_out}_int2.nc 3d $cfutools $confout $mon
  91. # The vertical extrapolation to empty levels is performed below
  92. python ${cfutools}/interpolation/vertextrap.py ${var}_${restart_out}_int2.nc ${var} $vertgridout nav_lev ${var}_${restart_out}_int3.nc
  93. # Apply the mask
  94. applymask $vertgridout $mask ${var}_${restart_out}_int3.nc $var ${var}_${restart_out}.nc
  95. # Pasting the output to ${restart_out}.nc
  96. gathervar ${restart_out}.nc ${var}_${restart_out}.nc
  97. rm -f ${var}_${restart_out}.nc ${var}_${restart_out}_int.nc ${var}_${restart_out}_int2.nc ${var}_${restart_out}_int3.nc
  98. done
  99. # Horizontal extrapolation and filling empty seas of 2d variables
  100. ncks -O -d lev,0 ${Ptoextrap} Ptoextrap_lev0.nc
  101. ncks -O -d lev,0 ${Ptofillclim} Ptofillclim_lev0.nc
  102. ncks -O -d z,0 $vertgridout mask_lev0.nc
  103. ncks -O -d z,0 $meshmaskin maskin_lev0.nc
  104. for var in ${listvarsextrap[@]} ; do
  105. case $var in
  106. 'gru'|'gsu'|'gtu'|'ssu_m'|'u_io') varlon='glamu' ; varlat='gphiu' ; fill='umask' ; mask='umask' ;;
  107. 'grv'|'gsv'|'gtv'|'ssv_m'|'v_io') varlon='glamv' ; varlat='gphiv' ; fill='vmask' ; mask='vmask' ;;
  108. 'gcx'|'gcxb'|'gcxbfs'|'ssh_m'|'sshb'|'sshn'|'sss_m'|'sst_m'|'alb_ice'|'sst_io'|'sss_io') varlon='glamt' ; varlat='gphit' ; fill='tmask' ; mask='tmask' ;;
  109. esac
  110. # Apply the input mask
  111. applymask maskin_lev0.nc $mask ${restart_in}.nc $var ${var}_${restart_in}.nc
  112. # Horizontal extrapolation and fillup the empty seas with a climatology
  113. extrap ${var}_${restart_in}.nc ${var} ${meshmaskin} ${varlon} ${varlat} Ptoextrap_lev0.nc Ptofillclim_lev0.nc ${fill} ${var}_${restart_out}_int.nc 2d $cfutools $confout $mon
  114. # Apply the output mask
  115. applymask mask_lev0.nc $mask ${var}_${restart_out}_int.nc $var ${var}_${restart_out}.nc
  116. # Pasting the output to ${restart_out}.nc
  117. gathervar ${restart_out}.nc ${var}_${restart_out}.nc
  118. rm -f ${var}_${restart_out}.nc ${var}_${restart_out}_int.nc ${var}_${restart_in}.nc
  119. done
  120. rm -f Ptoextrap_lev0.nc Ptofillclim_lev0.nc mask2din.nc mask_lev0.nc tmpmask.nc maskin_lev0.nc
  121. if [[ -e Ptoextrap.nc ]] ; then rm -f Ptoextrap.nc ; fi