Changeset 2717 for TOOLS


Ignore:
Timestamp:
02/03/16 11:14:35 (8 years ago)
Author:
labetoulle
Message:

allow two sub-allocation periods, part 1

Location:
TOOLS/ConsoGENCMIP6/bin
Files:
5 edited

Legend:

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

    r2517 r2717  
    167167 
    168168######################################## 
    169 def get_input_files(dir_data, file_list): 
     169def get_input_files(dir_data, file_list, date=None): 
    170170  """ 
    171171  """ 
    172172  res = [] 
    173173 
    174   for filename in file_list: 
     174  for filebase in file_list: 
     175    if date: 
     176      filename = "_".join((filebase, date)) 
     177    else: 
     178      filename = filebase 
     179 
    175180    res.append(get_last_file(dir_data, filename)) 
    176181 
     
    244249    dates, utheos = zip(*data) 
    245250 
    246     (x1, x2) = (np.nanargmin(utheos), np.nanargmax(utheos)) 
     251    x2 = len(utheos) - 1 
     252    for nb, elem in enumerate(utheos[-2::-1]): 
     253      if elem >= utheos[x2]: 
     254        break 
     255      x1 = x2 - nb + 1 
    247256 
    248257    m = np.array([[x1, 1.], [x2, 1.]]) 
     
    256265 
    257266    if poly_ok: 
    258       delta = int(round(polynome.r[0] + 1)) 
    259  
    260       d1 = dates[0] 
    261       self.date_init = d1 + dt.timedelta(days=delta) 
     267      delta = x1 - int(round(polynome.r[0])) 
     268      d1 = dates[x1] 
     269      self.date_init = d1 - dt.timedelta(days=delta) 
    262270    else: 
    263271      self.date_init = dt.datetime(self.deadline.year, 1, 1) 
  • TOOLS/ConsoGENCMIP6/bin/plot_bilan.py

    r2633 r2717  
    242242  from matplotlib.ticker import AutoMinorLocator 
    243243 
     244  # ... Compute useful stuff ... 
     245  # ---------------------------- 
     246  multialloc = False 
     247  if conso_per_day_2: 
     248    date_inter = projet.date_init + dt.timedelta(days=projet.days//2) 
     249    if projet.date_init in dates: 
     250      xi = dates.index(projet.date_init) 
     251    else: 
     252      xi = 0 
     253 
     254    if projet.deadline in dates: 
     255      xf = dates.index(projet.deadline) 
     256    else: 
     257      xf = len(dates) + 1 
     258 
     259    if date_inter in dates: 
     260      xn = dates.index(date_inter) 
     261      yi = conso_per_day 
     262      yf = conso_per_day_2 
     263      multialloc = True 
     264    else: 
     265      if dates[-1] < date_inter: 
     266        xn = xf 
     267        yi = conso_per_day 
     268        yf = conso_per_day 
     269      elif dates[0] > date_inter: 
     270        xn = xi 
     271        yi = conso_per_day_2 
     272        yf = conso_per_day_2 
     273 
    244274  # ... Config axes ... 
    245275  # ------------------- 
     
    249279    ymax = conso_max  # + conso_max*.1 
    250280  else: 
    251     ymax = 3. * max(conso_per_day, conso_per_day_2) 
     281    if multialloc: 
     282      ymax = 3. * max(yi, yf) 
     283    else: 
     284      ymax = 3. * yi 
    252285 
    253286  if conso_max > ymax: 
     
    274307  ax_theo.set_ylim(0., 100) 
    275308 
    276   # 2) Ticks labels 
     309  # 2) Plot ideal daily consumption in hours 
     310  line_color = "blue" 
     311  line_alpha = 0.5 
     312  line_label = "conso journaliÚre\nidéale (heures)" 
     313  ax_conso.plot( 
     314    [xi, xn, xn, xf], [yi, yi, yf, yf], 
     315    color=line_color, alpha=line_alpha, label=line_label, 
     316  ) 
     317 
     318  # 3) Ticks labels 
    277319  (date_beg, date_end) = (dates[0], dates[-1]) 
    278320  date_fmt = "{:%d-%m}" 
     
    300342  yticks = list(ax_conso.get_yticks()) 
    301343  yticks.append(conso_per_day) 
    302   if conso_per_day_2: 
     344  if multialloc: 
    303345    yticks.append(conso_per_day_2) 
    304346  ax_conso.set_yticks(yticks) 
     
    307349  ax_theo.tick_params(colors="firebrick") 
    308350  ax_theo.yaxis.label.set_color("firebrick") 
    309  
    310   ax_conso.axhline(y=conso_per_day, color="blue", alpha=0.5, 
    311                    label="conso journaliÚre\nidéale (heures)") 
    312  
    313   if conso_per_day_2: 
    314     ax_conso.axhline(y=conso_per_day_2, color="blue", alpha=0.5) 
    315351 
    316352  for x, d in zip(xcoord, dates): 
     
    319355                       linewidth=0.5, linestyle=":") 
    320356 
    321   # 3) Define axes title 
     357  # 4) Define axes title 
    322358  for ax, label in ( 
    323359    (ax_conso, "heures"), 
     
    327363    ax.tick_params(axis="y", labelsize="small") 
    328364 
    329   # 4) Define plot size 
     365  # 5) Define plot size 
    330366  fig.subplots_adjust( 
    331367    left=0.08, 
     
    358394                      type=string_to_date, 
    359395                      help="date range: ssaa-mm-jj ssaa-mm-jj") 
     396  parser.add_argument("--date", action="store",                                                                                                                                                       
     397                      help="date to plot: ssaammjj")                                                                                                                                                  
    360398  parser.add_argument("-m", "--max", action="store_true", 
    361399                      help="plot with y_max = allocation") 
     
    394432 
    395433  (file_param, file_utheo, file_data) = \ 
    396       get_input_files(DIR["SAVEDATA"], 
    397                       [OUT["PARAM"], OUT["UTHEO"], OUT["BILAN"]]) 
     434      get_input_files( 
     435        DIR["SAVEDATA"], 
     436        [OUT["PARAM"], OUT["UTHEO"], OUT["BILAN"]], 
     437        args.date 
     438      ) 
    398439 
    399440  img_name = os.path.splitext( 
     
    457498 
    458499  if projet.project == "gencmip6": 
    459     alloc1 = 5.e6 
    460     alloc2 = projet.alloc - alloc1 
     500    alloc1 = (1 * projet.alloc) / 3 
     501    alloc2 = (2 * projet.alloc) / 3 
    461502    conso_per_day   = 2 * alloc1 / projet.days 
    462503    conso_per_day_2 = 2 * alloc2 / projet.days 
     
    520561  # ... Save figure ... 
    521562  # ------------------- 
    522   img_in  = os.path.join(DIR["PLOT"], "{}.pdf".format(img_name)) 
    523   img_out = os.path.join(DIR["SAVEPLOT"], 
    524                          "{}_{}.pdf".format(img_name, today)) 
     563  if args.date: 
     564    img_in = os.path.join( 
     565      DIR["PLOT"], "{}_{}.pdf".format(img_name, today) 
     566    ) 
     567  else: 
     568    img_in = os.path.join( 
     569      DIR["PLOT"], "{}.pdf".format(img_name) 
     570    ) 
     571  img_out = os.path.join( 
     572    DIR["SAVEPLOT"], 
     573    "{}_{}.pdf".format(img_name, today) 
     574  ) 
    525575 
    526576  plot_save(img_in, img_out, title, DIR) 
  • TOOLS/ConsoGENCMIP6/bin/plot_bilan_jobs.py

    r2632 r2717  
    268268  # 1) Range 
    269269  conso_max = np.nanmax(consos) 
     270  jobs_max = np.nanmax(run_mean) 
    270271  if args.max: 
    271     ymax = conso_max  # + conso_max*.1 
     272    ymax = conso_max  # * 1.1 
     273    ymax_jobs = jobs_max  # * 1.1 
    272274  else: 
    273275    ymax = 3. * max(conso_per_day, conso_per_day_2) 
     276    ymax_jobs = max(conso_per_day, conso_per_day_2)/24. 
    274277 
    275278  if conso_max > ymax: 
     
    295298  ax_conso.set_xlim(xmin, xmax) 
    296299  ax_conso.set_ylim(0., ymax) 
     300  ax_jobs.set_ylim(0., ymax_jobs) 
    297301  ax_theo.set_ylim(0., 100) 
    298302 
    299   # 2) Ticks labels 
     303  # 2) Plot ideal daily consumption in hours 
     304  line_color = "blue" 
     305  line_alpha = 0.5 
     306  line_label = "conso journaliÚre\nidéale ({})" 
     307  for ax, y_div, label in ( 
     308    (ax_conso, 1., line_label.format("heures")), 
     309    (ax_jobs, 24., line_label.format("cœurs")), 
     310  ): 
     311    if conso_per_day_2: 
     312      list_x = [0, xmax/2, xmax/2, xmax] 
     313      list_y = np.array( 
     314        [conso_per_day, conso_per_day, conso_per_day_2, conso_per_day_2], 
     315        dtype=float 
     316      ) 
     317      ax.plot( 
     318        list_x, list_y/y_div, 
     319        color=line_color, alpha=line_alpha, label=label, 
     320      ) 
     321    else: 
     322      ax.axhline( 
     323        y=conso_per_day/y_div, 
     324        color=line_color, alpha=line_alpha, label=label, 
     325      ) 
     326 
     327  # 3) Ticks labels 
    300328  (date_beg, date_end) = (dates[0], dates[-1]) 
    301329  date_fmt = "{:%d-%m}" 
     
    328356    yticks.append(y) 
    329357    ax.set_yticks(yticks) 
    330     ax.axhline(y=y, color="blue", alpha=0.5, 
    331                label="conso journaliÚre\nidéale ({})".format(label)) 
    332358 
    333359  if conso_per_day_2: 
    334360    yticks.append(conso_per_day_2) 
    335     ax_conso.axhline(y=conso_per_day_2, color="blue", alpha=0.5) 
    336     ax_jobs.axhline(y=conso_per_day_2 / 24., color="blue", alpha=0.5) 
    337361 
    338362  ax_theo.spines["right"].set_color("firebrick") 
     
    346370                   linewidth=0.5, linestyle=":") 
    347371 
    348   # 3) Define axes title 
     372  # 4) Define axes title 
    349373  for ax, label in ( 
    350374    (ax_conso, "heures"), 
     
    355379    ax.tick_params(axis="y", labelsize="small") 
    356380 
    357   # 4) Define plot size 
     381  # 5) Define plot size 
    358382  fig.subplots_adjust( 
    359383    left=0.08, 
     
    488512 
    489513  if projet.project == "gencmip6": 
    490     alloc1 = 5.e6 
    491     alloc2 = projet.alloc - alloc1 
     514    alloc1 = (1 * projet.alloc) / 3 
     515    alloc2 = (2 * projet.alloc) / 3 
    492516    conso_per_day   = 2 * alloc1 / projet.days 
    493517    conso_per_day_2 = 2 * alloc2 / projet.days 
  • TOOLS/ConsoGENCMIP6/bin/plot_jobs.py

    r2632 r2717  
    122122    """ 
    123123    items = (item for item in self.itervalues() 
    124                    if item.date.hour == 0) 
     124                   if item.date >= projet.date_init and 
     125                      item.date <= projet.deadline  and 
     126                      item.date.hour == 0) 
    125127    items = sorted(items, key=lambda item: item.date) 
    126128 
     
    218220  from matplotlib.ticker import AutoMinorLocator 
    219221 
     222  # ... Compute useful stuff ... 
     223  # ---------------------------- 
     224  multialloc = False 
     225  if conso_per_day_2: 
     226    date_inter = projet.date_init + dt.timedelta(days=projet.days//2) 
     227    if projet.date_init in dates: 
     228      xi = dates.index(projet.date_init) 
     229    else: 
     230      xi = 0 
     231 
     232    if projet.deadline in dates: 
     233      xf = dates.index(projet.deadline) 
     234    else: 
     235      xf = len(dates) 
     236 
     237    if date_inter in dates: 
     238      xn = dates.index(date_inter) 
     239      yi = conso_per_day 
     240      yf = conso_per_day_2 
     241      multialloc = True 
     242    else: 
     243      if dates[-1] < date_inter: 
     244        xn = xf 
     245        yi = conso_per_day 
     246        yf = conso_per_day 
     247      elif dates[0] > date_inter: 
     248        xn = xi 
     249        yi = conso_per_day_2 
     250        yf = conso_per_day_2 
     251 
    220252  # ... Config axes ... 
    221253  # ------------------- 
    222254  # 1) Range 
    223255  xmin, xmax = xcoord[0]-1, xcoord[-1]+1 
     256  if multialloc: 
     257    ymax = 4. * max(yi, yf) 
     258  else: 
     259    ymax = 4. * yi 
    224260  ax.set_xlim(xmin, xmax) 
    225  
    226   # 2) Ticks labels 
     261  ax.set_ylim(0, ymax) 
     262 
     263  # 2) Plot ideal daily consumption 
     264  line_color = "blue" 
     265  line_alpha = 0.5 
     266  line_label = "conso journaliÚre idéale" 
     267  ax.plot( 
     268    [xi, xn, xn, xf], [yi, yi, yf, yf], 
     269    color=line_color, alpha=line_alpha, label=line_label, 
     270  ) 
     271 
     272  # 3) Ticks labels 
    227273  (date_beg, date_end) = (dates[0], dates[-1]) 
    228274 
     
    249295  yticks = list(ax.get_yticks()) 
    250296  yticks.append(conso_per_day) 
    251   if conso_per_day_2: 
     297  if multialloc: 
    252298    yticks.append(conso_per_day_2) 
    253299  ax.set_yticks(yticks) 
    254300 
    255   ax.axhline(y=conso_per_day, color="blue", alpha=0.5, 
    256              label="conso journaliÚre idéale") 
    257  
    258   if conso_per_day_2: 
    259     ax.axhline(y=conso_per_day_2, color="blue", alpha=0.5) 
    260301 
    261302  for x, d in zip(xcoord, dates): 
     
    263304      ax.axvline(x=x, color="black", linewidth=1., linestyle=":") 
    264305 
    265   # 3) Define axes title 
     306  # 4) Define axes title 
    266307  ax.set_ylabel("cœurs", fontweight="bold") 
    267308  ax.tick_params(axis="y", labelsize="small") 
    268309 
    269   # 4) Define plot size 
     310  # 5) Define plot size 
    270311  fig.subplots_adjust( 
    271312    left=0.08, 
     
    420461 
    421462  if projet.project == "gencmip6": 
    422     alloc1 = 5.e6 
    423     alloc2 = projet.alloc - alloc1 
     463    alloc1 = (1 * projet.alloc) / 3 
     464    alloc2 = (2 * projet.alloc) / 3 
    424465    conso_per_day   = 2 * alloc1 / (projet.days * 24.) 
    425466    conso_per_day_2 = 2 * alloc2 / (projet.days * 24.) 
  • TOOLS/ConsoGENCMIP6/bin/plot_store.py

    r2632 r2717  
    143143    self.listdir.append(DirVolume(date, login, dirname, dirsize, 
    144144                                  date_init, dirsize_init)) 
    145     self.add_to_total(dirsize) 
     145    if isinstance(dirsize, SizeUnit): 
     146      self.add_to_total(dirsize) 
     147    elif args.verbose: 
     148      print("No size for {}, {}".format(login, dirname)) 
    146149 
    147150 
Note: See TracChangeset for help on using the changeset viewer.