Changeset 2843 for TOOLS


Ignore:
Timestamp:
05/12/16 15:42:41 (8 years ago)
Author:
labetoulle
Message:

[consogencmip6] data anonymization (store & logins)

Location:
TOOLS/ConsoGENCMIP6/bin
Files:
1 added
2 edited

Legend:

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

    r2632 r2843  
    8181 
    8282######################################## 
     83def get_aliases(alias_file): 
     84 
     85  res = {} 
     86 
     87  if os.path.isfile(alias_file): 
     88    try: 
     89      data = np.genfromtxt( 
     90        os.path.join(alias_file), 
     91        skip_header=2, 
     92        converters={ 
     93          0: str, 
     94          1: str, 
     95          2: str, 
     96          3: str, 
     97        }, 
     98        missing_values="", 
     99      ) 
     100    except Exception as rc: 
     101      print("Empty file {}:\n{}".format(filein, rc)) 
     102      exit(1) 
     103 
     104  for alias, login, _, _ in data: 
     105    res[login] = alias 
     106 
     107  return res 
     108 
     109 
     110######################################## 
    83111def plot_init(): 
    84112  paper_size  = np.array([29.7, 21.0]) 
     
    97125 
    98126######################################## 
    99 def plot_config(ax, ycoord, ylabels, title): 
     127def plot_config(fig, ax, ycoord, ylabels, title): 
    100128  """ 
    101129  """ 
     
    111139  ax.ticklabel_format(axis="x", style="sci", scilimits=(0, 0)) 
    112140  ax.set_yticks(ycoord, minor=False) 
    113   ax.set_yticklabels(ylabels, size="x-small", fontweight="bold") 
     141  ax.set_yticklabels(ylabels, size="xx-small", fontweight="bold") 
    114142  ax.invert_yaxis() 
    115143 
     
    119147  # 3) Define axes title 
    120148  ax.set_xlabel("heures", fontweight="bold") 
     149 
     150  # 4) Define plot size 
     151  fig.subplots_adjust( 
     152    left=0.08, 
     153    bottom=0.09, 
     154    right=0.93, 
     155    top=0.93, 
     156  ) 
    121157 
    122158  # ... Main title and legend ... 
     
    167203  project_name, DIR, OUT = parse_config("bin/config.ini") 
    168204 
    169   (file_param, file_utheo, file_data) = \ 
    170       get_input_files(DIR["SAVEDATA"], 
    171                       [OUT["PARAM"], OUT["UTHEO"], OUT["LOGIN"]]) 
     205  (file_param, file_utheo, file_data) = get_input_files( 
     206    DIR["SAVEDATA"], 
     207    [OUT["PARAM"], OUT["UTHEO"], OUT["LOGIN"]] 
     208  ) 
     209 
     210  alias_file = os.path.join( 
     211    "bin", 
     212    "alias_catalog.dat", 
     213  ) 
    172214 
    173215  img_name = os.path.splitext( 
     
    186228    print(fmt_str.format("img_name", img_name)) 
    187229 
     230  # .. Get alias info .. 
     231  # ==================== 
     232  alias_dict = get_aliases(alias_file) 
     233 
    188234  # .. Get project info .. 
    189235  # ====================== 
     
    213259 
    214260  ycoord  = np.linspace(1, nb_items, num=nb_items) 
    215   ylabels = [item.login for item in selected_items] 
     261  ylabels = [ 
     262    alias_dict[item.login]  
     263    if item.login in alias_dict  
     264    else str(hash(item.login))  
     265    for item in selected_items 
     266  ] 
    216267  consos  = np.array([item.conso for item in selected_items], 
    217268                      dtype=float) 
     
    234285    date 
    235286  ) 
    236   plot_config(ax, ycoord, ylabels, title) 
     287  plot_config(fig, ax, ycoord, ylabels, title) 
    237288 
    238289  # ... Save figure ... 
  • TOOLS/ConsoGENCMIP6/bin/plot_store.py

    r2717 r2843  
    150150 
    151151######################################## 
     152def get_aliases(alias_file): 
     153 
     154  res = {} 
     155 
     156  if os.path.isfile(alias_file): 
     157    try: 
     158      data = np.genfromtxt( 
     159        os.path.join(alias_file), 
     160        skip_header=2, 
     161        converters={ 
     162          0: str, 
     163          1: str, 
     164          2: str, 
     165          3: str, 
     166        }, 
     167        missing_values="", 
     168      ) 
     169    except Exception as rc: 
     170      print("Empty file {}:\n{}".format(filein, rc)) 
     171      exit(1) 
     172 
     173  for alias, login, _, _ in data: 
     174    res[login] = alias 
     175 
     176  return res 
     177 
     178 
     179######################################## 
    152180def plot_init(): 
    153181  paper_size  = np.array([29.7, 21.0]) 
     
    168196 
    169197######################################## 
    170 def plot_config(ax, coords, ylabels, dirnames, title, 
     198def plot_config(fig, ax, coords, ylabels, dirnames, title, 
    171199                tot_volume, tot_volume_init, delta): 
    172200  """ 
     
    183211  ax.ticklabel_format(axis="x", style="sci", scilimits=(0, 0)) 
    184212  ax.set_yticks(coords, minor=False) 
    185   ax.set_yticklabels(ylabels, size="x-small", fontweight="bold") 
     213  ax.set_yticklabels(ylabels, size="xx-small", fontweight="bold") 
    186214  ax.invert_yaxis() 
    187215 
     
    197225  # 3) Define axes title 
    198226  ax.set_xlabel("$To$", fontweight="bold") 
     227 
     228  # 4) Define plot size 
     229  fig.subplots_adjust( 
     230    left=0.08, 
     231    bottom=0.09, 
     232    right=0.93, 
     233    top=0.93, 
     234  ) 
    199235 
    200236  # ... Main title and legend ... 
     
    264300      get_input_files(DIR["DATA"], [OUT["SINIT"]]) 
    265301 
     302  alias_file = os.path.join( 
     303    "bin", 
     304    "alias_catalog.dat", 
     305  ) 
     306 
    266307  img_name = os.path.splitext( 
    267308               os.path.basename(__file__) 
     
    279320    print(fmt_str.format("file_init", file_init)) 
    280321    print(fmt_str.format("img_name", img_name)) 
     322 
     323  # .. Get alias info .. 
     324  # ==================== 
     325  alias_dict = get_aliases(alias_file) 
    281326 
    282327  # .. Get project info .. 
     
    316361  # .. Compute data to be plotted .. 
    317362  # ================================ 
    318   ylabels = [item.login for item in selected_items] 
     363  ylabels = [ 
     364    alias_dict[item.login]  
     365    if item.login in alias_dict  
     366    else str(hash(item.login))  
     367    for item in selected_items 
     368  ] 
    319369  values = np.array( 
    320370    [item.dirsize.convert_size("T").size for item in selected_items], 
     
    325375    dtype=float 
    326376  ) 
    327   dirnames = [item.dirname for item in selected_items] 
     377  dirnames = [ 
     378    "/".join(item.dirname.split("/")[6:]) for item in selected_items 
     379  ] 
    328380  date = selected_items[0].date 
    329381 
     
    352404  delta = tot_volume - tot_volume_init 
    353405   
    354   plot_config(ax, coords, ylabels, dirnames, title, 
     406  plot_config(fig, ax, coords, ylabels, dirnames, title, 
    355407              SizeUnit(tot_volume, "T"), 
    356408              SizeUnit(tot_volume_init, "T"), 
Note: See TracChangeset for help on using the changeset viewer.