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_bilan.py

    r2426 r2427  
    3939  #--------------------------------------- 
    4040  def fill_data(self, filein): 
    41     data = np.genfromtxt( 
    42       filein, 
    43       skip_header=1, 
    44       converters={0: string_to_date, 
    45                   1: string_to_float, 
    46                   2: string_to_percent, 
    47                   3: string_to_percent}, 
    48       missing_values="nan", 
    49     ) 
     41    """ 
     42    """ 
     43    try: 
     44      data = np.genfromtxt( 
     45        filein, 
     46        skip_header=1, 
     47        converters={0: string_to_date, 
     48                    1: string_to_float, 
     49                    2: string_to_percent, 
     50                    3: string_to_percent}, 
     51        missing_values="nan", 
     52      ) 
     53    except: 
     54      print("Empty file {}".format(filein)) 
     55      exit(1) 
    5056 
    5157    for date, conso, real_use, theo_use in data: 
     
    226232 
    227233 
    228 ######################################## 
    229 def plot_save(img_name): 
    230   """ 
    231   """ 
    232   dpi = 200. 
    233  
    234   with PdfPages(img_name) as pdf: 
    235     pdf.savefig(dpi=dpi) 
    236  
    237     # pdf file's metadata 
    238     d = pdf.infodict() 
    239     d["Title"]   = "Conso GENCMIP6" 
    240     d["Author"]  = "plot_bilan.py" 
    241     # d["Subject"] = "Time spent over specific commands during create_ts \ 
    242     #                 jobs at IDRIS and four configurations at TGCC" 
    243     # d["Keywords"] = "bench create_ts TGCC IDRIS ncrcat" 
    244     # d["CreationDate"] = dt.datetime(2009, 11, 13) 
    245     # d["ModDate"] = dt.datetime.today() 
     234# ######################################## 
     235# def plot_save(img_name, titre): 
     236#   """ 
     237#   """ 
     238#   dpi = 200. 
     239 
     240#   img_in  = os.path.join(DIR["PLOT"], "{}.pdf".format(img_name)) 
     241 
     242#   with PdfPages(img_in) as pdf: 
     243#     pdf.savefig(dpi=dpi) 
     244 
     245#     # pdf file's metadata 
     246#     d = pdf.infodict() 
     247#     d["Title"]   = titre 
     248#     d["Author"]  = os.path.basename(__file__) 
     249#     # d["Subject"] = "Time spent over specific commands during create_ts \ 
     250#     #                 jobs at IDRIS and four configurations at TGCC" 
     251#     # d["Keywords"] = "bench create_ts TGCC IDRIS ncrcat" 
     252#     # d["CreationDate"] = dt.datetime(2009, 11, 13) 
     253#     # d["ModDate"] = dt.datetime.today() 
     254 
     255#   if os.path.isdir(DIR["SAVEPLOT"]): 
     256#     img_out = os.path.join(DIR["SAVEPLOT"], 
     257#                            "{}_{}.pdf".format(img_name, today)) 
     258#     shutil.copy(img_in, img_out) 
    246259 
    247260 
     
    287300 
    288301  import matplotlib.pyplot as plt 
    289   from matplotlib.backends.backend_pdf import PdfPages 
     302  # from matplotlib.backends.backend_pdf import PdfPages 
    290303 
    291304  if not args.show: 
     
    294307  # ... Files and directories ... 
    295308  # ----------------------------- 
    296   file_param = get_last_file(DIR["SAVEDATA"], OUT["PARAM"]) 
    297   file_utheo = get_last_file(DIR["SAVEDATA"], OUT["UTHEO"]) 
    298   file_bilan = get_last_file(DIR["SAVEDATA"], OUT["BILAN"]) 
    299  
    300   if file_param is None or \ 
    301      file_utheo is None or \ 
    302      file_bilan is None: 
    303     print("Missing one or more input files, we stop.") 
    304     print("=> PARAM: {}\n=> UTHEO: {}\n=> BILAN: {}".format( 
    305               file_param, file_utheo, file_bilan) 
    306           ) 
    307     exit(1) 
     309  (file_param, file_utheo, file_data) = \ 
     310      get_input_files(DIR["SAVEDATA"], 
     311                      [OUT["PARAM"], OUT["UTHEO"], OUT["BILAN"]]) 
    308312 
    309313  img_name = "bilan" 
     
    313317    print(file_param) 
    314318    print(file_utheo) 
    315     print(file_bilan) 
     319    print(file_data) 
    316320    print(img_name) 
    317321    print(today) 
    318     print(DIR) 
    319     print(OUT) 
    320322 
    321323  # .. Get project info .. 
     
    333335  # ... Extract data from file ... 
    334336  # ------------------------------ 
    335   bilan.fill_data(file_bilan) 
     337  bilan.fill_data(file_data) 
    336338  # ... Compute theoratical use from known data  ... 
    337339  # ------------------------------------------------ 
     
    401403  # ... Save figure ... 
    402404  # ------------------- 
    403   # plot_save(os.path.join(DIR["PLOT"], img_name)) 
    404405  img_in  = os.path.join(DIR["PLOT"], "{}.pdf".format(img_name)) 
    405   plot_save(img_in) 
    406   if os.path.isdir(DIR["SAVEPLOT"]): 
    407     img_out = os.path.join(DIR["SAVEPLOT"], 
    408                            "{}_{}.pdf".format(img_name, today)) 
    409     shutil.copy(img_in, img_out) 
     406  img_out = os.path.join(DIR["SAVEPLOT"], 
     407                         "{}_{}.pdf".format(img_name, today)) 
     408 
     409  plot_save(img_in, img_out, "Conso GENCMIP6") 
    410410 
    411411  # ... Publish figure on dods ... 
Note: See TracChangeset for help on using the changeset viewer.