calculate_anomalies_Jan.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. set -u
  3. # This script takes EC-Earth hindcast and historical ocean temperature and salinity conditions and calculates anomalies for January 1985 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. # Calculate climatological ORAS5 reference
  9. module --force purge
  10. module load releases/2020b
  11. module load noarch
  12. module load NCO
  13. module load CDO
  14. cd ${in_folder}/"oras5_clim"
  15. cdo ymonmean ${oras5_file}.nc ${oras5_file}_Mm.nc
  16. # Extract January 1985 from ORAS5 file and month of January from climatological reference
  17. ncks -d time_counter,0 ${oras5_file}.nc ORAS5_preinterp_opa1_grid_T_Jan1985.nc
  18. ncks -d time_counter,0 ${oras5_file}_Mm.nc ${oras5_file}_Mm_Jan.nc
  19. # Calculate anomalies: Jan 1985 -climatological ref (these anomalies will then have to be ADDED to the PARASO restarts)
  20. ncdiff -v conservative_temperature ORAS5_preinterp_opa1_grid_T_Jan1985.nc ${oras5_file}_Mm_Jan.nc ../anomalies/thetao_anomaly_3D_Jan_1985.nc
  21. ncdiff -v absolute_salinity ORAS5_preinterp_opa1_grid_T_Jan1985.nc ${oras5_file}_Mm_Jan.nc ../anomalies/so_anomaly_3D_Jan_1985.nc
  22. # Extract anomalies for the surface only
  23. cd ${in_folder}/anomalies
  24. ncks -d deptht,0 thetao_anomaly_3D_Jan_1985.nc tos_anomaly_2D_Jan_1985.nc
  25. ncks -d deptht,0 so_anomaly_3D_Jan_1985.nc sos_anomaly_2D_Jan_1985.nc
  26. ncwa -O -a deptht tos_anomaly_2D_Jan_1985.nc tos_anomaly_2D_Jan_1985.nc
  27. ncwa -O -a deptht sos_anomaly_2D_Jan_1985.nc sos_anomaly_2D_Jan_1985.nc
  28. ncks -O -x -v deptht tos_anomaly_2D_Jan_1985.nc tos_anomaly_2D_Jan_1985.nc
  29. ncks -O -x -v deptht sos_anomaly_2D_Jan_1985.nc sos_anomaly_2D_Jan_1985.nc
  30. # Reformat anomaly files to have the same format as the PARASO restart files
  31. ncrename -O -d time_counter,time -v lat,nav_lat -v lon,nav_lon -v conservative_temperature,sst_m tos_anomaly_2D_Jan_1985.nc
  32. ncrename -O -d time_counter,time -v lat,nav_lat -v lon,nav_lon -v absolute_salinity,sss_m sos_anomaly_2D_Jan_1985.nc
  33. ncrename -O -d time_counter,time -d deptht,z -v deptht,nav_lev -v lat,nav_lat -v lon,nav_lon -v conservative_temperature,tb thetao_anomaly_3D_Jan_1985.nc
  34. ncrename -O -d time_counter,time -d deptht,z -v deptht,nav_lev -v lat,nav_lat -v lon,nav_lon -v absolute_salinity,sb so_anomaly_3D_Jan_1985.nc
  35. cp tos_anomaly_2D_Jan_1985.nc tos_anomaly_2D_Jan_1985_reformatted.nc
  36. cp sos_anomaly_2D_Jan_1985.nc sos_anomaly_2D_Jan_1985_reformatted.nc
  37. ncap2 -s 'tn=tb' thetao_anomaly_3D_Jan_1985.nc thetao_anomaly_3D_Jan_1985_reformatted.nc
  38. ncap2 -s 'sn=sb' so_anomaly_3D_Jan_1985.nc so_anomaly_3D_Jan_1985_reformatted.nc
  39. # Combine all anomaly files into a single one
  40. cp so_anomaly_3D_Jan_1985_reformatted.nc all_anomalies_Jan_1985.nc
  41. ncks -A tos_anomaly_2D_Jan_1985_reformatted.nc sos_anomaly_2D_Jan_1985_reformatted.nc
  42. ncks -A sos_anomaly_2D_Jan_1985_reformatted.nc thetao_anomaly_3D_Jan_1985_reformatted.nc
  43. ncks -A thetao_anomaly_3D_Jan_1985_reformatted.nc all_anomalies_Jan_1985.nc
  44. ncap2 -s 'nav_lat=float(nav_lat); lat_bnds=float(lat_bnds); nav_lon=float(nav_lon); lon_bnds=float(lon_bnds); sn=double(sn); sb=double(sb); sss_m=double(sss_m); sst_m=double(sst_m); tb=double(tb); tn=double(tn);' all_anomalies_Jan_1985.nc all_anomalies_Jan_1985_reformatted.nc