ESA_to_ORCA1.bash 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/bash
  2. #SBATCH -n 1
  3. #SBATCH -t 96:00:00
  4. #SBATCH -J interpolate_ESA
  5. #SBATCH -o /esnas/obs/esa/scripts/prepare_obs_EnKF/interpolation/slurm-%j.out
  6. #SBATCH -e /esnas/obs/esa/scripts/prepare_obs_EnKF/interpolation/slurm-%j.err
  7. # Original: Pierre Mathiot, 2011
  8. # Update : Francois Massonnet, 2013
  9. # Update at BSC: Francois Massonnet, 2016
  10. #
  11. # Interpolation of ESA sea ice concentration to ORCA grid
  12. # Particular attention is paid to "flag" values. Concentration
  13. # is only considered in "nominal" regions, that is, not the coastal
  14. # areas, not the gap filling area around the north pole, not questionable
  15. # data etc.
  16. #
  17. #
  18. # Questions: francois.massonnet@uclouvain.be
  19. # francois.massonnet@bsc.es
  20. module load netCDF-Fortran/4.2-foss-2015a
  21. #set -x
  22. set -o nounset
  23. set -o errexit
  24. yearb=1992 # Years to process
  25. yeare=2008
  26. grid=ORCA1 # Grid type
  27. nbsmooth=2 # This is important. We need to interpolate the observations
  28. # on the model grid. However the model is on a coarser grid.
  29. # Therefore, before interpolation, we will smooth the input
  30. # observational data. This variable tells how many times we
  31. # have to apply the "smooth9" function of cdo. This function
  32. # makes a 2-D smoothing of each grid point by weighting with
  33. # itself and its neighbours.
  34. # Roughly speaking, the variable nbsmooth should be the ratio
  35. # of model resolution to observational resolution.
  36. # At ORCA1, resolution is ~50 km at the poles and input data
  37. # from ESA is 25 km, hence a ratio of 2
  38. # Set nbsmooth to 0 if you don't want smoothing.
  39. sosiedir=$HOME/sosie-2.6.2/bin
  40. mask=/esnas/autosubmit/con_files/mesh_mask_nemo.Ec3.2_O1L75.nc
  41. sourcedir=/esnas/obs/esa/original_files/seaice # Where original files are located
  42. outdir=/esnas/obs/esa/interpolated/
  43. scratchdir=/esnas/scratch/$USER/TMP
  44. # Create a directory to work
  45. # --------------------------
  46. tmpdir=$scratchdir/TMP_${RANDOM}
  47. echo "TMPDIR IS >>>>>> $tmpdir <<<<<<<"
  48. mkdir -p $tmpdir
  49. cp namelist* $tmpdir
  50. cp sosie_mapping_ESA*.nc $tmpdir
  51. cd $tmpdir
  52. # 1. Get the model grid and the mask
  53. if [ ! -f ${mask} ]
  54. then
  55. echo "${mask} does not exist."
  56. exit
  57. fi
  58. ln -sf ${mask} mask_out.nc
  59. # Link sosie
  60. ln -sf $sosiedir/sosie.x .
  61. for year in `seq ${yearb} ${yeare}`
  62. do
  63. for month in 01 02 03 04 05 06 07 08 09 10 11 12
  64. do
  65. echo $year-${month}
  66. rm -f listfiles.txt
  67. ls $sourcedir/${year}/$month/ESACCI-SEAICE-L4-SICONC-SSMI-NH25kmEASE2-????????-fv01.11.nc > list_files.txt
  68. for file in `cat list_files.txt`
  69. do
  70. tag=`basename $file | sed -e "s/ESACCI-SEAICE-L4-SICONC-SSMI-NH25kmEASE2-//" -e "s/-fv01.11.nc//"`
  71. echo $tag
  72. # Check that the file is also available for the other hemisphere
  73. nfile=`ls $sourcedir/${year}/${month}/ESACCI-SEAICE-L4-SICONC-SSMI-?H25kmEASE2-${tag}-fv01.11.nc | wc -l`
  74. if [[ $nfile == 2 ]]
  75. then
  76. echo "Two files were found for the time stamp ${tag}!"
  77. for hemi in nh sh
  78. do
  79. HEMI=`echo $hemi | tr '[:lower:]' '[:upper:]'`
  80. filein=$sourcedir/${year}/${month}/ESACCI-SEAICE-L4-SICONC-SSMI-${HEMI}25kmEASE2-${tag}-fv01.11.nc
  81. cp -f $filein data_in_${hemi}-${tag}.nc
  82. # We only take points that have nominal (status_flag = 0) quality
  83. cdo chname,status_flag,mask -eqc,0 \
  84. -selvar,status_flag data_in_${hemi}-${tag}.nc mask_in_${hemi}-${tag}.nc
  85. # Smoothing input data
  86. if [[ $nbsmooth == 0 ]]
  87. then
  88. echo "WARNING - YOU DID NOT SMOOTH INPUT DATA"
  89. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  90. mv data_in_${hemi}-${tag}.nc data_in_smooth_${hemi}-${tag}.nc
  91. else
  92. mv data_in_${hemi}-${tag}.nc data_in_smooth0_${hemi}-${tag}.nc
  93. for jsmooth in `seq 1 $nbsmooth`
  94. do
  95. cdo smooth9 data_in_smooth$(( $jsmooth - 1 ))_${hemi}-${tag}.nc \
  96. data_in_smooth${jsmooth}_${hemi}-${tag}.nc
  97. done
  98. mv data_in_smooth${jsmooth}_${hemi}-${tag}.nc data_in_smooth_${hemi}-${tag}.nc
  99. fi # if smoothing is necessary
  100. # Interpolation of land-sea mask
  101. echo "Interpolation of land-sea mask"
  102. sed -e "s/TTAARRGGEETT/${grid}/" \
  103. -e "s/HHEEMMII/${hemi}/" \
  104. -e "s/TTAAGG/${tag}/" \
  105. namelist_ESA-mask > namelist
  106. ./sosie.x
  107. # Since we just did an interpolation, the mask will not be sharp:
  108. # There will be values not equal to 1. Let's remask the result
  109. # The threshold is pretty arbitrary here, but to be conservative
  110. # we just ignore points different from one.
  111. cdo eqc,1 tmask_ESA-${hemi}-${grid}_${tag}.nc ESA-${hemi}_mask_on_${grid}_${tag}.nc
  112. # 2. Interpolation of concentration
  113. sed -e "s/TTAARRGGEETT/${grid}/" \
  114. -e "s/HHEEMMII/${hemi}/" \
  115. -e "s/TTAAGG/${tag}/" \
  116. namelist_ESA-conc > namelist
  117. ./sosie.x
  118. # Mask the interpolated ice concentration using the interpolated mask.
  119. # Also, put missing values returned by sosie (<0) to zero, so that
  120. # we'll be able to add northern and southern hemispheres later
  121. cdo setmisstoc,0 \
  122. -mul -selvar,at_i at_i_ESA-${hemi}-${grid}_${tag}.nc \
  123. -selvar,tmask ESA-${hemi}_mask_on_${grid}_${tag}.nc \
  124. at_i_ESA-${hemi}-${grid}_${tag}_masked.nc
  125. # 3. Interpolation of standard deviation
  126. #
  127. # This is a point to worry about, although there is not enough
  128. # at this stage to do better. Interpolation of second-order moments
  129. # should account for the fact that errors are correlated, however
  130. # we don't have this information from the OSI-SAF product.
  131. # The best we can do is to assume that these errors are not correlated
  132. # and can be interpolated as is.
  133. sed -e "s/TTAARRGGEETT/${grid}/" \
  134. -e "s/HHEEMMII/${hemi}/" \
  135. -e "s/TTAAGG/${tag}/" \
  136. namelist_ESA-error > namelist
  137. ./sosie.x
  138. # Mask the interpolated error using the interpolated mask
  139. cdo setmisstoc,0 \
  140. -mul -selvar,error_at_i error_at_i_ESA-${hemi}-${grid}_${tag}.nc \
  141. -selvar,tmask ESA-${hemi}_mask_on_${grid}_${tag}.nc \
  142. error_at_i_ESA-${hemi}-${grid}_${tag}_masked.nc
  143. done # for each hemisphere
  144. # Merge North and South data in one file
  145. for var in at_i error_at_i
  146. do
  147. ncbo -O -F -v ${var} --op_typ=add ${var}_ESA-nh-${grid}_${tag}_masked.nc \
  148. ${var}_ESA-sh-${grid}_${tag}_masked.nc \
  149. ${var}_ESA-${grid}_${tag}.nc
  150. done
  151. # Dump errors into concentration files
  152. ncks -F -A -v error_at_i error_at_i_ESA-${grid}_${tag}.nc at_i_ESA-${grid}_${tag}.nc
  153. mv at_i_ESA-${grid}_${tag}.nc $outdir
  154. # Do a bit of cleaning here!
  155. rm -f at_i_ESA-?h-${grid}_${tag}_masked.nc \
  156. error_at_i_ESA-?h-${grid}_${tag}_masked.nc \
  157. error_at_i_ESA-?h-${grid}_${tag}_masked.nc \
  158. error_at_i_ESA-${grid}_${tag}.nc \
  159. ESA-?h_mask_on_${grid}_${tag}.nc \
  160. error_at_i_ESA-?h-${grid}_${tag}.nc \
  161. at_i_ESA-?h-${grid}_${tag}.nc \
  162. tmask_ESA-?h-${grid}_${tag}.nc \
  163. data_in_smooth*${tag}.nc \
  164. mask_in_?h-${tag}.nc
  165. else
  166. echo "Only one file was found for the time stamp $tag"
  167. echo "This is not coded yet"
  168. fi # if there are two files
  169. done # for each file of the year
  170. done # for each month
  171. done # for each year