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. #
  16. #cdo ymonmean ${oras5_file}.nc ${oras5_file}_Mm.nc
  17. #
  18. ## Extract January 1985 from ORAS5 file and month of January from climatological reference
  19. #ncks -d time_counter,0 ${oras5_file}.nc ORAS5_preinterp_opa1_grid_T_Jan1985.nc
  20. #ncks -d time_counter,0 ${oras5_file}_Mm.nc ${oras5_file}_Mm_Jan.nc
  21. #
  22. ## Calculate anomalies: Jan 1985 -climatological ref (these anomalies will then have to be ADDED to the PARASO restarts)
  23. #ncdiff -v conservative_temperature ORAS5_preinterp_opa1_grid_T_Jan1985.nc ${oras5_file}_Mm_Jan.nc ../anomalies/thetao_anomaly_3D_Jan_1985.nc
  24. #ncdiff -v absolute_salinity ORAS5_preinterp_opa1_grid_T_Jan1985.nc ${oras5_file}_Mm_Jan.nc ../anomalies/so_anomaly_3D_Jan_1985.nc
  25. #
  26. # Extract anomalies for the surface only
  27. cd ${in_folder}/anomalies
  28. #ncks -d deptht,0 thetao_anomaly_3D_Jan_1985.nc tos_anomaly_2D_Jan_1985.nc
  29. #ncks -d deptht,0 so_anomaly_3D_Jan_1985.nc sos_anomaly_2D_Jan_1985.nc
  30. #ncwa -O -a deptht tos_anomaly_2D_Jan_1985.nc tos_anomaly_2D_Jan_1985.nc
  31. #ncwa -O -a deptht sos_anomaly_2D_Jan_1985.nc sos_anomaly_2D_Jan_1985.nc
  32. #ncks -O -x -v deptht tos_anomaly_2D_Jan_1985.nc tos_anomaly_2D_Jan_1985.nc
  33. #ncks -O -x -v deptht sos_anomaly_2D_Jan_1985.nc sos_anomaly_2D_Jan_1985.nc
  34. #
  35. ## Reformat anomaly files to have the same format as the PARASO restart files
  36. #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
  37. #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
  38. #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
  39. #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
  40. #cp tos_anomaly_2D_Jan_1985.nc tos_anomaly_2D_Jan_1985_reformatted.nc
  41. #cp sos_anomaly_2D_Jan_1985.nc sos_anomaly_2D_Jan_1985_reformatted.nc
  42. #ncap2 -s 'tn=tb' thetao_anomaly_3D_Jan_1985.nc thetao_anomaly_3D_Jan_1985_reformatted.nc
  43. #ncap2 -s 'sn=sb' so_anomaly_3D_Jan_1985.nc so_anomaly_3D_Jan_1985_reformatted.nc
  44. #
  45. ## Combine all anomaly files into a single one
  46. #cp so_anomaly_3D_Jan_1985_reformatted.nc all_anomalies_Jan_1985.nc
  47. #ncks -A tos_anomaly_2D_Jan_1985_reformatted.nc sos_anomaly_2D_Jan_1985_reformatted.nc
  48. #ncks -A sos_anomaly_2D_Jan_1985_reformatted.nc thetao_anomaly_3D_Jan_1985_reformatted.nc
  49. #ncks -A thetao_anomaly_3D_Jan_1985_reformatted.nc all_anomalies_Jan_1985.nc
  50. 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