prepare_ecearth_hindcasts_paraso.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/bin/bash
  2. set -u
  3. # This script takes EC-Earth hindcast outputs, reinterpolates them to the NEMO grid, and then generates BDY dta from it.
  4. # Author: C. Pelletier & D. Verfaillie
  5. # Inclusive year range
  6. year_start=1985
  7. year_stop=2014
  8. # Input prefix (with folder) for input data files.
  9. in_prefix="/storepelican/dverfail/bsc/anom_bias/hindcasts"
  10. # Name of experience
  11. name_exp="a3du"
  12. # Frequency
  13. freq="1m"
  14. #for fc_num in fc00 fc01 fc02; do
  15. for fc_num in fc00 fc01 fc02; do
  16. # Working folder where pre-interpolated datafiles will be put
  17. dest_folder="/storepelican/dverfail/bsc/nemo_bdy/bdydta"
  18. dest_prefix="ECEarth_${name_exp}_${fc_num}_${freq}_eORCA025-SO_BDYDTA_nbr1_"
  19. pwd=`pwd`
  20. # Python script for reformatting BDYDTA (final step)
  21. reformat_script="/home/elic/dverfail/PARAMOUR_TOOLS/nemo_bdy/generate_new_bdy_dta_onefile.py"
  22. # min_lon, max_lon, min_lat, max_lat
  23. # To precut the input data prior to interpolation (not required, but less expensive if your source code is much bigger than the destination one, which is the case from global to the Southern Ocean.
  24. # Take a generous margin (4-5 nodes bigger than the destination grid limit)
  25. latlon_cut="-180,180,-90,-28"
  26. # # Script for converting EOS80 to TEOS-10 (look at the script comments for why it exists and what it does).
  27. # not needed for EC-Earth, which is already in TEOS-10
  28. # curr_dir=`pwd`
  29. # eos10_script="${curr_dir}/convert_eos10_new.py"
  30. # NEMO destination CDO grid description (see `cdo_get_griddes.sh`).
  31. dest_gridfile_t="/storepelican/pelletie/nemo_bdy/grids/eORCA025-SO_grid_T.grid"
  32. dest_gridfile_u="/storepelican/pelletie/nemo_bdy/grids/eORCA025-SO_grid_U.grid"
  33. dest_gridfile_v="/storepelican/pelletie/nemo_bdy/grids/eORCA025-SO_grid_V.grid"
  34. pid="$$"
  35. mkdir -p ${dest_folder}
  36. cd ${dest_folder}
  37. for((year=year_start;year<=year_stop;year++)); do
  38. # Loop over input years.
  39. module --force purge
  40. module load releases/2020b
  41. module load noarch
  42. module load NCO
  43. module load CDO
  44. # 1) Extract T, S and ssh (T grid).
  45. cdo selname,thetao,so ${in_prefix}/${fc_num}/${name_exp}_${freq}_opa_grid_T_3D_${year}.nc tmp_pid${pid}.nc
  46. cdo selname,zos ${in_prefix}/${fc_num}/${name_exp}_${freq}_opa_grid_T_2D_${year}.nc tmp2_pid${pid}.nc
  47. cdo -O merge tmp_pid${pid}.nc tmp2_pid${pid}.nc tmp3_pid${pid}.nc
  48. # precut
  49. cdo -O sellonlatbox,${latlon_cut} tmp3_pid${pid}.nc tmp_pid${pid}.nc
  50. ncrename -v olevel,deptht tmp_pid${pid}.nc
  51. ncrename -d olevel,deptht tmp_pid${pid}.nc
  52. # remap
  53. cdo remapbil,${dest_gridfile_t} tmp_pid${pid}.nc tmp2_pid${pid}.nc
  54. cdo setmisstonn tmp2_pid${pid}.nc tmp_pid${pid}.nc
  55. module --force purge
  56. module load releases/2019a
  57. module load noarch
  58. module load Java/11.0.2
  59. module load ELIC_Python/1-foss-2019a-Python-3.7.2
  60. input_full=`readlink -f tmp_pid${pid}.nc`
  61. output_full="${dest_folder}/${dest_prefix}grid_T_y${year}.nc"
  62. python ${reformat_script} ${input_full} t ${output_full}
  63. module --force purge
  64. module load releases/2020b
  65. module load noarch
  66. module load NCO
  67. module load CDO
  68. # 2) Extract u velocities.
  69. #calculate ubarotropic from uo (3D): vertical mean of uo
  70. cdo selname,uo ${in_prefix}/${fc_num}/${name_exp}_${freq}_opa_grid_U_3D_${year}.nc tmp_pid${pid}.nc
  71. cdo vertmean tmp_pid${pid}.nc tmp2_pid${pid}.nc
  72. ncap2 -O -s 'ubar = uo;' tmp2_pid${pid}.nc tmp3_pid${pid}.nc
  73. cdo -O merge tmp_pid${pid}.nc tmp3_pid${pid}.nc tmp4_pid${pid}.nc
  74. # precut
  75. cdo -O sellonlatbox,${latlon_cut} tmp4_pid${pid}.nc tmp_pid${pid}.nc
  76. ncap2 -O -s 'uobaroclinic = uo - ubar;' tmp_pid${pid}.nc tmp2_pid${pid}.nc
  77. ncks -x -v uo,uo_2 tmp2_pid${pid}.nc -O tmp_pid${pid}.nc
  78. ncrename -v ubar,uobarotropic tmp_pid${pid}.nc
  79. ncrename -v olevel,depthu -v olevel_bnds,depthu_bnds tmp_pid${pid}.nc
  80. ncatted -a bounds,depthu,o,c,"depthu_bnds" -a name,depthu,o,c,"depthu" tmp_pid${pid}.nc
  81. ncrename -d olevel,depthu tmp_pid${pid}.nc
  82. ncpdq -O -a time_counter,depthu,y,x tmp_pid${pid}.nc tmp2_pid${pid}.nc
  83. # remap
  84. cdo remapbil,${dest_gridfile_u} tmp2_pid${pid}.nc tmp_pid${pid}.nc
  85. cdo setmisstonn tmp_pid${pid}.nc tmp2_pid${pid}.nc
  86. module --force purge
  87. module load releases/2019a
  88. module load noarch
  89. module load Java/11.0.2
  90. module load ELIC_Python/1-foss-2019a-Python-3.7.2
  91. input_full=`readlink -f tmp2_pid${pid}.nc`
  92. output_full="${dest_folder}/${dest_prefix}grid_U_y${year}.nc"
  93. python ${reformat_script} ${input_full} u ${output_full}
  94. module --force purge
  95. module load releases/2020b
  96. module load noarch
  97. module load NCO
  98. module load CDO
  99. # 3) Extract v velocities.
  100. #calculate vbarotropic from vo (3D): vertical mean of vo
  101. cdo selname,vo ${in_prefix}/${fc_num}/${name_exp}_${freq}_opa_grid_V_3D_${year}.nc tmp_pid${pid}.nc
  102. cdo vertmean tmp_pid${pid}.nc tmp2_pid${pid}.nc
  103. ncap2 -O -s 'vbar = vo;' tmp2_pid${pid}.nc tmp3_pid${pid}.nc
  104. cdo -O merge tmp_pid${pid}.nc tmp3_pid${pid}.nc tmp4_pid${pid}.nc
  105. # precut
  106. cdo -O sellonlatbox,${latlon_cut} tmp4_pid${pid}.nc tmp_pid${pid}.nc
  107. ncap2 -O -s 'vobaroclinic = vo - vbar;' tmp_pid${pid}.nc tmp2_pid${pid}.nc
  108. ncks -x -v vo,vo_2 tmp2_pid${pid}.nc -O tmp_pid${pid}.nc
  109. ncrename -v vbar,vobarotropic tmp_pid${pid}.nc
  110. ncrename -v olevel,depthv -v olevel_bnds,depthv_bnds tmp_pid${pid}.nc
  111. ncatted -a bounds,depthv,o,c,"depthv_bnds" -a name,depthv,o,c,"depthv" tmp_pid${pid}.nc
  112. ncrename -d olevel,depthv tmp_pid${pid}.nc
  113. ncpdq -O -a time_counter,depthv,y,x tmp_pid${pid}.nc tmp2_pid${pid}.nc
  114. # remap
  115. cdo remapbil,${dest_gridfile_v} tmp2_pid${pid}.nc tmp_pid${pid}.nc
  116. cdo setmisstonn tmp_pid${pid}.nc tmp2_pid${pid}.nc
  117. module --force purge
  118. module load releases/2019a
  119. module load noarch
  120. module load Java/11.0.2
  121. module load ELIC_Python/1-foss-2019a-Python-3.7.2
  122. input_full=`readlink -f tmp2_pid${pid}.nc`
  123. output_full="${dest_folder}/${dest_prefix}grid_V_y${year}.nc"
  124. python ${reformat_script} ${input_full} v ${output_full}
  125. module --force purge
  126. module load releases/2020b
  127. module load noarch
  128. module load NCO
  129. module load CDO
  130. done
  131. done
  132. rm -rf ./*pid${pid}*