prepare_ecearth_paraso.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/bin/bash
  2. set -u
  3. # This script takes EC-Earth outputs, reinterpolates them to the NEMO grid, and then generates BDY dta from it.
  4. # Author: C. Pelletier
  5. # Inclusive year range
  6. year_start=1979
  7. year_stop=2050
  8. # Input prefix (with folder) for input data files (in .tar format).
  9. in_prefix="/storage/elic/chamarro/data"
  10. # Name of experience
  11. name_exp="a1tq"
  12. # Frequency
  13. freq="1m"
  14. # Working folder where pre-interpolated datafiles will be put
  15. dest_folder="/storepelican/pelletie/nemo_bdy/bdydta"
  16. dest_prefix="ECEarth_${name_exp}_${freq}_eORCA025-SO_BDYDTA_nbr1_"
  17. pwd=`pwd`
  18. # Python script for reformatting BDYDTA (final step)
  19. reformat_script="${pwd}/generate_new_bdy_dta_onefile.py"
  20. # min_lon, max_lon, min_lat, max_lat
  21. # 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.
  22. # Take a generous margin (4-5 nodes bigger than the destination grid limit)
  23. latlon_cut="-180,180,-90,-28"
  24. # # Script for converting EOS80 to TEOS-10 (look at the script comments for why it exists and what it does).
  25. # not needed for EC-Earth, which is already in TEOS-10
  26. # curr_dir=`pwd`
  27. # eos10_script="${curr_dir}/convert_eos10_new.py"
  28. # NEMO destination CDO grid description (see `cdo_get_griddes.sh`).
  29. dest_gridfile_t="/storepelican/pelletie/nemo_bdy/grids/eORCA025-SO_grid_T.grid"
  30. dest_gridfile_u="/storepelican/pelletie/nemo_bdy/grids/eORCA025-SO_grid_U.grid"
  31. dest_gridfile_v="/storepelican/pelletie/nemo_bdy/grids/eORCA025-SO_grid_V.grid"
  32. pid="$$"
  33. mkdir -p ${dest_folder}
  34. cd ${dest_folder}
  35. for((year=year_start;year<=year_stop;year++)); do
  36. # Loop over input years.
  37. module purge
  38. module load 2018b CDO NCO
  39. # 1) Extract T, S and ssh (T grid).
  40. tar -xvf ${in_prefix}/${name_exp}/NEMO/MMO_${name_exp}_18500101_fc0_${year}0101-${year}1231.tar ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_T_3D.nc ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_T_2D.nc
  41. cdo selname,thetao,so ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_T_3D.nc tmp_pid${pid}.nc
  42. cdo selname,zos ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_T_2D.nc tmp2_pid${pid}.nc
  43. cdo merge tmp_pid${pid}.nc tmp2_pid${pid}.nc tmp3_pid${pid}.nc
  44. rm -f ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_T_3D.nc ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_T_2D.nc
  45. # precut
  46. cdo -O sellonlatbox,${latlon_cut} tmp3_pid${pid}.nc tmp_pid${pid}.nc
  47. ncrename -v olevel,deptht tmp_pid${pid}.nc
  48. ncrename -d olevel,deptht tmp_pid${pid}.nc
  49. # remap
  50. cdo remapbil,${dest_gridfile_t} tmp_pid${pid}.nc tmp2_pid${pid}.nc
  51. cdo setmisstonn tmp2_pid${pid}.nc tmp_pid${pid}.nc
  52. module purge
  53. module load ELIC/0.1-foss-2018b-Python-3.6.6
  54. input_full=`readlink -f tmp_pid${pid}.nc`
  55. output_full="${dest_folder}/${dest_prefix}grid_T_y${year}.nc"
  56. python ${reformat_script} ${input_full} t ${output_full}
  57. module purge
  58. module load CDO NCO
  59. # 2) Extract u velocities.
  60. if [ "${freq}" == "1d" ]; then
  61. tar -xvf ${in_prefix}/${name_exp}/NEMO/MMO_${name_exp}_18500101_fc0_${year}0101-${year}1231.tar ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_U_3D.nc ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_U_2D.nc
  62. cdo selname,ubar ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_U_2D.nc tmp2_pid${pid}.nc
  63. else
  64. # ubar is not stored in monthly outputs, so take it from daily and monmean
  65. tar -xvf ${in_prefix}/${name_exp}/NEMO/MMO_${name_exp}_18500101_fc0_${year}0101-${year}1231.tar ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_U_3D.nc ${name_exp}_1d_${year}0101_${year}1231_opa_grid_U_2D.nc
  66. cdo selname,ubar ${name_exp}_1d_${year}0101_${year}1231_opa_grid_U_2D.nc tmp3_pid${pid}.nc
  67. cdo monmean tmp3_pid${pid}.nc tmp2_pid${pid}.nc
  68. fi
  69. cdo selname,uo ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_U_3D.nc tmp_pid${pid}.nc
  70. cdo merge tmp_pid${pid}.nc tmp2_pid${pid}.nc tmp3_pid${pid}.nc
  71. rm -f ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_U_3D.nc ${name_exp}_??_${year}0101_${year}1231_opa_grid_U_2D.nc
  72. # precut
  73. cdo -O sellonlatbox,${latlon_cut} tmp3_pid${pid}.nc tmp_pid${pid}.nc
  74. ncap2 -O -s 'uobaroclinic = uo - ubar;' tmp_pid${pid}.nc tmp2_pid${pid}.nc
  75. ncks -x -v uo tmp2_pid${pid}.nc -O tmp_pid${pid}.nc
  76. ncrename -v ubar,uobarotropic tmp_pid${pid}.nc
  77. ncrename -v olevel,depthu -v olevel_bnds,depthu_bnds tmp_pid${pid}.nc
  78. ncatted -a bounds,depthu,o,c,"depthu_bnds" -a name,depthu,o,c,"depthu" tmp_pid${pid}.nc
  79. ncrename -d olevel,depthu tmp_pid${pid}.nc
  80. ncpdq -O -a time_counter,depthu,y,x tmp_pid${pid}.nc tmp2_pid${pid}.nc
  81. # remap
  82. cdo remapbil,${dest_gridfile_u} tmp2_pid${pid}.nc tmp_pid${pid}.nc
  83. cdo setmisstonn tmp_pid${pid}.nc tmp2_pid${pid}.nc
  84. module purge
  85. module load ELIC/0.1-foss-2018b-Python-3.6.6
  86. input_full=`readlink -f tmp2_pid${pid}.nc`
  87. output_full="${dest_folder}/${dest_prefix}grid_U_y${year}.nc"
  88. python ${reformat_script} ${input_full} u ${output_full}
  89. module purge
  90. module load CDO NCO
  91. # 3) Extract v velocities.
  92. if [ "${freq}" == "1d" ]; then
  93. tar -xvf ${in_prefix}/${name_exp}/NEMO/MMO_${name_exp}_18500101_fc0_${year}0101-${year}1231.tar ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_V_3D.nc ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_V_2D.nc
  94. cdo selname,vbar ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_V_2D.nc tmp2_pid${pid}.nc
  95. else
  96. # vbar is not stored in monthly outputs, so take it from daily and monmean
  97. tar -xvf ${in_prefix}/${name_exp}/NEMO/MMO_${name_exp}_18500101_fc0_${year}0101-${year}1231.tar ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_V_3D.nc ${name_exp}_1d_${year}0101_${year}1231_opa_grid_V_2D.nc
  98. cdo selname,vbar ${name_exp}_1d_${year}0101_${year}1231_opa_grid_V_2D.nc tmp3_pid${pid}.nc
  99. cdo monmean tmp3_pid${pid}.nc tmp2_pid${pid}.nc
  100. fi
  101. cdo selname,vo ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_V_3D.nc tmp_pid${pid}.nc
  102. cdo merge tmp_pid${pid}.nc tmp2_pid${pid}.nc tmp3_pid${pid}.nc
  103. rm -f ${name_exp}_${freq}_${year}0101_${year}1231_opa_grid_V_3D.nc ${name_exp}_??_${year}0101_${year}1231_opa_grid_V_2D.nc
  104. # precut
  105. cdo -O sellonlatbox,${latlon_cut} tmp3_pid${pid}.nc tmp_pid${pid}.nc
  106. ncap2 -O -s 'vobaroclinic = vo - vbar;' tmp_pid${pid}.nc tmp2_pid${pid}.nc
  107. ncks -x -v vo tmp2_pid${pid}.nc -O tmp_pid${pid}.nc
  108. ncrename -v vbar,vobarotropic tmp_pid${pid}.nc
  109. ncrename -v olevel,depthv -v olevel_bnds,depthv_bnds tmp_pid${pid}.nc
  110. ncatted -a bounds,depthv,o,c,"depthv_bnds" -a name,depthv,o,c,"depthv" tmp_pid${pid}.nc
  111. ncrename -d olevel,depthv tmp_pid${pid}.nc
  112. ncpdq -O -a time_counter,depthv,y,x tmp_pid${pid}.nc tmp2_pid${pid}.nc
  113. # remap
  114. cdo remapbil,${dest_gridfile_v} tmp2_pid${pid}.nc tmp_pid${pid}.nc
  115. cdo setmisstonn tmp_pid${pid}.nc tmp2_pid${pid}.nc
  116. module purge
  117. module load ELIC/0.1-foss-2018b-Python-3.6.6
  118. input_full=`readlink -f tmp2_pid${pid}.nc`
  119. output_full="${dest_folder}/${dest_prefix}grid_V_y${year}.nc"
  120. python ${reformat_script} ${input_full} v ${output_full}
  121. module purge
  122. module load CDO NCO
  123. done
  124. rm -rf ./*pid${pid}*