Changeset 2417 for TOOLS


Ignore:
Timestamp:
02/25/15 15:18:06 (9 years ago)
Author:
labetoulle
Message:

put all path definitions in a seperate file

Location:
TOOLS/ConsoGENCMIP6/bin
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/ConsoGENCMIP6/bin/conso_gencmip6.py

    r2413 r2417  
    227227 
    228228######################################## 
    229 def write_store(filename, logins): 
     229def write_store(filename, today, logins): 
    230230  """ 
    231231  volume cree sur STORE 
     
    238238                  if conso > 0.) 
    239239 
    240   for login in items: 
    241     storedir = get_storedir(login) 
    242     if not storedir: 
    243       break 
    244     igcm_out = os.path.join(storedir, "IGCM_OUT") 
    245  
    246     for dirname in os.listdir(igcm_out): 
    247       print(dirname, get_dirsize(dirname)) 
     240  title_str  = "{:10s} {:10s} {:>7s} {:s}\n".format( 
     241                 "date", 
     242                 "login", 
     243                 "dirsize", 
     244                 "dirname", 
     245               ) 
     246 
     247  with open(filename, "w") as fileout: 
     248    if args.dryrun: 
     249      print(title_str.strip()) 
     250    else: 
     251      fileout.write(title_str) 
     252 
     253    for login in items: 
     254      if args.verbose: 
     255        print(login) 
     256      storedir = get_storedir(login) 
     257      if not storedir: 
     258        break 
     259      igcm_out = os.path.join(storedir, "IGCM_OUT") 
     260 
     261      for dirname in os.listdir(igcm_out): 
     262        print(dirname, get_dirsize(dirname)) 
     263 
     264        result_str = "{:%Y-%m-%d} {:10s} {:>7s} {:s}\n".format( 
     265                       today, 
     266                       login, 
     267                       get_dirsize(dirname), 
     268                       dirname 
     269                     ) 
     270        if args.dryrun: 
     271          print(result_str.strip()) 
     272        else: 
     273          fileout.write(result_str) 
     274 
     275 
     276######################################## 
     277def save_files(OUT, today): 
     278 
     279  if not args.dryrun: 
     280    suffix = "{:%Y%m%d}".format(today) 
     281    for filename in OUT.itervalues(): 
     282      filein  = os.path.join(DIR["DATA"], filename) 
     283      if os.path.isfile(filein): 
     284        fileout = os.path.join(DIR["SAVE"], 
     285                               "_".join((filename, suffix))) 
     286        shutil.copy(filein, fileout) 
    248287 
    249288 
     
    273312    print(args) 
    274313 
    275   # # Files and directories 
    276   # # ===================== 
    277   # if where_we_run() == "curie": 
    278   #   LOCAL_DIR = os.path.join( 
    279   #     "/ccc", 
    280   #     "cont003", 
    281   #     "home", 
    282   #     "dsm", 
    283   #     "p86ipsl", 
    284   #     "ConsoGENCMIP6", 
    285   #     "output" 
    286   #   ) 
    287   #   SAVE_DIR  = os.path.join( 
    288   #     "/ccc", 
    289   #     "work", 
    290   #     "cont003", 
    291   #     "dsm", 
    292   #     "p86ipsl", 
    293   #     "ConsoGENCMIP6", 
    294   #   ) 
    295   # # elif where_we_run() == "ipsl": 
    296   # #   LOCAL_DIR = os.path.join( 
    297   # #     "/home_local", 
    298   # #     "slipsl", 
    299   # #     "ConsoGENCMIP6", 
    300   # #     "output" 
    301   # #   ) 
    302   # #   SAVE_DIR  = os.path.join( 
    303   # #     "/home_local", 
    304   # #     "slipsl", 
    305   # #     "ConsoGENCMIP6", 
    306   # #     "save" 
    307   # #   ) 
    308   # else: 
    309   #   LOCAL_DIR = os.path.join( 
    310   #     "..", 
    311   #     "output" 
    312   #   ) 
    313   #   SAVE_DIR  = os.path.join( 
    314   #     "..", 
    315   #     "save" 
    316   #   ) 
    317  
    318   # LOCAL_DIR = os.path.abspath(LOCAL_DIR) 
    319   # SAVE_DIR  = os.path.abspath(SAVE_DIR) 
    320  
    321   OUT_PARAM = "OUT_CONSO_PARAM" 
    322   OUT_BILAN = "OUT_CONSO_BILAN" 
    323   OUT_UTHEO = "OUT_CONSO_UTHEO" 
    324   OUT_LOGIN = "OUT_CONSO_LOGIN" 
    325   OUT_STORE = "OUT_CONSO_STORE" 
    326   OUT_CCCMP = "ccc_myproject.dat" 
    327  
    328   if args.verbose: 
    329     # print(LOCAL_DIR) 
    330     # print(SAVE_DIR) 
     314  if args.bilan or args.login or args.store: 
     315    args.all = False 
     316 
     317  if args.verbose: 
    331318    print(DIR["DATA"]) 
    332319    print(DIR["SAVE"]) 
    333320 
    334321  (project, logins, today, total, utheo, ureal) = \ 
    335       parse_myproject(os.path.join(DIR["DATA"], OUT_CCCMP)) 
     322      parse_myproject(os.path.join(DIR["DATA"], OUT["CCCMP"])) 
    336323 
    337324  if args.verbose: 
     
    345332  # 1- Parametres du projet 
    346333  # ----------------------- 
    347   write_param(os.path.join(DIR["DATA"], OUT_PARAM), project) 
     334  if args.verbose: 
     335    print("=> write_param") 
     336 
     337  write_param(os.path.join(DIR["DATA"], OUT["PARAM"]), project) 
    348338 
    349339  # 2- Conso totale par jour 
    350340  # ------------------------ 
     341  if args.verbose: 
     342    print("=> write_bilan") 
     343 
    351344  write_bilan( 
    352     os.path.join(DIR["DATA"], OUT_BILAN), 
     345    os.path.join(DIR["DATA"], OUT["BILAN"]), 
    353346    today, 
    354347    total, 
     
    359352  # 2b- Conso théorique par jour 
    360353  # ---------------------------- 
    361   write_utheo(os.path.join(DIR["DATA"], OUT_UTHEO), today, utheo) 
     354  if args.verbose: 
     355    print("=> write_utheo") 
     356 
     357  write_utheo(os.path.join(DIR["DATA"], OUT["UTHEO"]), today, utheo) 
    362358 
    363359  # 3- Conso par login (HOME) 
    364360  # ------------------------- 
    365   write_login(os.path.join(DIR["DATA"], OUT_LOGIN), today, logins) 
     361  if args.verbose: 
     362    print("=> write_login") 
     363 
     364  write_login(os.path.join(DIR["DATA"], OUT["LOGIN"]), today, logins) 
    366365 
    367366  # 4- volume cree sur STORE 
    368367  # ------------------------ 
     368  if args.verbose: 
     369    print("=> write_store") 
     370 
    369371  # if where_we_run() == "curie": 
    370   #   write_store(os.path.join(DIR["DATA"], OUT_STORE)) 
    371   write_store(os.path.join(DIR["DATA"], OUT_STORE), logins) 
     372  #   write_store(os.path.join(DIR["DATA"], OUT["STORE"])) 
     373  write_store(os.path.join(DIR["DATA"], OUT["STORE"]), today, logins) 
    372374 
    373375  # Save files (on WORKDIR) 
    374376  # ======================= 
     377  if args.verbose: 
     378    print("=> Save files") 
     379 
    375380  if not args.dryrun: 
    376     suffix = "{:%Y%m%d}".format(today) 
    377     file_list = [ 
    378       OUT_PARAM, 
    379       OUT_BILAN, 
    380       OUT_UTHEO, 
    381       OUT_LOGIN, 
    382       OUT_STORE 
    383     ] 
    384     for filename in file_list: 
    385       filein  = os.path.join(DIR["DATA"], filename) 
    386       if os.path.isfile(filein): 
    387         fileout = os.path.join(DIR["SAVE"], "_".join((filename, suffix))) 
    388         shutil.copy(filein, fileout) 
     381    save_files(OUT, today) 
  • TOOLS/ConsoGENCMIP6/bin/gencmip6.py

    r2413 r2417  
    111111      missing_values="nan", 
    112112    ) 
     113    print(data) 
     114    print(type(data)) 
     115    print(data.shape) 
     116    print(data.size) 
    113117    dates, utheos = zip(*data) 
    114118 
  • TOOLS/ConsoGENCMIP6/bin/gencmip6_path.py.init

    r2413 r2417  
    2525if __name__ == "__main__": 
    2626  print(DIR, ) 
     272 
  • TOOLS/ConsoGENCMIP6/bin/plot_bilan.py

    r2413 r2417  
    99import os 
    1010import os.path 
    11 # import glob 
    1211import datetime as dt 
    1312import numpy as np 
     
    273272  # ... Files and directories ... 
    274273  # ----------------------------- 
    275   file_pattern = "OUT_CONSO_" 
    276   file_param = get_last_file(DIR["DATA"], file_pattern+"PARAM") 
    277   file_utheo = get_last_file(DIR["DATA"], file_pattern+"UTHEO") 
    278   file_bilan = get_last_file(DIR["DATA"], file_pattern+"BILAN") 
    279   file_login = get_last_file(DIR["DATA"], file_pattern+"LOGIN") 
    280   file_store = get_last_file(DIR["DATA"], file_pattern+"STORE") 
     274  file_param = get_last_file(DIR["DATA"], OUT["PARAM"]) 
     275  file_utheo = get_last_file(DIR["DATA"], OUT["UTHEO"]) 
     276  file_bilan = get_last_file(DIR["DATA"], OUT["BILAN"]) 
    281277  img_name = "bilan.pdf" 
    282278 
     
    285281    print(file_utheo) 
    286282    print(file_bilan) 
    287     print(file_login) 
    288     print(file_store) 
     283    print(img_name) 
    289284 
    290285  # .. Get project info .. 
     
    309304  # .. Extract data depending on C.L. arguments .. 
    310305  # ============================================== 
    311   # args.range = [ 
    312   #   string_to_date("2015-01-01"), 
    313   #   string_to_date("2015-01-31") 
    314   # ] 
    315   # args.full  = True 
    316306  if args.full: 
    317307    selected_items = bilan.get_items_in_full_range(args.inc) 
  • TOOLS/ConsoGENCMIP6/bin/plot_login.py

    r2413 r2417  
    99import os 
    1010import os.path 
    11 # import glob 
    12 # import datetime as dt 
    1311import numpy as np 
    1412import matplotlib.pyplot as plt 
     
    4543    self[login] = Login(date, login, conso) 
    4644 
    47   # #--------------------------------------- 
    48   # def get_items_in_full_range(self, inc=1): 
    49   #   """ 
    50   #   """ 
    51   #   items = (item for item in self.itervalues()) 
    52   #   items = sorted(items, key=lambda item: item.date) 
    53  
    54   #   return items[::inc] 
    55  
    5645  #--------------------------------------- 
    5746  def get_items(self): 
     
    8473  def __repr__(self): 
    8574    return "{} ({:.2}h)".format(self.login, self.conso) 
    86  
    87   # #--------------------------------------- 
    88   # def isfilled(self): 
    89   #   return self.filled 
    90  
    91   # #--------------------------------------- 
    92   # def fill(self): 
    93   #   self.filled = True 
    9475 
    9576 
     
    181162  # ... Files and directories ... 
    182163  # ----------------------------- 
    183   file_pattern = "OUT_CONSO_" 
    184   file_param = get_last_file(DIR["DATA"], file_pattern+"PARAM") 
    185   file_utheo = get_last_file(DIR["DATA"], file_pattern+"UTHEO") 
    186   file_bilan = get_last_file(DIR["DATA"], file_pattern+"BILAN") 
    187   file_login = get_last_file(DIR["DATA"], file_pattern+"LOGIN") 
    188   file_store = get_last_file(DIR["DATA"], file_pattern+"STORE") 
    189   img_name = "login.pdf" 
     164  file_param = get_last_file(DIR["DATA"], OUT["PARAM"]) 
     165  file_utheo = get_last_file(DIR["DATA"], OUT["UTHEO"]) 
     166  file_login = get_last_file(DIR["DATA"], OUT["LOGIN"]) 
     167  img_name = "bilan.pdf" 
     168 
     169  if args.verbose: 
     170    print(file_param) 
     171    print(file_utheo) 
     172    print(file_login) 
     173    print(img_name) 
    190174 
    191175  # .. Get project info .. 
     
    233217  plot_data(ax, ycoord, ylabels, consos) 
    234218 
    235   # # ... Tweak figure ... 
    236   # # -------------------- 
     219  # ... Tweak figure ... 
     220  # -------------------- 
    237221  title = "Consommation {} par login\n{:%d/%m/%Y}".format( 
    238222    gencmip6.project.upper(), 
  • TOOLS/ConsoGENCMIP6/bin/plot_store.py

    r2413 r2417  
    99import os 
    1010import os.path 
    11 # import glob 
    12 # import datetime as dt 
    1311import numpy as np 
    1412import matplotlib.pyplot as plt 
     
    213211  # ... Files and directories ... 
    214212  # ----------------------------- 
    215   file_pattern = "OUT_CONSO_" 
    216   file_param = get_last_file(DIR["DATA"], file_pattern+"PARAM") 
    217   file_utheo = get_last_file(DIR["DATA"], file_pattern+"UTHEO") 
    218   file_bilan = get_last_file(DIR["DATA"], file_pattern+"BILAN") 
    219   file_login = get_last_file(DIR["DATA"], file_pattern+"LOGIN") 
    220   file_store = get_last_file(DIR["DATA"], file_pattern+"STORE") 
    221   img_name = "store.pdf" 
     213  file_param = get_last_file(DIR["DATA"], OUT["PARAM"]) 
     214  file_utheo = get_last_file(DIR["DATA"], OUT["UTHEO"]) 
     215  file_store = get_last_file(DIR["DATA"], OUT["STORE"]) 
     216  img_name = "bilan.pdf" 
     217 
     218  if args.verbose: 
     219    print(file_param) 
     220    print(file_utheo) 
     221    print(file_store) 
     222    print(img_name) 
    222223 
    223224  # .. Get project info .. 
Note: See TracChangeset for help on using the changeset viewer.