OSISAF_to_ORCA.bash 8.2 KB

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