Changeset 2427


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

Move common functions to common module

Location:
TOOLS/ConsoGENCMIP6
Files:
5 edited

Legend:

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

    r2421 r2427  
    9696  os.chdir(current_dir) 
    9797  return res 
     98 
     99 
     100######################################## 
     101def get_input_files(dir_data, file_list): 
     102  """ 
     103  """ 
     104  res = [] 
     105 
     106  for filename in file_list: 
     107    res.append(get_last_file(dir_data, filename)) 
     108 
     109  if None in res: 
     110    print("\nMissing one or more input files, we stop.") 
     111    for f_in, f_out in zip(file_list, res): 
     112      print("=> {}: {}".format(f_in, f_out)) 
     113    exit(1) 
     114 
     115  return res 
     116 
     117 
     118######################################## 
     119def plot_save(img_in, img_out, title): 
     120  """ 
     121  """ 
     122  from matplotlib.backends.backend_pdf import PdfPages 
     123 
     124  dpi = 200. 
     125 
     126  # img_in  = os.path.join(DIR["PLOT"], "{}.pdf".format(img_name)) 
     127 
     128  with PdfPages(img_in) as pdf: 
     129    pdf.savefig(dpi=dpi) 
     130 
     131    # pdf file's metadata 
     132    d = pdf.infodict() 
     133    d["Title"]   = title 
     134    d["Author"]  = os.path.basename(__file__) 
     135    # d["Subject"] = "Time spent over specific commands during create_ts \ 
     136    #                 jobs at IDRIS and four configurations at TGCC" 
     137    # d["Keywords"] = "bench create_ts TGCC IDRIS ncrcat" 
     138    # d["CreationDate"] = dt.datetime(2009, 11, 13) 
     139    # d["ModDate"] = dt.datetime.today() 
     140 
     141  if os.path.isdir(DIR["SAVEPLOT"]): 
     142    # img_out = os.path.join(DIR["SAVEPLOT"], 
     143    #                        "{}_{}.pdf".format(img_name, suffix)) 
     144    shutil.copy(img_in, img_out) 
    98145 
    99146 
  • 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 ... 
  • 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) 
  • TOOLS/ConsoGENCMIP6/bin/plot_store.py

    r2425 r2427  
    4040  #--------------------------------------- 
    4141  def fill_data(self, filein): 
    42     data = np.genfromtxt( 
    43       filein, 
    44       skip_header=1, 
    45       converters={0: string_to_date, 
    46                   1: str, 
    47                   2: string_to_size_unit, 
    48                   3: str}, 
    49       missing_values="nan", 
    50     ) 
     42    """ 
     43    """ 
     44    try: 
     45      data = np.genfromtxt( 
     46        filein, 
     47        skip_header=1, 
     48        converters={0: string_to_date, 
     49                    1: str, 
     50                    2: string_to_size_unit, 
     51                    3: str}, 
     52        missing_values="nan", 
     53      ) 
     54    except: 
     55      print("Empty file {}".format(filein)) 
     56      exit(1) 
    5157 
    5258    for date, login, dirsize, dirname in data: 
     
    161167  plt.figtext(x=0.95, y=0.93, s=tot_label, backgroundcolor="linen", 
    162168              ha="right", va="bottom", fontsize="small") 
    163  
    164  
    165 ######################################## 
    166 def plot_save(img_name): 
    167   """ 
    168   """ 
    169   dpi = 200. 
    170  
    171   with PdfPages(img_name) as pdf: 
    172     pdf.savefig(dpi=dpi) 
    173  
    174     # pdf file's metadata 
    175     d = pdf.infodict() 
    176     d["Title"]   = "Occupation GENCMIP6 sur STORE par login" 
    177     d["Author"]  = "plot_bilan.py" 
    178     # d["Subject"] = "Time spent over specific commands during create_ts \ 
    179     #                 jobs at IDRIS and four configurations at TGCC" 
    180     # d["Keywords"] = "bench create_ts TGCC IDRIS ncrcat" 
    181     # d["CreationDate"] = dt.datetime(2009, 11, 13) 
    182     # d["ModDate"] = dt.datetime.today() 
    183169 
    184170 
     
    220206 
    221207  import matplotlib.pyplot as plt 
    222   from matplotlib.backends.backend_pdf import PdfPages 
     208  # from matplotlib.backends.backend_pdf import PdfPages 
    223209 
    224210  if not args.show: 
     
    227213  # ... Files and directories ... 
    228214  # ----------------------------- 
    229   file_param = get_last_file(DIR["SAVE"], OUT["PARAM"]) 
    230   file_utheo = get_last_file(DIR["SAVE"], OUT["UTHEO"]) 
    231   file_store = get_last_file(DIR["SAVE"], OUT["STORE"]) 
    232   img_name = "bilan.pdf" 
     215  (file_param, file_utheo, file_data) = \ 
     216      get_input_files(DIR["SAVEDATA"], 
     217                      [OUT["PARAM"], OUT["UTHEO"], OUT["STORE"]]) 
     218 
     219  img_name = "store" 
     220  today = os.path.basename(file_param).strip(OUT["PARAM"]) 
    233221 
    234222  if args.verbose: 
    235223    print(file_param) 
    236224    print(file_utheo) 
    237     print(file_store) 
     225    print(file_data) 
    238226    print(img_name) 
     227    print(today) 
    239228 
    240229  # .. Get project info .. 
     
    247236  # ======================= 
    248237  stores = StoreDict() 
    249   stores.fill_data(file_store) 
     238  stores.fill_data(file_data) 
    250239 
    251240  # .. Extract data depending on C.L. arguments .. 
     
    301290  # ... Save figure ... 
    302291  # ------------------- 
    303   plot_save(os.path.join(DIR["PLOT"], img_name)) 
     292  plot_save(img_name, today, "Occupation GENCMIP6 sur STORE par login") 
    304293 
    305294  # ... Publish figure on dods ... 
     
    311300    plt.show() 
    312301 
    313   exit() 
     302  exit(0) 
  • TOOLS/ConsoGENCMIP6/launch_conso.sh

    r2424 r2427  
    2323# Main script to get data 
    2424# ======================= 
    25 bin/conso_gencmip6.py 
     25script="conso_gencmip6" 
     26printf "${script}\n" 
     27echo "--------------------" 
     28bin/${script}.py 
     29rc=$? 
     30if [ ${rc} -ne 0 ] ; then 
     31  echo "${script} terminated abnormally" 
     32  exit 
     33else 
     34  echo "${script} OK" 
     35fi 
    2636 
    2737# Plot daily consumption 
     
    2939# -f : plot the whole period of the project 
    3040# -d : copy plot on dods 
    31 bin/plot_bilan.py -fd 
     41script="plot_bilan" 
     42printf "\n${script}\n" 
     43echo "--------------------" 
     44bin/${script}.py -fd 
     45rc=$? 
     46if [ ${rc} -ne 0 ] ; then 
     47  echo "${script} terminated abnormally" 
     48else 
     49  echo "${script} OK" 
     50fi 
     51 
     52script="plot_login" 
     53printf "\n${script}\n" 
     54echo "--------------------" 
     55bin/${script}.py -d 
     56rc=$? 
     57if [ ${rc} -ne 0 ] ; then 
     58  echo "${script} terminated abnormally" 
     59else 
     60  echo "${script} OK" 
     61fi 
     62 
     63script="plot_store" 
     64printf "\n${script}\n" 
     65echo "--------------------" 
     66bin/${script}.py -d 
     67rc=$? 
     68if [ ${rc} -ne 0 ] ; then 
     69  echo "${script} terminated abnormally" 
     70else 
     71  echo "${script} OK" 
     72fi 
     73 
     74printf "\nEnd of script OK\n" 
Note: See TracChangeset for help on using the changeset viewer.