Changeset 2524


Ignore:
Timestamp:
05/20/15 17:47:20 (9 years ago)
Author:
labetoulle
Message:

plot_store.py : plot initial volume in addition to current volume.

Location:
TOOLS/ConsoGENCMIP6
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/ConsoGENCMIP6/bin/config.ini.init

    r2464 r2524  
    1818LOGIN: OUT_CONSO_LOGIN 
    1919STORE: OUT_CONSO_STORE 
     20SINIT: OUT_CONSO_STORE_INIT 
    2021CCCMP: ccc_myproject.dat 
    2122JOBS:  OUT_JOBS_PENDING 
  • TOOLS/ConsoGENCMIP6/bin/conso_gencmip6.py

    r2462 r2524  
    259259                  if conso > 0.) 
    260260 
    261   title_str  = "{:10s} {:10s} {:>7s} {:s}\n".format( 
    262                  "date", 
    263                  "login", 
    264                  "dirsize", 
    265                  "dirname", 
    266                ) 
     261  title_str = "{:10s} {:10s} {:>7s} {:s}\n".format( 
     262                "date", 
     263                "login", 
     264                "dirsize", 
     265                "dirname", 
     266              ) 
    267267 
    268268  with open(filename, "w") as fileout: 
     
    277277      storedir = get_storedir(login) 
    278278      if not storedir: 
     279        print("storedir not found for {}".format(storedir)) 
    279280        break 
    280281      igcm_out = os.path.join(storedir, "IGCM_OUT") 
    281282 
    282283      if not os.path.isdir(igcm_out): 
    283         break 
     284        print("no {}".format(igcm_out))  
     285        continue 
    284286 
    285287      dirlist = [] 
     
    405407      exit(1) 
    406408 
    407     if len(data) == 24: 
    408       run_mean = np.nanmean( 
    409           np.array([run for _, run, _ in data]) 
    410       ) 
    411       pen_mean = np.nanmean( 
    412           np.array([pen for _, _, pen in data]) 
    413       ) 
    414  
    415       run_std = np.nanstd( 
    416           np.array([run for _, run, _ in data]) 
    417       ) 
    418       pen_std = np.nanstd( 
    419           np.array([pen for _, _, pen in data]) 
    420       ) 
     409    run_mean = np.nanmean( 
     410        np.array([run for _, run, _ in data]) 
     411    ) 
     412    pen_mean = np.nanmean( 
     413        np.array([pen for _, _, pen in data]) 
     414    ) 
     415 
     416    run_std = np.nanstd( 
     417        np.array([run for _, run, _ in data]) 
     418    ) 
     419    pen_std = np.nanstd( 
     420        np.array([pen for _, _, pen in data]) 
     421    ) 
    421422 
    422423  if args.verbose: 
  • TOOLS/ConsoGENCMIP6/bin/plot_bilan.py

    r2522 r2524  
    201201    line_width = 0.05 
    202202  else: 
    203     # line_style = "+-" 
    204203    line_width = 0.1 
    205204 
     
    432431  nb_items = len(selected_items) 
    433432 
    434   xcoord    = np.linspace(1, nb_items, num=nb_items) 
    435   dates   = [item.date for item in selected_items] 
    436  
    437   cumul     = np.array([item.conso for item in selected_items], 
     433  xcoord = np.linspace(1, nb_items, num=nb_items) 
     434  dates = [item.date for item in selected_items] 
     435 
     436  cumul = np.array([item.conso for item in selected_items], 
    438437                        dtype=float) 
    439   consos    = [] 
     438  consos = [] 
    440439  consos.append(cumul[0]) 
    441440  consos[1:nb_items] = cumul[1:nb_items] - cumul[0:nb_items-1] 
    442   consos    = np.array(consos, dtype=float) 
     441  consos = np.array(consos, dtype=float) 
    443442 
    444443  conso_per_day = projet.alloc / projet.days 
     
    448447    dtype=float 
    449448  ) 
    450  
    451449  real_uses = np.array( 
    452450    [100.*item.real_use for item in selected_items], 
  • TOOLS/ConsoGENCMIP6/bin/plot_store.py

    r2464 r2524  
    2020class DirVolume(object): 
    2121  #--------------------------------------- 
    22   def __init__(self, date, login, dirname, size): 
    23     self.date  = date 
     22  def __init__(self, date, login, dirname, size, date_init, dirsize_init): 
     23    self.date = date 
    2424    self.login = login 
    2525    self.dirname = dirname 
    2626    self.dirsize = size 
     27    self.date_init = date_init 
     28    self.dirsize_init = dirsize_init 
    2729 
    2830  #--------------------------------------- 
    2931  def __repr__(self): 
    30     return "{}={}".format(self.dirname, self.dirsize) 
     32    return "{}={}-{}".format(self.dirname, self.dirsize, self.dirsize_init) 
    3133 
    3234 
     
    3840 
    3941  #--------------------------------------- 
    40   def fill_data(self, filein): 
     42  def fill_data(self, filein, fileinit): 
    4143    """ 
    4244    """ 
     
    5355        missing_values="nan", 
    5456      ) 
    55     except: 
    56       print("Empty file {}, nothing to plot".format(filein)) 
     57    except Exception as rc: 
     58      print("Problem with file {} :\n{}".format(filein, rc)) 
    5759      exit(1) 
    5860 
    59     for date, login, dirsize, dirname in data: 
    60       self.add_item(date, login, dirsize, dirname) 
    61  
    62   #--------------------------------------- 
    63   def add_item(self, date, login, dirsize, dirname): 
     61    try: 
     62      init = np.genfromtxt( 
     63        fileinit, 
     64        skip_header=1, 
     65        converters={ 
     66          0: string_to_date, 
     67          1: str, 
     68          2: string_to_size_unit, 
     69          3: str, 
     70        }, 
     71        missing_values="nan", 
     72      ) 
     73    except Exception as rc: 
     74      print("Problem with file {} :\n{}".format(filein, rc)) 
     75      exit(1) 
     76 
     77    for (date, login, dirsize, dirname), \ 
     78        (date_init, _, dirsize_init, _) in zip(data, init): 
     79      self.add_item( 
     80        date, login, dirsize, dirname, 
     81        date_init, dirsize_init 
     82      ) 
     83 
     84  #--------------------------------------- 
     85  def add_item(self, date, login, dirsize, dirname, date_init, dirsize_init): 
    6486    """ 
    6587    """ 
    6688    if login not in self: 
    6789      self[login] = Login(date, login) 
    68     self[login].add_directory(date, login, dirsize, dirname) 
     90    self[login].add_directory( 
     91      date, login, dirsize, dirname, 
     92      date_init, dirsize_init 
     93    ) 
    6994 
    7095  #--------------------------------------- 
     
    112137 
    113138  #--------------------------------------- 
    114   def add_directory(self, date, login, dirsize, dirname): 
    115     """ 
    116     """ 
    117     self.listdir.append(DirVolume(date, login, dirname, dirsize)) 
     139  def add_directory(self, date, login, dirsize, dirname, 
     140                    date_init, dirsize_init): 
     141    """ 
     142    """ 
     143    self.listdir.append(DirVolume(date, login, dirname, dirsize, 
     144                                  date_init, dirsize_init)) 
    118145    self.add_to_total(dirsize) 
    119146 
     
    128155 
    129156######################################## 
    130 def plot_data(ax, coords, ylabels, values): 
     157def plot_data(ax, coords, ylabels, values, values_init): 
    131158  """ 
    132159  """ 
    133   ax.barh(coords, values, align="center", color="linen", 
    134           linewidth=0.2, label="volume sur STORE ($To$)") 
    135  
    136  
    137 ######################################## 
    138 def plot_config(ax, coords, ylabels, dirnames, title, tot_volume): 
     160  ax.barh(coords, values, align="center", color="orange", 
     161          linewidth=0.1, label="volume sur STORE ($To$)") 
     162  ax.barh(coords, values_init, align="center", color="linen", 
     163          linewidth=0.1, label="volume initial sur STORE ($To$)") 
     164 
     165 
     166######################################## 
     167def plot_config(ax, coords, ylabels, dirnames, title, 
     168                tot_volume, tot_volume_init, delta): 
    139169  """ 
    140170  """ 
     
    165195  ax.legend(loc="best", fontsize="x-small", frameon=False) 
    166196 
    167   tot_label = "volume total = {}".format(tot_volume) 
     197  tot_label = "prod {} = {}\n({} - {})".format( 
     198    projet.project.upper(), 
     199    delta, 
     200    tot_volume, 
     201    tot_volume_init, 
     202  ) 
    168203  plt.figtext(x=0.95, y=0.93, s=tot_label, backgroundcolor="linen", 
    169204              ha="right", va="bottom", fontsize="small") 
     
    197232  # ------------------------------ 
    198233  args = get_arguments() 
    199   if args.verbose: 
    200     print(args) 
    201234 
    202235  # ... Turn interactive mode off ... 
     
    220253                      [OUT["PARAM"], OUT["UTHEO"], OUT["STORE"]]) 
    221254 
    222   img_name = "store" 
     255  (file_init, ) = \ 
     256      get_input_files(DIR["DATA"], [OUT["SINIT"]]) 
     257 
     258  img_name = os.path.splitext( 
     259               os.path.basename(__file__) 
     260             )[0].replace("plot_", "") 
     261 
    223262  today = os.path.basename(file_param).strip(OUT["PARAM"]) 
    224263 
    225264  if args.verbose: 
    226     print(file_param) 
    227     print(file_utheo) 
    228     print(file_data) 
    229     print(img_name) 
    230     print(today) 
     265    fmt_str = "{:10s} : {}" 
     266    print(fmt_str.format("args", args)) 
     267    print(fmt_str.format("today", today)) 
     268    print(fmt_str.format("file_param", file_param)) 
     269    print(fmt_str.format("file_utheo", file_utheo)) 
     270    print(fmt_str.format("file_data", file_data)) 
     271    print(fmt_str.format("file_init", file_init)) 
     272    print(fmt_str.format("img_name", img_name)) 
    231273 
    232274  # .. Get project info .. 
     
    239281  # ======================= 
    240282  stores = StoreDict() 
    241   stores.fill_data(file_data) 
     283  stores.fill_data(file_data, file_init) 
    242284 
    243285  # .. Extract data depending on C.L. arguments .. 
     
    250292  if args.verbose: 
    251293    for item in selected_items: 
     294      fmt_str = "{:8s} " + 2*"{:%F} {} {:>18s} " + "{} " 
    252295      print( 
    253         "{:8s} {:%F} {} {:>18s} {} ".format( 
     296        fmt_str.format( 
    254297          item.login, 
    255298          item.date, 
    256299          item.dirsize, 
    257300          item.dirsize.convert_size("K"), 
     301          item.date_init, 
     302          item.dirsize_init, 
     303          item.dirsize_init.convert_size("K"), 
    258304          item.dirname, 
    259305        ) 
     
    263309  # ================================ 
    264310  ylabels = [item.login for item in selected_items] 
    265   values  = np.array([item.dirsize.convert_size("T").size 
    266                           for item in selected_items], 
    267                      dtype=float) 
     311  values = np.array( 
     312    [item.dirsize.convert_size("T").size for item in selected_items], 
     313    dtype=float 
     314  ) 
     315  values_init = np.array( 
     316    [item.dirsize_init.convert_size("T").size for item in selected_items], 
     317    dtype=float 
     318  ) 
    268319  dirnames = [item.dirname for item in selected_items] 
    269320  date = selected_items[0].date 
     
    280331  # ... Plot data ... 
    281332  # ----------------- 
    282   plot_data(ax, coords, ylabels, values) 
     333  plot_data(ax, coords, ylabels, values, values_init) 
    283334 
    284335  # ... Tweak figure ... 
     
    288339    date 
    289340  ) 
     341   
     342  tot_volume = np.sum(values) 
     343  tot_volume_init = np.sum(values_init) 
     344  delta = tot_volume - tot_volume_init 
     345   
    290346  plot_config(ax, coords, ylabels, dirnames, title, 
    291               SizeUnit(np.sum(values), "T")) 
     347              SizeUnit(tot_volume, "T"), 
     348              SizeUnit(tot_volume_init, "T"), 
     349              SizeUnit(delta, "T")) 
    292350 
    293351  # ... Save figure ... 
     
    302360  # ------------------------------ 
    303361  if args.dods: 
     362    if args.verbose: 
     363      print("Publish figure on dods") 
    304364    dods_cp(img_in, DIR) 
    305365 
  • TOOLS/ConsoGENCMIP6/launch_conso.sh

    r2460 r2524  
    7878printf "\n${script}\n" 
    7979echo "--------------------" 
     80# Last STORE file produced 
     81data_file="OUT_CONSO_STORE" 
     82OUTDIR="${HOME}/ConsoGENCMIP6/output" 
     83# Directories in last file 
     84dirlist=$( gawk '{if ($4 != "dirname") print $4}' ${OUTDIR}/${data_file} ) 
     85# Where to find the saved files 
     86SAVEDIR="${WORKDIR}/ConsoGENCMIP6/data" 
     87# Previous STORE files 
     88filelist=$( ls ${SAVEDIR}/${data_file}_* ) 
     89fileout="${data_file}_INIT" 
     90echo "date       login      dirsize dirname" > ${OUTDIR}/${fileout} 
     91for dir in ${dirlist} ; do 
     92  grep -h "$dir\$" ${filelist} | head -1 
     93  grep -h "$dir\$" ${filelist} | head -1 >> ${OUTDIR}/${fileout} 
     94done 
     95 
    8096bin/${script}.py -v 
    8197rc=$? 
  • TOOLS/ConsoGENCMIP6/launch_jobs.sh

    r2461 r2524  
    5050 
    5151printf "\nEnd of script OK\n" 
     52 
Note: See TracChangeset for help on using the changeset viewer.