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

[consogencmip6] data anonymization (store & logins)

File:
1 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 ... 
Note: See TracChangeset for help on using the changeset viewer.