Changeset 2437 for TOOLS


Ignore:
Timestamp:
03/13/15 16:21:21 (9 years ago)
Author:
labetoulle
Message:

Add plot_bilan_jobs.py and do some cleaning

Location:
TOOLS/ConsoGENCMIP6
Files:
1 added
9 edited

Legend:

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

    r2433 r2437  
    2222def get_storedir(login): 
    2323 
     24  print("get_storedir") 
     25 
    2426  command = ["ccc_home", "-A", "-u", login] 
    2527  try : 
    2628    res = subprocess.check_output(command) 
     29    print("res", res) 
    2730  except Exception as rc: 
    28     print(rc) 
     31    print("exception", rc) 
    2932    res = None 
    3033 
     
    134137 
    135138######################################## 
    136 def write_bilan(filename, today, total, ureal, utheo): 
     139def write_bilan(filename, today, total, ureal, utheo, run_mean, pen_mean, run_std, pen_std): 
    137140  """ 
    138141  Conso totale par jour 
     
    142145  """ 
    143146 
    144   title_str  = "{:10s} {:12s} {:11s} {:11s}\n".format( 
     147  title_str  = "{:10s} {:12s} {:11s} {:11s} {:13s} {:13s} {:13s} {:13s}\n".format( 
    145148                 "date", 
    146149                 "conso(hours)", 
    147150                 "real_use(%)", 
    148151                 "theo_use(%)", 
    149                ) 
    150   result_str = "{:%Y-%m-%d} {:12.2f} {:11.2f} {:11.2f}\n".format( 
     152                 "running(core)", 
     153                 "pending(core)", 
     154                 "run_std(core)", 
     155                 "pen_std(core)", 
     156               ) 
     157  str_fmt = "{:%Y-%m-%d} {:12.2f} {:11.2f} {:11.2f} {:13.2f} {:13.2f} {:13.2f} {:13.2f}\n" 
     158  result_str = str_fmt.format( 
    151159                 today, 
    152160                 total, 
    153161                 ureal, 
    154162                 utheo, 
     163                 run_mean, 
     164                 pen_mean, 
     165                 run_std, 
     166                 pen_std, 
    155167               ) 
    156168 
     
    285297 
    286298######################################## 
    287 def save_files(OUT, today): 
     299def save_files(file_list, today): 
    288300 
    289301  if not args.dryrun: 
    290302    suffix = "{:%Y%m%d}".format(today) 
    291     for filename in OUT.itervalues(): 
     303    for filename in file_list: 
    292304      filein  = os.path.join(DIR["DATA"], filename) 
    293305      if os.path.isfile(filein): 
     
    349361  # 2- Conso totale par jour 
    350362  # ------------------------ 
     363 
    351364  if args.verbose: 
    352365    print("=> write_bilan") 
     366 
     367  file_jobs = get_last_file( 
     368      DIR["SAVEDATA"], 
     369      "{}_{:%Y%m%d}".format(OUT["JOBS"], today) 
     370  ) 
     371  if args.verbose: 
     372    print(file_jobs) 
     373 
     374  run_mean = np.nan 
     375  pen_mean = np.nan 
     376  run_std  = np.nan 
     377  pen_std  = np.nan 
     378 
     379  if file_jobs: 
     380    try: 
     381      data = np.genfromtxt( 
     382        file_jobs, 
     383        skip_header=1, 
     384        converters={ 
     385          0: string_to_datetime, 
     386          1: int, 
     387          2: int, 
     388        }, 
     389        missing_values="nan", 
     390      ) 
     391    except Exception as rc: 
     392      print("Problem with file {} :\n{}".format(file_jobs, rc)) 
     393      exit(1) 
     394 
     395    if len(data) == 24: 
     396      run_mean = np.nanmean( 
     397          np.array([run for _, run, _ in data]) 
     398      ) 
     399      pen_mean = np.nanmean( 
     400          np.array([pen for _, _, pen in data]) 
     401      ) 
     402 
     403      run_std = np.nanstd( 
     404          np.array([run for _, run, _ in data]) 
     405      ) 
     406      pen_std = np.nanstd( 
     407          np.array([pen for _, _, pen in data]) 
     408      ) 
     409 
     410  if args.verbose: 
     411    print(run_mean, pen_mean, run_std, pen_std) 
    353412 
    354413  write_bilan( 
     
    357416    total, 
    358417    ureal, 
    359     utheo 
     418    utheo, 
     419    run_mean, 
     420    pen_mean, 
     421    run_std, 
     422    pen_std, 
    360423  ) 
    361424 
     
    379442    print("=> write_store") 
    380443 
    381   # if where_we_run() == "curie": 
    382   #   write_store(os.path.join(DIR["DATA"], OUT["STORE"])) 
    383   write_store(os.path.join(DIR["DATA"], OUT["STORE"]), today, logins) 
     444  if where_we_run() == "curie": 
     445    write_store(os.path.join(DIR["DATA"], OUT["STORE"]), today, logins) 
    384446 
    385447  # Save files (on WORKDIR) 
     
    388450    print("=> Save files") 
    389451  if not args.dryrun: 
    390     save_files(OUT, today) 
     452    file_list = [ 
     453        OUT["PARAM"], 
     454        OUT["BILAN"], 
     455        OUT["UTHEO"], 
     456        OUT["LOGIN"], 
     457        OUT["STORE"], 
     458        OUT["CCCMP"], 
     459    ] 
     460 
     461    save_files(file_list, today) 
    391462 
    392463  exit(0) 
  • TOOLS/ConsoGENCMIP6/bin/gencmip6.py

    r2433 r2437  
    1111import glob 
    1212import shutil 
     13import subprocess 
    1314import datetime as dt 
    1415import numpy as np 
     
    2627    return 
    2728 
    28   fileout = os.path.join(DIR["DODS"], os.path.basename(filein)) 
     29  basefile = os.path.basename(filein) 
     30 
     31  fileout = os.path.join(DIR["DODS"], basefile) 
     32  filepng = os.path.join(DIR["DODS"], "img", basefile.split(".")[0] + ".png") 
     33 
     34  # Copy file 
    2935  shutil.copy(filein, fileout) 
     36 
     37  # Convert it to png for web page 
     38  command = ["convert", "-density", "200", fileout, filepng] 
     39 
     40  try : 
     41    subprocess.call(command) 
     42  except Exception as rc : 
     43    print("Error in convert for {}:\n{}".format(fileout, rc)) 
    3044 
    3145  return 
  • TOOLS/ConsoGENCMIP6/bin/gencmip6_path.py.init

    r2425 r2437  
    1313 
    1414 
    15 ROOT_DIR = os.getcwd() 
     15ROOT_DIR = os.path.join(os.environ["HOME"], "ConsoGENCMIP6") 
    1616 
    1717# Common paths 
     
    2020  "ROOT": ROOT_DIR, 
    2121  "DATA": os.path.join(ROOT_DIR, "output"), 
    22   "SAVE": os.path.join(ROOT_DIR, "save"), 
     22  "SAVE": os.path.join(os.environ["CCCWORKDIR"], "ConsoGENCMIP6"), 
    2323  "PLOT": os.path.join(ROOT_DIR, "plot"), 
    2424  "DODS": None, 
     
    4242  "LOGIN": "OUT_CONSO_LOGIN", 
    4343  "STORE": "OUT_CONSO_STORE", 
    44   "CCCMP": "ccc_myproject.dat" 
     44  "CCCMP": "ccc_myproject.dat", 
     45  "JOBS":  "OUT_JOBS_PENDING", 
    4546} 
    4647 
  • TOOLS/ConsoGENCMIP6/bin/plot_bilan.py

    r2434 r2437  
    1818 
    1919######################################## 
    20 class BilanDict(dict): 
     20class DataDict(dict): 
    2121  #--------------------------------------- 
    2222  def __init__(self): 
     
    4545        filein, 
    4646        skip_header=1, 
    47         converters={0: string_to_date, 
    48                     1: string_to_float, 
    49                     2: string_to_percent, 
    50                     3: string_to_percent}, 
     47        converters={ 
     48          0: string_to_date, 
     49          1: string_to_float, 
     50          2: string_to_percent, 
     51          3: string_to_percent, 
     52          4: string_to_float, 
     53          5: string_to_float, 
     54          6: string_to_float, 
     55          7: string_to_float, 
     56        }, 
    5157        missing_values="nan", 
    5258      ) 
    53     except: 
    54       print("Empty file {}".format(filein)) 
     59    except Exception as rc: 
     60      print("Empty file {}:\n{}".format(filein, rc)) 
    5561      exit(1) 
    5662 
    57     for date, conso, real_use, theo_use in data: 
     63    for date, conso, real_use, theo_use, \ 
     64        run_mean, pen_mean, run_std, pen_std in data: 
    5865      if date in self: 
    59         self.add_item(date, conso, real_use, theo_use) 
     66        self.add_item( 
     67          date, 
     68          conso, 
     69          real_use, 
     70          theo_use, 
     71          run_mean, 
     72          pen_mean, 
     73          run_std, 
     74          pen_std, 
     75        ) 
    6076        self[date].fill() 
    6177 
    6278  #--------------------------------------- 
    6379  def add_item(self, date, conso=np.nan, 
    64                real_use=np.nan, theo_use=np.nan): 
    65     """ 
    66     """ 
    67     self[date] = Conso(date, conso, real_use, theo_use) 
     80               real_use=np.nan, theo_use=np.nan, 
     81               run_mean=np.nan, pen_mean=np.nan, 
     82               run_std=np.nan, pen_std=np.nan): 
     83    """ 
     84    """ 
     85    self[date] = Conso(date, conso, real_use, theo_use, 
     86                       run_mean, pen_mean, run_std, pen_std) 
    6887 
    6988  #--------------------------------------- 
     
    136155  #--------------------------------------- 
    137156  def __init__(self, date, conso=np.nan, 
    138                real_use=np.nan, theo_use=np.nan): 
     157               real_use=np.nan, theo_use=np.nan, 
     158               run_mean=np.nan, pen_mean=np.nan, 
     159               run_std=np.nan, pen_std=np.nan): 
    139160    self.date     = date 
    140161    self.conso    = conso 
     
    142163    self.theo_use = theo_use 
    143164    self.theo_equ = np.nan 
     165    self.run_mean = run_mean 
     166    self.pen_mean = pen_mean 
     167    self.run_std  = run_std 
     168    self.pen_std  = pen_std 
    144169    self.filled   = False 
    145170 
     
    167192 
    168193######################################## 
    169 def plot_data(ax_conso, ax_theo, xcoord, xlabels, 
    170               consos, conso_per_day, theo_uses, real_uses, theo_equs): 
     194def plot_data(ax_conso, ax_theo, xcoord, dates, 
     195              consos, theo_uses, real_uses, theo_equs, 
     196              run_mean, pen_mean, run_std, pen_std): 
    171197  """ 
    172198  """ 
     199  line_style = "-" 
    173200  if args.full: 
    174     line_style = "-" 
     201    line_width = 0.05 
     202  else: 
     203    # line_style = "+-" 
    175204    line_width = 0.1 
    176   else: 
    177     line_style = "+-" 
    178     line_width = 0.2 
    179  
    180   ax_conso.bar(xcoord, consos, align="center", color="linen", 
     205 
     206  ax_conso.bar(xcoord, consos, width=1, align="center", color="linen", 
    181207               linewidth=line_width, label="conso (heures)") 
    182   ax_conso.axhline(y=conso_per_day, color="blue", alpha=0.5, 
    183                    label="conso journaliÚre idéale (heures)") 
    184208 
    185209  ax_theo.plot(xcoord, theo_equs, "--", 
     
    188212  ax_theo.plot(xcoord, theo_uses, line_style, color="firebrick", 
    189213               linewidth=1, markersize=8, 
    190                # solid_capstyle="round", solid_joinstyle="round", 
     214               solid_capstyle="round", solid_joinstyle="round", 
    191215               label="conso théorique (%)") 
    192216  ax_theo.plot(xcoord, real_uses, line_style, color="forestgreen", 
    193217               linewidth=1, markersize=8, 
    194                # solid_capstyle="round", solid_joinstyle="round", 
     218               solid_capstyle="round", solid_joinstyle="round", 
    195219               label="conso réelle (%)") 
    196220 
    197221 
    198222######################################## 
    199 def plot_config(ax_conso, ax_theo, xcoord, xlabels, ymax, title, conso_per_day): 
     223def plot_config(fig, ax_conso, ax_theo, xcoord, dates, title, conso_per_day): 
    200224  """ 
    201225  """ 
     
    203227  # ------------------- 
    204228  # 1) Range 
     229  if args.max: 
     230    ymax = gencmip6.alloc 
     231  else: 
     232    ymax = np.nanmax(consos) + np.nanmax(consos)*.1 
     233 
    205234  xmin, xmax = xcoord[0]-1, xcoord[-1]+1 
    206235  ax_conso.set_xlim(xmin, xmax) 
     
    209238 
    210239  # 2) Ticks labels 
    211   inc_label = 7 if nb_items > 37 else 1 
     240  (date_beg, date_end) = (dates[0], dates[-1]) 
     241  date_fmt = "{:%d-%m}" 
     242 
     243  if date_end - date_beg > dt.timedelta(weeks=9): 
     244    maj_xticks = [x for x, d in zip(xcoord, dates) 
     245                     if d.weekday() == 0] 
     246    maj_xlabs  = [date_fmt.format(d) for d in dates 
     247                     if d.weekday() == 0] 
     248  else: 
     249    maj_xticks = [x for x, d in zip(xcoord, dates)] 
     250    maj_xlabs  = [date_fmt.format(d) for d in dates] 
     251 
    212252  ax_conso.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) 
     253 
    213254  ax_conso.set_xticks(xcoord, minor=True) 
    214   ax_conso.set_xticks(xcoord[::inc_label], minor=False) 
    215   ax_conso.set_xticklabels( 
    216     xlabels[::inc_label], rotation="45", size="x-small" 
    217   ) 
     255  ax_conso.set_xticks(maj_xticks, minor=False) 
     256  ax_conso.set_xticklabels(maj_xlabs, rotation="vertical", size="x-small") 
    218257 
    219258  yticks = list(ax_conso.get_yticks()) 
     
    221260  ax_conso.set_yticks(yticks) 
    222261 
     262  ax_conso.axhline(y=conso_per_day, color="blue", alpha=0.5, 
     263                   label="conso journaliÚre idéale (heures)") 
     264 
     265  for x, d in zip(xcoord, dates): 
     266    if d.weekday() == 0 and d.hour == 0: 
     267      ax_conso.axvline(x=x, color="black", alpha=0.5, 
     268                       linewidth=0.5, linestyle=":") 
     269 
    223270  # 3) Define axes title 
    224   ax_conso.set_ylabel("heures", fontweight="bold") 
    225   ax_theo.set_ylabel("%", fontweight="bold") 
     271  for ax, label in ( 
     272    (ax_conso, "heures"), 
     273    (ax_theo, "%"), 
     274  ): 
     275    ax.set_ylabel(label, fontweight="bold") 
     276    ax.tick_params(axis="y", labelsize="small") 
     277 
     278  # 4) Define plot size 
     279  fig.subplots_adjust( 
     280    left=0.08, 
     281    bottom=0.09, 
     282    right=0.93, 
     283    top=0.93, 
     284  ) 
    226285 
    227286  # ... Main title and legend ... 
    228287  # ----------------------------- 
    229   ax_conso.set_title(title, fontweight="bold", size="large") 
    230   ax_theo.legend(loc="upper right", fontsize="x-small", frameon=False) 
    231   ax_conso.legend(loc="upper left", fontsize="x-small", frameon=False) 
    232  
    233  
    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) 
     288  fig.suptitle(title, fontweight="bold", size="large") 
     289  for ax, loc in ( 
     290    (ax_conso, "upper left"), 
     291    (ax_theo, "upper right"), 
     292  ): 
     293    ax.legend(loc=loc, fontsize="x-small", frameon=False) 
    259294 
    260295 
     
    327362  gencmip6.get_date_init(file_utheo) 
    328363 
    329   # .. Fill in conso data .. 
    330   # ======================== 
     364  # .. Fill in data .. 
     365  # ================== 
    331366  # ... Initialization ... 
    332367  # ---------------------- 
    333   bilan = BilanDict() 
     368  bilan = DataDict() 
    334369  bilan.init_range(gencmip6.date_init, gencmip6.deadline) 
    335370  # ... Extract data from file ... 
     
    356391 
    357392  xcoord    = np.linspace(1, nb_items, num=nb_items) 
    358   xlabels   = ["{:%d-%m}".format(item.date) 
    359                for item in selected_items] 
     393  dates   = [item.date for item in selected_items] 
     394 
    360395  cumul     = np.array([item.conso for item in selected_items], 
    361396                        dtype=float) 
     
    374409                       dtype=float) 
    375410 
     411  run_mean = np.array([item.run_mean for item in selected_items], 
     412                       dtype=float) 
     413  pen_mean = np.array([item.pen_mean for item in selected_items], 
     414                       dtype=float) 
     415  run_std  = np.array([item.run_std for item in selected_items], 
     416                       dtype=float) 
     417  pen_std  = np.array([item.pen_std for item in selected_items], 
     418                       dtype=float) 
     419 
    376420  # .. Plot stuff .. 
    377421  # ================ 
     
    382426  # ... Plot data ... 
    383427  # ----------------- 
    384   plot_data(ax_conso, ax_theo, xcoord, xlabels, 
    385             consos, conso_per_day, theo_uses, real_uses, theo_equs) 
     428  plot_data(ax_conso, ax_theo, xcoord, dates, 
     429            consos, theo_uses, real_uses, theo_equs, 
     430            run_mean, pen_mean, run_std, pen_std) 
    386431 
    387432  # ... Tweak figure ... 
    388433  # -------------------- 
    389   if args.max: 
    390     ymax = gencmip6.alloc 
    391   else: 
    392     ymax = np.nanmax(consos) + np.nanmax(consos)*.1 
    393  
    394434  title = "Consommation {}\n({:%d/%m/%Y} - {:%d/%m/%Y})".format( 
    395435    gencmip6.project.upper(), 
     
    398438  ) 
    399439 
    400   plot_config(ax_conso, ax_theo, xcoord, xlabels, ymax, title, conso_per_day) 
     440  plot_config(fig, ax_conso, ax_theo, xcoord, dates, title, conso_per_day) 
    401441 
    402442  # ... Save figure ... 
  • TOOLS/ConsoGENCMIP6/bin/plot_jobs.py

    r2434 r2437  
    1818 
    1919######################################## 
    20 class BilanDict(dict): 
     20class DataDict(dict): 
    2121  #--------------------------------------- 
    2222  def __init__(self): 
     
    2727    """ 
    2828    """ 
    29     delta = date_end - date_beg 
    30  
    31     (deb, fin) = (0, delta.days+1) 
    32  
    33     dates = (date_beg + dt.timedelta(days=i) 
     29    # delta = date_end - date_beg 
     30    # delta = delta + dt.timedelta(days=1) 
     31    delta = date_end - date_beg + dt.timedelta(days=1) 
     32 
     33    (deb, fin) = (0, int(delta.total_seconds() / 3600)) 
     34 
     35    dates = (date_beg + dt.timedelta(hours=i) 
    3436             for i in xrange(deb, fin, inc)) 
    3537 
     
    3840 
    3941  #--------------------------------------- 
    40   def fill_data(self, filein): 
    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) 
    56  
    57     for date, conso, real_use, theo_use in data: 
    58       if date in self: 
    59         self.add_item(date, conso, real_use, theo_use) 
     42  def fill_data(self, file_list): 
     43    """ 
     44    """ 
     45    for filein in sorted(file_list): 
     46      try: 
     47        data = np.genfromtxt( 
     48          filein, 
     49          skip_header=1, 
     50          converters={ 
     51            0: string_to_datetime, 
     52            1: int, 
     53            2: int, 
     54          }, 
     55          missing_values="nan", 
     56        ) 
     57      except Exception as rc: 
     58        print("Problem with file {} :\n{}".format(filein, rc)) 
     59        exit(1) 
     60 
     61      if len(data) == 24: 
     62        run_mean = np.nanmean( 
     63            np.array([run for _, run, _ in data]) 
     64        ) 
     65        pen_mean = np.nanmean( 
     66            np.array([pen for _, _, pen in data]) 
     67        ) 
     68        run_std = np.nanstd( 
     69            np.array([run for _, run, _ in data]) 
     70        ) 
     71        pen_std = np.nanstd( 
     72            np.array([pen for _, _, pen in data]) 
     73        ) 
     74      else: 
     75        run_mean = np.nan 
     76        pen_mean = np.nan 
     77        run_std  = np.nan 
     78        pen_std  = np.nan 
     79 
     80      for date, run, pen in data: 
     81        if date.hour == 0: 
     82          self.add_item( 
     83            date, 
     84            run, 
     85            pen, 
     86            run_mean, 
     87            pen_mean, 
     88            run_std, 
     89            pen_std 
     90          ) 
     91        else: 
     92          self.add_item(date, run, pen) 
    6093        self[date].fill() 
    6194 
    6295  #--------------------------------------- 
    63   def add_item(self, date, conso=np.nan, 
    64                real_use=np.nan, theo_use=np.nan): 
    65     """ 
    66     """ 
    67     self[date] = Conso(date, conso, real_use, theo_use) 
    68  
    69   #--------------------------------------- 
    70   def theo_equation(self): 
    71     """ 
    72     """ 
    73     (dates, theo_uses) = \ 
    74       zip(*((item.date, item.theo_use) 
    75             for item in self.get_items_in_full_range())) 
    76  
    77     (idx_min, idx_max) = \ 
    78         (np.nanargmin(theo_uses), np.nanargmax(theo_uses)) 
    79  
    80     x1 = dates[idx_min].timetuple().tm_yday 
    81     x2 = dates[idx_max].timetuple().tm_yday 
    82  
    83     y1 = theo_uses[idx_min] 
    84     y2 = theo_uses[idx_max] 
    85  
    86     m = np.array([ 
    87       [x1, 1.], 
    88       [x2, 1.] 
    89     ], dtype="float") 
    90     n = np.array([ 
    91       y1, 
    92       y2 
    93     ], dtype="float") 
    94  
    95     try: 
    96       (a, b) = np.linalg.solve(m, n) 
    97     except np.linalg.linalg.LinAlgError: 
    98       (a, b) = (None, None) 
    99  
    100     if a and b: 
    101       for date in dates: 
    102         self[date].theo_equ = date.timetuple().tm_yday*a + b 
     96  def add_item(self, date, run=np.nan, pen=np.nan, 
     97               run_mean=np.nan, pen_mean=np.nan, 
     98               run_std=np.nan, pen_std=np.nan): 
     99    """ 
     100    """ 
     101    self[date] = Conso( 
     102      date, 
     103      run, 
     104      pen, 
     105      run_mean, 
     106      pen_mean, 
     107      run_std, 
     108      pen_std 
     109    ) 
    103110 
    104111  #--------------------------------------- 
     
    117124    """ 
    118125    """ 
    119     items = (item for item in self.itervalues()) 
     126    items = (item for item in self.itervalues() 
     127                   if item.date.hour == 0) 
    120128    items = sorted(items, key=lambda item: item.date) 
    121129 
     
    135143class Conso(object): 
    136144  #--------------------------------------- 
    137   def __init__(self, date, conso=np.nan, 
    138                real_use=np.nan, theo_use=np.nan): 
     145  def __init__(self, date, run=np.nan, pen=np.nan, 
     146               run_mean=np.nan, pen_mean=np.nan, 
     147               run_std=np.nan, pen_std=np.nan): 
     148 
    139149    self.date     = date 
    140     self.conso    = conso 
    141     self.real_use = real_use 
    142     self.theo_use = theo_use 
    143     self.theo_equ = np.nan 
     150    self.run      = run 
     151    self.pen      = pen 
     152    self.run_mean = run_mean 
     153    self.pen_mean = pen_mean 
     154    self.run_std  = run_std 
     155    self.pen_std  = pen_std 
    144156    self.filled   = False 
    145157 
    146158  #--------------------------------------- 
    147159  def __repr__(self): 
    148     return "{:.2f} ({:.2%})".format(self.conso, self.real_use) 
     160    return "R{:.0f} ({:.0f}/{:.0f}) P{:.0f} ({:.0f}/{:.0f})".format( 
     161      self.run, 
     162      self.run_mean, 
     163      self.run_std, 
     164      self.pen, 
     165      self.pen_mean, 
     166      self.pen_std, 
     167    ) 
    149168 
    150169  #--------------------------------------- 
     
    166185 
    167186######################################## 
    168 def plot_data(ax, xcoord, xlabels, run_jobs, pen_jobs, conso_per_day): 
     187def plot_data(ax, xcoord, dates, run_jobs, pen_jobs, run_std, pen_std): 
    169188  """ 
    170189  """ 
    171190  line_width = 0. 
    172  
    173   ax.bar(xcoord, run_jobs, align="center", color="lightgreen", 
    174          linewidth=line_width, label="jobs running") 
    175   ax.bar(xcoord, pen_jobs, bottom=run_jobs, align="center", 
    176          color="indianred", linewidth=line_width, label="jobs pending") 
    177  
    178   ax.axhline(y=conso_per_day, color="blue", alpha=0.5, 
    179              label="conso journaliÚre idéale") 
    180  
    181  
    182 ######################################## 
    183 def plot_config(ax, xcoord, xlabels, title, conso_per_day): 
     191  width = 1.05 
     192 
     193  ax.bar(xcoord, run_jobs, width=width, yerr=run_std/2., 
     194         linewidth=line_width, align="center", 
     195         color="lightgreen", ecolor="green", antialiased=True, 
     196         label="jobs running") 
     197  ax.bar(xcoord, pen_jobs, bottom=run_jobs, width=width, 
     198         linewidth=line_width, align="center", 
     199         color="indianred", antialiased=True, 
     200         label="jobs pending") 
     201 
     202 
     203######################################## 
     204def plot_config(fig, ax, xcoord, dates, title, conso_per_day): 
    184205  """ 
    185206  """ 
     
    189210  xmin, xmax = xcoord[0]-1, xcoord[-1]+1 
    190211  ax.set_xlim(xmin, xmax) 
    191   # ax.set_ylim(0., ymax) 
    192212 
    193213  # 2) Ticks labels 
    194   # inc_label = 12 
    195   # ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) 
    196   xcoord_maj = [x for x, l in zip(xcoord, xlabels) 
    197                    if l.hour == 0 or l.hour == 12] 
    198   xlabels_maj = ["{:%d-%m %Hh}".format(l) for l in xlabels 
    199                  if l.hour == 0 or l.hour == 12] 
     214  (date_beg, date_end) = (dates[0], dates[-1]) 
     215 
     216  if date_end - date_beg > dt.timedelta(weeks=9): 
     217    date_fmt = "{:%d-%m}" 
     218    maj_xticks = [x for x, d in zip(xcoord, dates) 
     219                     if d.weekday() == 0 and d.hour == 0] 
     220    maj_xlabs  = [date_fmt.format(d) for d in dates 
     221                     if d.weekday() == 0 and d.hour == 0] 
     222  else: 
     223    date_fmt = "{:%d-%m %Hh}" 
     224    maj_xticks = [x for x, d in zip(xcoord, dates) 
     225                     if d.hour == 0 or d.hour == 12] 
     226    maj_xlabs  = [date_fmt.format(d) for d in dates 
     227                     if d.hour == 0 or d.hour == 12] 
     228 
    200229  ax.set_xticks(xcoord, minor=True) 
    201   ax.set_xticks(xcoord_maj, minor=False) 
    202   ax.set_xticklabels(xlabels_maj, rotation="vertical", size="x-small") 
     230  ax.set_xticks(maj_xticks, minor=False) 
     231  ax.set_xticklabels(maj_xlabs, rotation="vertical", size="x-small") 
    203232 
    204233  yticks = list(ax.get_yticks()) 
     
    206235  ax.set_yticks(yticks) 
    207236 
     237  ax.axhline(y=conso_per_day, color="blue", alpha=0.5, 
     238             label="conso journaliÚre idéale") 
     239 
     240  for x, d in zip(xcoord, dates): 
     241    if d.weekday() == 0 and d.hour == 0: 
     242      ax.axvline(x=x, color="black", linewidth=1., linestyle=":") 
     243 
    208244  # 3) Define axes title 
    209245  ax.set_ylabel("cœurs", fontweight="bold") 
     246  ax.tick_params(axis="y", labelsize="small") 
     247 
     248  # 4) Define plot size 
     249  fig.subplots_adjust( 
     250    left=0.08, 
     251    bottom=0.09, 
     252    right=0.93, 
     253    top=0.93, 
     254  ) 
    210255 
    211256  # ... Main title and legend ... 
    212257  # ----------------------------- 
    213   ax.set_title(title, fontweight="bold", size="large") 
    214   ax.legend(loc="best", fontsize="x-small", frameon=False) 
     258  fig.suptitle(title, fontweight="bold", size="large") 
     259  ax.legend(loc="upper right", fontsize="x-small", frameon=False) 
    215260 
    216261 
     
    220265  parser.add_argument("-v", "--verbose", action="store_true", 
    221266                      help="verbose mode") 
     267  parser.add_argument("-f", "--full", action="store_true", 
     268                      help="plot the whole period") 
     269  parser.add_argument("-i", "--increment", action="store", 
     270                      type=int, default=1, dest="inc", 
     271                      help="sampling increment") 
     272  parser.add_argument("-r", "--range", action="store", nargs=2, 
     273                      type=string_to_date, 
     274                      help="date range: ssaa-mm-jj ssaa-mm-jj") 
    222275  parser.add_argument("-s", "--show", action="store_true", 
    223276                      help="interactive mode") 
     
    256309      get_input_files(DIR["SAVEDATA"], [OUT["PARAM"], OUT["UTHEO"]]) 
    257310 
     311  file_list = glob.glob(os.path.join(DIR["SAVEDATA"], 
     312                                     "OUT_JOBS_PENDING_*")) 
     313 
    258314  img_name = "jobs" 
    259315  today = os.path.basename(file_param).strip(OUT["PARAM"]) 
     
    262318    print(file_param) 
    263319    print(file_utheo) 
    264     # print(file_data) 
     320    print(file_list) 
     321    print(img_name) 
    265322    print(today) 
    266     print(img_name) 
    267  
    268   file_list = glob.glob(os.path.join(DIR["SAVEDATA"], 
    269                                      "OUT_JOBS_PENDING_*")) 
    270  
    271   fg_first = True 
    272  
    273   for filein in sorted(file_list): 
    274     try: 
    275       data = np.genfromtxt( 
    276         filein, 
    277         skip_header=1, 
    278         converters={ 
    279           0: string_to_datetime, 
    280           1: int, 
    281           2: int, 
    282         }, 
    283         missing_values="nan", 
    284       ) 
    285     except Exception as rc: 
    286       print("Problem with file {} :\n{}".format(filein, rc)) 
    287       exit(1) 
    288  
    289     if fg_first: 
    290       fg_first = False 
    291       full_data = data 
    292     else: 
    293       full_data = np.append(full_data, values=data) 
    294323 
    295324  # .. Get project info .. 
     
    299328  gencmip6.get_date_init(file_utheo) 
    300329 
    301   # .. Fill in conso data .. 
    302   # ======================== 
    303   # # ... Initialization ... 
    304   # # ---------------------- 
    305   # bilan = BilanDict() 
    306   # bilan.init_range(gencmip6.date_init, gencmip6.deadline) 
    307   # # ... Extract data from file ... 
    308   # # ------------------------------ 
    309   # bilan.fill_data(file_data) 
     330  # .. Fill in data .. 
     331  # ================== 
     332  # ... Initialization ... 
     333  # ---------------------- 
     334  bilan = DataDict() 
     335  bilan.init_range(gencmip6.date_init, gencmip6.deadline) 
     336 
     337  # ... Extract data from file ... 
     338  # ------------------------------ 
     339  bilan.fill_data(file_list) 
     340 
    310341  # # ... Compute theoratical use from known data  ... 
    311342  # # ------------------------------------------------ 
    312343  # bilan.theo_equation() 
    313344 
    314   # # .. Extract data depending on C.L. arguments .. 
    315   # # ============================================== 
    316   # if args.full: 
    317   #   selected_items = bilan.get_items_in_full_range(args.inc) 
    318   # elif args.range: 
    319   #   selected_items = bilan.get_items_in_range( 
    320   #     args.range[0], args.range[1], args.inc 
    321   #   ) 
    322   # else: 
    323   #   selected_items = bilan.get_items(args.inc) 
     345  # .. Extract data depending on C.L. arguments .. 
     346  # ============================================== 
     347  if args.full: 
     348    selected_items = bilan.get_items_in_full_range(args.inc) 
     349  elif args.range: 
     350    selected_items = bilan.get_items_in_range( 
     351      args.range[0], args.range[1], args.inc 
     352    ) 
     353  else: 
     354    selected_items = bilan.get_items(args.inc) 
    324355 
    325356  # .. Compute data to be plotted .. 
    326357  # ================================ 
    327   # nb_items = len(selected_items) 
    328   nb_items = full_data.size 
     358  nb_items = len(selected_items) 
    329359 
    330360  xcoord   = np.linspace(1, nb_items, num=nb_items) 
    331   if full_data.size > 1: 
    332     xlabels  = np.array([date for date, run, pen in full_data]) 
    333     run_jobs = np.array([run for date, run, pen in full_data], 
    334                           dtype=int) 
    335     pen_jobs = np.array([pen for date, run, pen in full_data], 
    336                           dtype=int) 
     361  dates  = [item.date for item in selected_items] 
     362 
     363  if args.full: 
     364    run_jobs = np.array([item.run_mean for item in selected_items], 
     365                         dtype=float) 
     366    pen_jobs = np.array([item.pen_mean for item in selected_items], 
     367                         dtype=float) 
     368    run_std  = np.array([item.run_std for item in selected_items], 
     369                         dtype=float) 
     370    pen_std  = np.array([item.pen_std for item in selected_items], 
     371                         dtype=float) 
    337372  else: 
    338     xlabels , run_jobs, pen_jobs = full_data.tolist() 
    339     xlabels = list(xlabels) 
    340     run_jobs = list(run_jobs ) 
    341     pen_jobs = list(pen_jobs ) 
    342  
    343   # cumul     = np.array([item.conso for item in selected_items], 
    344   #                       dtype=float) 
    345   # consos    = [] 
    346   # consos.append(cumul[0]) 
    347   # consos[1:nb_items] = cumul[1:nb_items] - cumul[0:nb_items-1] 
    348   # consos    = np.array(consos, dtype=float) 
     373    run_jobs = np.array([item.run for item in selected_items], 
     374                         dtype=float) 
     375    pen_jobs = np.array([item.pen for item in selected_items], 
     376                         dtype=float) 
     377    run_std  = np.nan 
     378    pen_std  = np.nan 
     379 
     380  if args.verbose: 
     381    for i in selected_items: 
     382      if not np.isnan(i.run_mean): 
     383        print( 
     384          "{} {:13.2f} {:13.2f} {:13.2f} {:13.2f}".format( 
     385           i.date, 
     386           i.run_mean, i.pen_mean, 
     387           i.run_std, i.pen_std 
     388          ) 
     389        ) 
    349390 
    350391  conso_per_day = gencmip6.alloc / (gencmip6.days * 24.) 
    351  
    352   # theo_uses = np.array([100.*item.theo_use for item in selected_items], 
    353   #                      dtype=float) 
    354   # real_uses = np.array([100.*item.real_use for item in selected_items], 
    355   #                      dtype=float) 
    356   # theo_equs = np.array([100.*item.theo_equ for item in selected_items], 
    357   #                      dtype=float) 
    358392 
    359393  # .. Plot stuff .. 
     
    365399  # ... Plot data ... 
    366400  # ----------------- 
    367   plot_data(ax, xcoord, xlabels, run_jobs, pen_jobs, conso_per_day) 
     401  plot_data(ax, xcoord, dates, run_jobs, pen_jobs, run_std, pen_std) 
    368402 
    369403  # # ... Tweak figure ... 
     
    380414  ) 
    381415 
    382   plot_config(ax, xcoord, xlabels, title, conso_per_day) 
     416  plot_config(fig, ax, xcoord, dates, title, conso_per_day) 
    383417 
    384418  # ... Save figure ... 
  • TOOLS/ConsoGENCMIP6/bin/plot_store.py

    r2433 r2437  
    5353      ) 
    5454    except: 
    55       print("Empty file {}".format(filein)) 
     55      print("Empty file {}, nothing to plot".format(filein)) 
    5656      exit(1) 
    5757 
  • TOOLS/ConsoGENCMIP6/bin/run_pen_v2.sh

    r2433 r2437  
    6161# Files and directories 
    6262# ===================== 
    63 LOCAL_DIR="/ccc/cont003/home/dsm/p86ipsl/ConsoGENCMIP6/output" 
    64 SAVE_DIR="/ccc/work/cont003/dsm/p86ipsl/ConsoGENCMIP6/data" 
     63LOCAL_DIR="${HOME}/ConsoGENCMIP6/output" 
     64SAVE_DIR="${CCCWORKDIR}/ConsoGENCMIP6/data" 
    6565 
    6666if ( ${fg_dry} ) ; then 
     
    106106if ( ! ${fg_dry} ) ; then 
    107107  Suffix=$( echo ${Today} | sed 's/-//g' ) 
    108   [ -f ${SAVE_DIR}/${OUT_PENDING}_${Suffix} ] || echo "AAAA-MM-DD HH:MM RUN   PENDING" > ${SAVE_DIR}/${OUT_PENDING}_${Suffix} 
     108  [ -f ${SAVE_DIR}/${OUT_PENDING}_${Suffix} ] || echo "AAAA-MM-DD-HH:MM RUN   PENDING" > ${SAVE_DIR}/${OUT_PENDING}_${Suffix} 
    109109  cat ${OUT_PENDING} >>${SAVE_DIR}/${OUT_PENDING}_${Suffix} 
    110110  cp ${OUT_TOUSJOBS} ${SAVE_DIR}/${OUT_TOUSJOBS}_${Suffix} 
  • TOOLS/ConsoGENCMIP6/launch_conso.sh

    r2433 r2437  
    1919# Go to root directory 
    2020# ==================== 
    21 cd /ccc/cont003/home/dsm/p86ipsl/ConsoGENCMIP6/ 
     21cd ${HOME}/ConsoGENCMIP6/ 
    2222 
    2323# Main script to get data 
     
    2626printf "${script}\n" 
    2727echo "--------------------" 
    28 bin/${script}.py 
     28bin/${script}.py -v 
    2929rc=$? 
    3030if [ ${rc} -ne 0 ] ; then 
     
    4242printf "\n${script}\n" 
    4343echo "--------------------" 
     44bin/${script}.py -fv 
     45rc=$? 
     46if [ ${rc} -ne 0 ] ; then 
     47  echo "${script} terminated abnormally" 
     48else 
     49  echo "${script} OK" 
     50fi 
     51 
     52script="plot_bilan_jobs" 
     53printf "\n${script}\n" 
     54echo "--------------------" 
    4455bin/${script}.py -fd 
    4556rc=$? 
     
    5364printf "\n${script}\n" 
    5465echo "--------------------" 
    55 bin/${script}.py -d 
     66bin/${script}.py -v 
    5667rc=$? 
    5768if [ ${rc} -ne 0 ] ; then 
     
    6475printf "\n${script}\n" 
    6576echo "--------------------" 
    66 bin/${script}.py -d 
     77bin/${script}.py -v 
    6778rc=$? 
    6879if [ ${rc} -ne 0 ] ; then 
  • TOOLS/ConsoGENCMIP6/launch_jobs.sh

    r2432 r2437  
    1818# Go to root directory 
    1919# ==================== 
    20 cd /ccc/cont003/home/dsm/p86ipsl/ConsoGENCMIP6/ 
     20cd ${HOME}/ConsoGENCMIP6/ 
    2121 
    2222# Main script to get data 
Note: See TracChangeset for help on using the changeset viewer.