- Timestamp:
- 03/13/15 16:21:21 (10 years ago)
- Location:
- TOOLS/ConsoGENCMIP6
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/ConsoGENCMIP6/bin/conso_gencmip6.py
r2433 r2437 22 22 def get_storedir(login): 23 23 24 print("get_storedir") 25 24 26 command = ["ccc_home", "-A", "-u", login] 25 27 try : 26 28 res = subprocess.check_output(command) 29 print("res", res) 27 30 except Exception as rc: 28 print( rc)31 print("exception", rc) 29 32 res = None 30 33 … … 134 137 135 138 ######################################## 136 def write_bilan(filename, today, total, ureal, utheo ):139 def write_bilan(filename, today, total, ureal, utheo, run_mean, pen_mean, run_std, pen_std): 137 140 """ 138 141 Conso totale par jour … … 142 145 """ 143 146 144 title_str = "{:10s} {:12s} {:11s} {:11s} \n".format(147 title_str = "{:10s} {:12s} {:11s} {:11s} {:13s} {:13s} {:13s} {:13s}\n".format( 145 148 "date", 146 149 "conso(hours)", 147 150 "real_use(%)", 148 151 "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( 151 159 today, 152 160 total, 153 161 ureal, 154 162 utheo, 163 run_mean, 164 pen_mean, 165 run_std, 166 pen_std, 155 167 ) 156 168 … … 285 297 286 298 ######################################## 287 def save_files( OUT, today):299 def save_files(file_list, today): 288 300 289 301 if not args.dryrun: 290 302 suffix = "{:%Y%m%d}".format(today) 291 for filename in OUT.itervalues():303 for filename in file_list: 292 304 filein = os.path.join(DIR["DATA"], filename) 293 305 if os.path.isfile(filein): … … 349 361 # 2- Conso totale par jour 350 362 # ------------------------ 363 351 364 if args.verbose: 352 365 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) 353 412 354 413 write_bilan( … … 357 416 total, 358 417 ureal, 359 utheo 418 utheo, 419 run_mean, 420 pen_mean, 421 run_std, 422 pen_std, 360 423 ) 361 424 … … 379 442 print("=> write_store") 380 443 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) 384 446 385 447 # Save files (on WORKDIR) … … 388 450 print("=> Save files") 389 451 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) 391 462 392 463 exit(0) -
TOOLS/ConsoGENCMIP6/bin/gencmip6.py
r2433 r2437 11 11 import glob 12 12 import shutil 13 import subprocess 13 14 import datetime as dt 14 15 import numpy as np … … 26 27 return 27 28 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 29 35 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)) 30 44 31 45 return -
TOOLS/ConsoGENCMIP6/bin/gencmip6_path.py.init
r2425 r2437 13 13 14 14 15 ROOT_DIR = os. getcwd()15 ROOT_DIR = os.path.join(os.environ["HOME"], "ConsoGENCMIP6") 16 16 17 17 # Common paths … … 20 20 "ROOT": ROOT_DIR, 21 21 "DATA": os.path.join(ROOT_DIR, "output"), 22 "SAVE": os.path.join( ROOT_DIR, "save"),22 "SAVE": os.path.join(os.environ["CCCWORKDIR"], "ConsoGENCMIP6"), 23 23 "PLOT": os.path.join(ROOT_DIR, "plot"), 24 24 "DODS": None, … … 42 42 "LOGIN": "OUT_CONSO_LOGIN", 43 43 "STORE": "OUT_CONSO_STORE", 44 "CCCMP": "ccc_myproject.dat" 44 "CCCMP": "ccc_myproject.dat", 45 "JOBS": "OUT_JOBS_PENDING", 45 46 } 46 47 -
TOOLS/ConsoGENCMIP6/bin/plot_bilan.py
r2434 r2437 18 18 19 19 ######################################## 20 class BilanDict(dict):20 class DataDict(dict): 21 21 #--------------------------------------- 22 22 def __init__(self): … … 45 45 filein, 46 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}, 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 }, 51 57 missing_values="nan", 52 58 ) 53 except :54 print("Empty file {} ".format(filein))59 except Exception as rc: 60 print("Empty file {}:\n{}".format(filein, rc)) 55 61 exit(1) 56 62 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: 58 65 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 ) 60 76 self[date].fill() 61 77 62 78 #--------------------------------------- 63 79 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) 68 87 69 88 #--------------------------------------- … … 136 155 #--------------------------------------- 137 156 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): 139 160 self.date = date 140 161 self.conso = conso … … 142 163 self.theo_use = theo_use 143 164 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 144 169 self.filled = False 145 170 … … 167 192 168 193 ######################################## 169 def plot_data(ax_conso, ax_theo, xcoord, xlabels, 170 consos, conso_per_day, theo_uses, real_uses, theo_equs): 194 def 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): 171 197 """ 172 198 """ 199 line_style = "-" 173 200 if args.full: 174 line_style = "-" 201 line_width = 0.05 202 else: 203 # line_style = "+-" 175 204 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", 181 207 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)")184 208 185 209 ax_theo.plot(xcoord, theo_equs, "--", … … 188 212 ax_theo.plot(xcoord, theo_uses, line_style, color="firebrick", 189 213 linewidth=1, markersize=8, 190 #solid_capstyle="round", solid_joinstyle="round",214 solid_capstyle="round", solid_joinstyle="round", 191 215 label="conso théorique (%)") 192 216 ax_theo.plot(xcoord, real_uses, line_style, color="forestgreen", 193 217 linewidth=1, markersize=8, 194 #solid_capstyle="round", solid_joinstyle="round",218 solid_capstyle="round", solid_joinstyle="round", 195 219 label="conso réelle (%)") 196 220 197 221 198 222 ######################################## 199 def plot_config( ax_conso, ax_theo, xcoord, xlabels, ymax, title, conso_per_day):223 def plot_config(fig, ax_conso, ax_theo, xcoord, dates, title, conso_per_day): 200 224 """ 201 225 """ … … 203 227 # ------------------- 204 228 # 1) Range 229 if args.max: 230 ymax = gencmip6.alloc 231 else: 232 ymax = np.nanmax(consos) + np.nanmax(consos)*.1 233 205 234 xmin, xmax = xcoord[0]-1, xcoord[-1]+1 206 235 ax_conso.set_xlim(xmin, xmax) … … 209 238 210 239 # 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 212 252 ax_conso.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) 253 213 254 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") 218 257 219 258 yticks = list(ax_conso.get_yticks()) … … 221 260 ax_conso.set_yticks(yticks) 222 261 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 223 270 # 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 ) 226 285 227 286 # ... Main title and legend ... 228 287 # ----------------------------- 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) 259 294 260 295 … … 327 362 gencmip6.get_date_init(file_utheo) 328 363 329 # .. Fill in consodata ..330 # ================== ======364 # .. Fill in data .. 365 # ================== 331 366 # ... Initialization ... 332 367 # ---------------------- 333 bilan = BilanDict()368 bilan = DataDict() 334 369 bilan.init_range(gencmip6.date_init, gencmip6.deadline) 335 370 # ... Extract data from file ... … … 356 391 357 392 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 360 395 cumul = np.array([item.conso for item in selected_items], 361 396 dtype=float) … … 374 409 dtype=float) 375 410 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 376 420 # .. Plot stuff .. 377 421 # ================ … … 382 426 # ... Plot data ... 383 427 # ----------------- 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) 386 431 387 432 # ... Tweak figure ... 388 433 # -------------------- 389 if args.max:390 ymax = gencmip6.alloc391 else:392 ymax = np.nanmax(consos) + np.nanmax(consos)*.1393 394 434 title = "Consommation {}\n({:%d/%m/%Y} - {:%d/%m/%Y})".format( 395 435 gencmip6.project.upper(), … … 398 438 ) 399 439 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) 401 441 402 442 # ... Save figure ... -
TOOLS/ConsoGENCMIP6/bin/plot_jobs.py
r2434 r2437 18 18 19 19 ######################################## 20 class BilanDict(dict):20 class DataDict(dict): 21 21 #--------------------------------------- 22 22 def __init__(self): … … 27 27 """ 28 28 """ 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) 34 36 for i in xrange(deb, fin, inc)) 35 37 … … 38 40 39 41 #--------------------------------------- 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) 60 93 self[date].fill() 61 94 62 95 #--------------------------------------- 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 ) 103 110 104 111 #--------------------------------------- … … 117 124 """ 118 125 """ 119 items = (item for item in self.itervalues()) 126 items = (item for item in self.itervalues() 127 if item.date.hour == 0) 120 128 items = sorted(items, key=lambda item: item.date) 121 129 … … 135 143 class Conso(object): 136 144 #--------------------------------------- 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 139 149 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 144 156 self.filled = False 145 157 146 158 #--------------------------------------- 147 159 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 ) 149 168 150 169 #--------------------------------------- … … 166 185 167 186 ######################################## 168 def plot_data(ax, xcoord, xlabels, run_jobs, pen_jobs, conso_per_day):187 def plot_data(ax, xcoord, dates, run_jobs, pen_jobs, run_std, pen_std): 169 188 """ 170 189 """ 171 190 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 ######################################## 204 def plot_config(fig, ax, xcoord, dates, title, conso_per_day): 184 205 """ 185 206 """ … … 189 210 xmin, xmax = xcoord[0]-1, xcoord[-1]+1 190 211 ax.set_xlim(xmin, xmax) 191 # ax.set_ylim(0., ymax)192 212 193 213 # 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 200 229 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") 203 232 204 233 yticks = list(ax.get_yticks()) … … 206 235 ax.set_yticks(yticks) 207 236 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 208 244 # 3) Define axes title 209 245 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 ) 210 255 211 256 # ... Main title and legend ... 212 257 # ----------------------------- 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) 215 260 216 261 … … 220 265 parser.add_argument("-v", "--verbose", action="store_true", 221 266 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") 222 275 parser.add_argument("-s", "--show", action="store_true", 223 276 help="interactive mode") … … 256 309 get_input_files(DIR["SAVEDATA"], [OUT["PARAM"], OUT["UTHEO"]]) 257 310 311 file_list = glob.glob(os.path.join(DIR["SAVEDATA"], 312 "OUT_JOBS_PENDING_*")) 313 258 314 img_name = "jobs" 259 315 today = os.path.basename(file_param).strip(OUT["PARAM"]) … … 262 318 print(file_param) 263 319 print(file_utheo) 264 # print(file_data) 320 print(file_list) 321 print(img_name) 265 322 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 = True272 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 = False291 full_data = data292 else:293 full_data = np.append(full_data, values=data)294 323 295 324 # .. Get project info .. … … 299 328 gencmip6.get_date_init(file_utheo) 300 329 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 310 341 # # ... Compute theoratical use from known data ... 311 342 # # ------------------------------------------------ 312 343 # bilan.theo_equation() 313 344 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.inc321 #)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) 324 355 325 356 # .. Compute data to be plotted .. 326 357 # ================================ 327 # nb_items = len(selected_items) 328 nb_items = full_data.size 358 nb_items = len(selected_items) 329 359 330 360 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) 337 372 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 ) 349 390 350 391 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)358 392 359 393 # .. Plot stuff .. … … 365 399 # ... Plot data ... 366 400 # ----------------- 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) 368 402 369 403 # # ... Tweak figure ... … … 380 414 ) 381 415 382 plot_config( ax, xcoord, xlabels, title, conso_per_day)416 plot_config(fig, ax, xcoord, dates, title, conso_per_day) 383 417 384 418 # ... Save figure ... -
TOOLS/ConsoGENCMIP6/bin/plot_store.py
r2433 r2437 53 53 ) 54 54 except: 55 print("Empty file {} ".format(filein))55 print("Empty file {}, nothing to plot".format(filein)) 56 56 exit(1) 57 57 -
TOOLS/ConsoGENCMIP6/bin/run_pen_v2.sh
r2433 r2437 61 61 # Files and directories 62 62 # ===================== 63 LOCAL_DIR=" /ccc/cont003/home/dsm/p86ipsl/ConsoGENCMIP6/output"64 SAVE_DIR=" /ccc/work/cont003/dsm/p86ipsl/ConsoGENCMIP6/data"63 LOCAL_DIR="${HOME}/ConsoGENCMIP6/output" 64 SAVE_DIR="${CCCWORKDIR}/ConsoGENCMIP6/data" 65 65 66 66 if ( ${fg_dry} ) ; then … … 106 106 if ( ! ${fg_dry} ) ; then 107 107 Suffix=$( echo ${Today} | sed 's/-//g' ) 108 [ -f ${SAVE_DIR}/${OUT_PENDING}_${Suffix} ] || echo "AAAA-MM-DD 108 [ -f ${SAVE_DIR}/${OUT_PENDING}_${Suffix} ] || echo "AAAA-MM-DD-HH:MM RUN PENDING" > ${SAVE_DIR}/${OUT_PENDING}_${Suffix} 109 109 cat ${OUT_PENDING} >>${SAVE_DIR}/${OUT_PENDING}_${Suffix} 110 110 cp ${OUT_TOUSJOBS} ${SAVE_DIR}/${OUT_TOUSJOBS}_${Suffix} -
TOOLS/ConsoGENCMIP6/launch_conso.sh
r2433 r2437 19 19 # Go to root directory 20 20 # ==================== 21 cd /ccc/cont003/home/dsm/p86ipsl/ConsoGENCMIP6/21 cd ${HOME}/ConsoGENCMIP6/ 22 22 23 23 # Main script to get data … … 26 26 printf "${script}\n" 27 27 echo "--------------------" 28 bin/${script}.py 28 bin/${script}.py -v 29 29 rc=$? 30 30 if [ ${rc} -ne 0 ] ; then … … 42 42 printf "\n${script}\n" 43 43 echo "--------------------" 44 bin/${script}.py -fv 45 rc=$? 46 if [ ${rc} -ne 0 ] ; then 47 echo "${script} terminated abnormally" 48 else 49 echo "${script} OK" 50 fi 51 52 script="plot_bilan_jobs" 53 printf "\n${script}\n" 54 echo "--------------------" 44 55 bin/${script}.py -fd 45 56 rc=$? … … 53 64 printf "\n${script}\n" 54 65 echo "--------------------" 55 bin/${script}.py - d66 bin/${script}.py -v 56 67 rc=$? 57 68 if [ ${rc} -ne 0 ] ; then … … 64 75 printf "\n${script}\n" 65 76 echo "--------------------" 66 bin/${script}.py - d77 bin/${script}.py -v 67 78 rc=$? 68 79 if [ ${rc} -ne 0 ] ; then -
TOOLS/ConsoGENCMIP6/launch_jobs.sh
r2432 r2437 18 18 # Go to root directory 19 19 # ==================== 20 cd /ccc/cont003/home/dsm/p86ipsl/ConsoGENCMIP6/20 cd ${HOME}/ConsoGENCMIP6/ 21 21 22 22 # Main script to get data
Note: See TracChangeset
for help on using the changeset viewer.