test2.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import os
  2. import sys
  3. import glob
  4. import subprocess
  5. # List of variable to save for output
  6. PLASIM_VAR = ['tas','hfls','hfss']
  7. OCEAN_VAR = ['heata','fldoa','sst']
  8. LSG_VAR = ['fluxhea', 'tbound']
  9. PLASIM_VAR = ['time','lat','lon'] + PLASIM_VAR
  10. OCEAN_VAR = ['time','lat','lon'] + OCEAN_VAR
  11. LSG_VAR = ['time','lat','lon','lev'] + LSG_VAR
  12. # check the python version
  13. if '3.6' not in sys.version:
  14. print("This script require Python 3.6 !")
  15. print("Try:")
  16. print("\n\tmodule load python3\n\n")
  17. print("and restart this script again.")
  18. print("Aborting...")
  19. sys.exit(1)
  20. #check if ecfs utils are loaded
  21. user = os.getenv('USER')
  22. try:
  23. dummy = subprocess.run(['els', 'ectmp:/'+user+'/'], check=True, stdout=subprocess.PIPE)
  24. except:
  25. print("This script require the ECFS toolchain to be loaded !")
  26. print("Try:")
  27. print("\n\tmodule load ecfs\n\n")
  28. print("and restart this script again.")
  29. print("Aborting...")
  30. sys.exit(1)
  31. #check if netcdf utils are loaded
  32. try:
  33. dummy = subprocess.run(['ncdump'], check=True, stderr=subprocess.PIPE)
  34. except:
  35. print("This script require NetCDF4 toolchain to be loaded !")
  36. print("Try:")
  37. print("\n\tmodule load netcdf4\n\n")
  38. print("and restart this script again.")
  39. print("Aborting...")
  40. sys.exit(1)
  41. home_dir = os.getenv("HOME")
  42. scratch_dir = os.getenv("SCRATCH")
  43. perm_dir = os.getenv("PERM")
  44. plasim_dir = home_dir + "/models/PLASIM/"
  45. if len(sys.argv) < 5:
  46. print('Bad arguments:', sys.argv)
  47. print('Usage:')
  48. print('\n\t python3 restart_ensemble_experiment.py where experiment ensemble_size number_of_years where_to_save\n')
  49. print('Arguments:\n')
  50. print('\twhere :\t\t\tWhere the experiment ensemble folders are located.')
  51. print('\texperiment :\t\tName of the experiment.')
  52. print('\tensemble_size :\t\tSize of the ensemble.')
  53. print('\tnumber_of_years :\tNumber of years simulated by one run of the experiment.')
  54. print('\twhere_to_save :\t\tOptional. Where to backup the previous run. If not provide, uses $PERM.')
  55. sys.exit(0)
  56. where = sys.argv[1]
  57. basedir = where.split('/')[-1]
  58. experiment = sys.argv[2]
  59. ensemble_size = int(sys.argv[3])
  60. restart_year_to_save = sys.argv[4]
  61. try:
  62. save = sys.argv[5]
  63. except:
  64. save = perm_dir
  65. save_light = save + "/"+experiment+"_light/"
  66. save += "/"+experiment+"/"