calculate_biases.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. set -u
  3. # This script takes ORAS5 and EC-Earth historical ocean temperature and salinity conditions and calculates biases from them.
  4. # Author: D. Verfaillie
  5. # Inputs
  6. in_folder="/storepelican/dverfail/bsc/anom_bias"
  7. oras5_file="ORAS5_preinterp_opa1_grid_T_1985-2014"
  8. histo_1m_thetao="thetao_Omon_EC-Earth3_historical_ensmean_gn_198501-201412"
  9. histo_1m_so="so_Omon_EC-Earth3_historical_ensmean_gn_198501-201412"
  10. # Prepare ORAS5 file to have the same grid and format as the EC-Earth files
  11. module --force purge
  12. module load releases/2020b
  13. module load noarch
  14. module load NCO
  15. module load CDO
  16. cd ${in_folder}/"oras5_clim"
  17. cdo remapbil,${in_folder}/oras5_clim/ECEarth_grid_T_new.grid ${oras5_file}.nc ${oras5_file}_remapped.nc
  18. ncrename -O -d time_counter,time -d x,i -d y,j -d nvertex,vertices -d deptht,lev -v time_counter,time -v nav_lon,longitude -v nav_lat,latitude -v nav_lon_bnds,longitude_bnds -v nav_lat_bnds,latitude_bnds -v deptht,lev -v conservative_temperature,thetao -v absolute_salinity,so ${oras5_file}_remapped.nc
  19. ncap2 -O -s 'defdim("bnds",2);make_bounds(lev,$bnds,"lev_bnds");' ${oras5_file}_remapped.nc ${oras5_file}_remapped_bounds.nc
  20. ncks -A -v i,j,lev_bnds ../histo_clim/${histo_1m_thetao}.nc ${oras5_file}_remapped_bounds.nc
  21. ncap2 -s 'lev=double(lev); lev_bnds=double(lev_bnds); longitude=float(longitude); longitude_bnds=float(longitude_bnds); latitude=float(latitude); latitude_bnds=float(latitude_bnds);' ${oras5_file}_remapped_bounds.nc ${oras5_file}_remapped_bounds_reformatted.nc
  22. ncks -O -x -v so,sossheig ${oras5_file}_remapped_bounds_reformatted.nc thetao_ORAS5_preinterp_opa1_grid_T_1985-2014.nc
  23. ncks -O -x -v thetao,sossheig ${oras5_file}_remapped_bounds_reformatted.nc so_ORAS5_preinterp_opa1_grid_T_1985-2014.nc
  24. # Calculate monthly and climatological biases: histo - oras5 (these biases will then have to be SUBSTRACTED from the hindcasts)
  25. ncdiff ../histo_clim/${histo_1m_so}.nc thetao_ORAS5_preinterp_opa1_grid_T_1985-2014.nc ../bias_histo-oras5/thetao_bias_1985-2014_1m.nc
  26. ncdiff ../histo_clim/${histo_1m_thetao}.nc so_ORAS5_preinterp_opa1_grid_T_1985-2014.nc ../bias_histo-oras5/so_bias_1985-2014_1m.nc
  27. cd ${in_folder}/bias_histo-oras5
  28. cdo ymonmean thetao_bias_1985-2014_1m.nc thetao_bias_1985-2014_Mm.nc
  29. cdo ymonmean so_bias_1985-2014_1m.nc so_bias_1985-2014_Mm.nc
  30. # Reformat the bias files to have same format as EC-Earth hindcast ocean temperature and salinity files
  31. ncrename -O -d time,time_counter -d i,x -d j,y -d vertices,nvertex -d lev,olevel -d bnds,axis_nbounds -v time,time_counter -v time_bnds,time_counter_bounds -v latitude,nav_lat -v latitude_bnds,bounds_nav_lat -v longitude,nav_lon -v longitude_bnds,bounds_nav_lon -v lev,olevel -v lev_bnds,olevel_bounds thetao_bias_1985-2014_Mm.nc thetao_bias_1985-2014_Mm_reformatted.nc
  32. ncrename -O -d time,time_counter -d i,x -d j,y -d vertices,nvertex -d lev,olevel -d bnds,axis_nbounds -v time,time_counter -v time_bnds,time_counter_bounds -v latitude,nav_lat -v latitude_bnds,bounds_nav_lat -v longitude,nav_lon -v longitude_bnds,bounds_nav_lon -v lev,olevel -v lev_bnds,olevel_bounds so_bias_1985-2014_Mm.nc so_bias_1985-2014_Mm_reformatted.nc