Ignore:
Timestamp:
03/02/15 17:43:15 (9 years ago)
Author:
labetoulle
Message:

Move common functions to common module

File:
1 edited

Legend:

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

    r2425 r2427  
    1010import os.path 
    1111import numpy as np 
    12 # import matplotlib.pyplot as plt 
    13 # from matplotlib.backends.backend_pdf import PdfPages 
    1412 
    1513# Application library imports 
     
    2624  #--------------------------------------- 
    2725  def fill_data(self, filein): 
    28     data = np.genfromtxt( 
    29       filein, 
    30       skip_header=1, 
    31       converters={0: string_to_date, 
    32                   1: str}, 
    33       missing_values="nan", 
    34     ) 
     26    """ 
     27    """ 
     28    try: 
     29      data = np.genfromtxt( 
     30        filein, 
     31        skip_header=1, 
     32        converters={0: string_to_date, 
     33                    1: str}, 
     34        missing_values="nan", 
     35      ) 
     36    except: 
     37      print("Empty file {}".format(filein)) 
     38      exit(1) 
    3539 
    3640    for date, login, conso in data: 
     
    8791  """ 
    8892  """ 
    89   print(ycoord) 
    90   print(consos) 
    91  
    9293  ax.barh(ycoord, consos, align="center", color="linen", 
    9394          linewidth=0.2, label="conso (heures)") 
     
    119120 
    120121 
    121 ######################################## 
    122 def plot_save(img_name): 
    123   """ 
    124   """ 
    125   dpi = 200. 
    126  
    127   with PdfPages(img_name) as pdf: 
    128     pdf.savefig(dpi=dpi) 
    129  
    130     # pdf file's metadata 
    131     d = pdf.infodict() 
    132     d["Title"]   = "Conso GENCMIP6 par login" 
    133     d["Author"]  = "plot_bilan.py" 
    134     # d["Subject"] = "Time spent over specific commands during create_ts \ 
    135     #                 jobs at IDRIS and four configurations at TGCC" 
    136     # d["Keywords"] = "bench create_ts TGCC IDRIS ncrcat" 
    137     # d["CreationDate"] = dt.datetime(2009, 11, 13) 
    138     # d["ModDate"] = dt.datetime.today() 
     122# ######################################## 
     123# def plot_save(img_name): 
     124#   """ 
     125#   """ 
     126#   dpi = 200. 
     127 
     128#   img_in  = os.path.join(DIR["PLOT"], "{}.pdf".format(img_name)) 
     129 
     130#   with PdfPages(img_in) as pdf: 
     131#     pdf.savefig(dpi=dpi) 
     132 
     133#     # pdf file's metadata 
     134#     d = pdf.infodict() 
     135#     d["Title"]   = "Conso GENCMIP6 par login" 
     136#     d["Author"]  = "plot_bilan.py" 
     137#     # d["Subject"] = "Time spent over specific commands during create_ts \ 
     138#     #                 jobs at IDRIS and four configurations at TGCC" 
     139#     # d["Keywords"] = "bench create_ts TGCC IDRIS ncrcat" 
     140#     # d["CreationDate"] = dt.datetime(2009, 11, 13) 
     141#     # d["ModDate"] = dt.datetime.today() 
     142 
     143#   if os.path.isdir(DIR["SAVEPLOT"]): 
     144#     img_out = os.path.join(DIR["SAVEPLOT"], 
     145#                            "{}_{}.pdf".format(img_name, today)) 
     146#     shutil.copy(img_in, img_out) 
    139147 
    140148 
     
    173181 
    174182  import matplotlib.pyplot as plt 
    175   from matplotlib.backends.backend_pdf import PdfPages 
     183  # from matplotlib.backends.backend_pdf import PdfPages 
    176184 
    177185  if not args.show: 
     
    180188  # ... Files and directories ... 
    181189  # ----------------------------- 
    182   file_param = get_last_file(DIR["SAVE"], OUT["PARAM"]) 
    183   file_utheo = get_last_file(DIR["SAVE"], OUT["UTHEO"]) 
    184   file_login = get_last_file(DIR["SAVE"], OUT["LOGIN"]) 
    185   img_name = "bilan.pdf" 
     190  (file_param, file_utheo, file_data) = \ 
     191      get_input_files(DIR["SAVEDATA"], 
     192                      [OUT["PARAM"], OUT["UTHEO"], OUT["LOGIN"]]) 
     193 
     194  img_name = "login" 
     195  today = os.path.basename(file_param).strip(OUT["PARAM"]) 
    186196 
    187197  if args.verbose: 
    188198    print(file_param) 
    189199    print(file_utheo) 
    190     print(file_login) 
     200    print(file_data) 
    191201    print(img_name) 
     202    print(today) 
    192203 
    193204  # .. Get project info .. 
     
    202213  # ---------------------- 
    203214  logins = LoginDict() 
    204   logins.fill_data(file_login) 
     215  logins.fill_data(file_data) 
    205216 
    206217  # .. Extract data depending on C.L. arguments .. 
     
    245256  # ... Save figure ... 
    246257  # ------------------- 
    247   plot_save(os.path.join(DIR["PLOT"], img_name)) 
     258  plot_save(img_name, today, "Conso GENCMIP6 par login") 
    248259 
    249260  # ... Publish figure on dods ... 
     
    255266    plt.show() 
    256267 
    257   exit() 
     268  exit(0) 
Note: See TracChangeset for help on using the changeset viewer.