OSISAF_to_ORCA.bash 8.7 KB

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