test_OSISAF_to_ORCA.bash 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/bin/bash
  2. #SBATCH -n 1
  3. #SBATCH -t 00:05:00
  4. #SBATCH -J interpolate_OSISAF
  5. #SBATCH -o slurm-%j.out
  6. #SBATCH -e slurm-%j.err
  7. #SBATCH --mem-per-cpu=8000
  8. #SBATCH --partition=debug # Partition sur laquelle lancer le travail
  9. #SBATCH --account=limhr # Compte associé au travail
  10. # Original: Pierre Mathiot, 2011
  11. # Update : Francois Massonnet, 2013
  12. # Update at BSC: Francois Massonnet, 2016
  13. # Francois Massonnet, Nov 2016 -- update to match
  14. # BSC conventions
  15. #
  16. # Interpolation of OSI-SAF sea ice concentration to ORCA grid
  17. # Particular attention is paid to "flag" values. Concentration
  18. # is only considered in "nominal" regions, that is, not the coastal
  19. # areas, the gap filling area around the north pole.
  20. #
  21. # Questions: francois.massonnet@uclouvain.be
  22. # francois.massonnet@bsc.es
  23. set -x
  24. set -o nounset
  25. set -o errexit
  26. yearb=1983 # Years to process
  27. yeare=1983
  28. grid=eORCA1 # Grid type: ORCA1 or ORCA25
  29. nbsmooth=2 # This is important. We need to interpolate the observations
  30. # on the model grid. However the model is on a coarser grid.
  31. # Therefore, before interpolation, we will smooth the input
  32. # observational data. This variable tells how many times we
  33. # have to apply the "smooth9" function of cdo. This function
  34. # makes a 2-D smoothing of each grid point by weighting with
  35. # itself and its neighbours.
  36. # Roughly speaking, the variable nbsmooth should be the ratio
  37. # of observational resolution to model resolution.
  38. # At ORCA1, resolution is ~50 km at the poles and input data
  39. # from OSI-SAF is 10 km, hence a ratio of 5
  40. # At ORCA25 resolution is ~15 km hence a ratio of close to 1.
  41. # Set nbsmooth to 0 if you don't want smoothing.
  42. # AD: Set to 2 for OSI SAF 450 => 25km and eORCA1 ~50km.
  43. sosiedir=$HOME/tools/sosie-master/bin
  44. mask=/gpfs/home/acad/ucl-elic/adelhass/git/EnKF/conversion_uf/mask-${grid}.nc
  45. sourcedir=/gpfs/home/acad/ucl-elic/adelhass/git/EnKF/conversion_uf/OSI-SAF-450
  46. ioutdir=/gpfs/home/acad/ucl-elic/adelhass/git/EnKF/conversion_uf/OSI-SAF-450-on-nemo
  47. scratchdir=/gpfs/home/acad/ucl-elic/$USER/scratch_limhr/sosie
  48. # Directory where weights are available (can leave blank if you want to recompute weights)
  49. #weightdir=/esnas/scratch/Earth/nfuckar/EnKF/
  50. weightdir=
  51. # Create a directory to work
  52. # --------------------------
  53. tmpdir=$scratchdir/TMP_${RANDOM}
  54. echo "TMPDIR IS >>>>>> $tmpdir <<<<<<<"
  55. mkdir -p $tmpdir
  56. cp namelist* $tmpdir
  57. # Copy weights if they already exist
  58. [[ -f ${weightdir}/sosie_mapping_OSISAF-nh-${grid}.nc ]] && cp ${weightdir}/sosie_mapping_OSISAF-nh-${grid}.nc $tmpdir
  59. [[ -f ${weightdir}/sosie_mapping_OSISAF-sh-${grid}.nc ]] && cp ${weightdir}/sosie_mapping_OSISAF-sh-${grid}.nc $tmpdir
  60. cd $tmpdir
  61. # 1. Get the model grid and the mask
  62. if [ ! -f ${mask} ]
  63. then
  64. echo "${mask} does not exist."
  65. exit
  66. fi
  67. ln -sf ${mask} mask_out.nc
  68. # Link sosie
  69. ln -sf $sosiedir/sosie3.x .
  70. for year in `seq ${yearb} ${yeare}`
  71. do
  72. echo $year
  73. rm -f listfiles.txt
  74. ls $sourcedir/ice_conc_nh_ease2-250_cdr-v2p0_${year}????1200.nc > list_files.txt
  75. for file in `cat list_files.txt`
  76. do
  77. tag=`basename $file | sed -e "s/ice_conc_nh_ease2-250_cdr-v2p0_//" -e "s/1200.nc//"`
  78. echo $tag
  79. # Check that the file is also available for the other hemisphere
  80. nfile=`ls $sourcedir/ice_conc_?h_ease2-250_cdr-v2p0_${tag}1200.nc | wc -l`
  81. if [[ $nfile == 2 ]]
  82. then
  83. echo "Two files were found for the time stamp ${tag}!"
  84. for hemi in nh sh
  85. do
  86. filein=$sourcedir/ice_conc_${hemi}_ease2-250_cdr-v2p0_${tag}1200.nc
  87. cp -f $filein data_in_${hemi}-${tag}.nc
  88. # We only take points that have nominal (status_flag = 0) quality
  89. cdo chname,status_flag,mask -eqc,0 \
  90. -selvar,status_flag data_in_${hemi}-${tag}.nc mask_in_${hemi}-${tag}.nc
  91. # Smoothing input data
  92. if [[ $nbsmooth == 0 ]]
  93. then
  94. echo "WARNING - YOU DID NOT SMOOTH INPUT DATA"
  95. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  96. mv data_in_${hemi}-${tag}.nc data_in_smooth_${hemi}-${tag}.nc
  97. else
  98. mv data_in_${hemi}-${tag}.nc data_in_smooth0_${hemi}-${tag}.nc
  99. for jsmooth in `seq 1 $nbsmooth`
  100. do
  101. cdo smooth9 data_in_smooth$(( $jsmooth - 1 ))_${hemi}-${tag}.nc \
  102. data_in_smooth${jsmooth}_${hemi}-${tag}.nc
  103. done
  104. mv data_in_smooth${jsmooth}_${hemi}-${tag}.nc data_in_smooth_${hemi}-${tag}.nc
  105. fi # if smoothing is necessary
  106. # Interpolation of land-sea mask
  107. sed -e "s/TTAARRGGEETT/${grid}/" \
  108. -e "s/HHEEMMII/${hemi}/" \
  109. -e "s/TTAAGG/${tag}/" \
  110. namelist_OSISAF-mask > namelist
  111. # ./sosie3.x
  112. # Since we just did an interpolation, the mask will not be sharp:
  113. # There will be values not equal to 1. Let's remask the result
  114. # The threshold is pretty arbitrary here, but to be conservative
  115. # we just ignore points different from one.
  116. # cdo eqc,1 tmask_OSISAF-${hemi}-${grid}_${tag}.nc OSISAF-${hemi}_mask_on_${grid}_${tag}.nc
  117. # 2. Interpolation of concentration
  118. sed -e "s/TTAARRGGEETT/${grid}/" \
  119. -e "s/HHEEMMII/${hemi}/" \
  120. -e "s/TTAAGG/${tag}/" \
  121. namelist_OSISAF-conc > namelist
  122. ./sosie3.x
  123. # Mask the interpolated ice concentration using the interpolated mask.
  124. # Also, put missing values returned by sosie (<0) to zero, so that
  125. # we'll be able to add northern and southern hemispheres later
  126. cdo setmisstoc,0 \
  127. -mul -selvar,at_i at_i_OSISAF-${hemi}-${grid}_${tag}.nc \
  128. -selvar,tmask OSISAF-${hemi}_mask_on_${grid}_${tag}.nc \
  129. at_i_OSISAF-${hemi}-${grid}_${tag}_masked.nc
  130. # 3. Interpolation of standard deviation
  131. #
  132. # This is a point to worry about, although there is not enough
  133. # at this stage to do better. Interpolation of second-order moments
  134. # should account for the fact that errors are correlated, however
  135. # we don't have this information from the OSI-SAF product.
  136. # The best we can do is to assume that these errors are not correlated
  137. # and can be interpolated as is.
  138. sed -e "s/TTAARRGGEETT/${grid}/" \
  139. -e "s/HHEEMMII/${hemi}/" \
  140. -e "s/TTAAGG/${tag}/" \
  141. namelist_OSISAF-error > namelist
  142. ./sosie3.x
  143. # Mask the interpolated error using the interpolated mask
  144. cdo setmisstoc,0 \
  145. -mul -selvar,error_at_i error_at_i_OSISAF-${hemi}-${grid}_${tag}.nc \
  146. -selvar,tmask OSISAF-${hemi}_mask_on_${grid}_${tag}.nc \
  147. error_at_i_OSISAF-${hemi}-${grid}_${tag}_masked.nc
  148. done # for each hemisphere
  149. # Merge North and South data in one file
  150. for var in at_i error_at_i
  151. do
  152. ncbo -O -F -v ${var} --op_typ=add ${var}_OSISAF-nh-${grid}_${tag}_masked.nc \
  153. ${var}_OSISAF-sh-${grid}_${tag}_masked.nc \
  154. ${var}_OSISAF-${grid}_${tag}.nc
  155. done
  156. # Dump errors into concentration files
  157. ncks -F -A -v error_at_i error_at_i_OSISAF-${grid}_${tag}.nc at_i_OSISAF-${grid}_${tag}.nc
  158. ncrename -v at_i,sic -v error_at_i,error_sic at_i_OSISAF-${grid}_${tag}.nc
  159. mv at_i_OSISAF-${grid}_${tag}.nc $outdir/sic-${grid}/
  160. # Do a bit of cleaning here!
  161. # rm -f at_i_OSISAF-?h-${grid}_${tag}_masked.nc \
  162. # error_at_i_OSISAF-?h-${grid}_${tag}_masked.nc \
  163. # error_at_i_OSISAF-?h-${grid}_${tag}_masked.nc \
  164. # error_at_i_OSISAF-${grid}_${tag}.nc \
  165. # OSISAF-?h_mask_on_${grid}_${tag}.nc \
  166. # error_at_i_OSISAF-?h-${grid}_${tag}.nc \
  167. # at_i_OSISAF-?h-${grid}_${tag}.nc \
  168. # tmask_OSISAF-?h-${grid}_${tag}.nc \
  169. # data_in_smooth*${tag}.nc \
  170. # mask_in_?h-${tag}.nc
  171. else
  172. echo "Only one file was found for the time stamp $tag"
  173. echo "This is not coded yet"
  174. fi # if there are two files
  175. done # for each file of the year
  176. done # for each year