fig = plt.figure(figsize=(16, 9), dpi=75)
  mintime = np.min(ensemble_all_df['s_since_midnight'])
  maxtime = np.max(ensemble_all_df['s_since_midnight'])
  plt.title("Ensemble der Netzfrequenz")
  plt.xlabel("Zeit [UTC]")
  plt.ylabel("Frequenz [Hz]")
  #plt.plot(ensemble_all_df.s_since_midnight,
  #    ensemble_all_df.freq_sg, 'k', label="Alle Tage")
  plt.plot(ensemble_weekday_df.s_since_midnight,
      ensemble_weekday_df.freq_sg, 'b', label="Wochentag")
  plt.plot(ensemble_weekend_df.s_since_midnight,
      ensemble_weekend_df.freq_sg, 'r', label="Wochenende")
  xlocs = np.arange(mintime, maxtime, 60*60)
  xlocs, xlabels = plt.xticks(xlocs, 
        map(lambda x: datatool.seconds_to_timeofday(x), xlocs))
  plt.setp(xlabels, rotation=45)
  plt.grid(True, which='both')
  plt.legend(loc="best")

  plt.xlim(0, 60*60*24-1)
 

  #plt.legend()
  #axarr[0].plot(axarr[0].get_xlim(), (lower_freq_limit, lower_freq_limit), 'r-')
  #axarr[0].plot(axarr[0].get_xlim(), (upper_freq_limit, upper_freq_limit), 'r-')

  ## the histogram of the data
  #n, bins, patches = axarr[1].hist(diofreq, 100, normed=1, facecolor='green', alpha=0.75)
  ## add a 'best fit' line
  #y = mlab.normpdf( bins, mu, sigma)
Beispiel #2
0
print "Using window of size", window_num_seconds, "seconds"

min_ts = np.min(df['unix'])
max_ts = np.max(df['unix'])
half_window_size = window_num_seconds/2
quarter_window_size = window_num_seconds/4

event_id = 0
for i in np.arange(min_ts + half_window_size, max_ts - half_window_size,
    quarter_window_size):
  window = df[(df.unix >= i-half_window_size) & (df.unix <
    i+half_window_size)]
  max_deviation = np.max(window['freq']) - np.min(window['freq'])
  if max_deviation > (rel_deviation_Hz):
    fulldatestring = "%s %s (UTC)" % (datatool.seconds_to_date(i),
        datatool.seconds_to_timeofday(i))
    title_string = "%s: %.3f Hz" % (fulldatestring, max_deviation)
    file_string = "(%d) - %s - %f" % (event_id, datatool.seconds_to_date(i), max_deviation)
    print "Found deviation: ", title_string
    plt.clf()
    plt.title("%s" % title_string)
    plt.xlabel("Uhrzeit")
    plt.ylabel("Frequenz [Hz]")
    plt.plot(window['unix'], window['freq'], 'r')
    plt.xlim(np.min(window['unix']), np.max(window['unix']))
    xlocs = np.arange(np.min(window['unix']), np.max(window['unix']), 60)
    xlocs, xlabels = plt.xticks(xlocs, 
        map(lambda x: datatool.seconds_to_timeofday(x), xlocs))
    plt.setp(xlabels, rotation=45)
    plt.savefig("images/events/%s.png" % file_string, bbox_inches='tight')
    event_id = event_id + 1
print "preparing data matrix"
datamatrix = np.zeros((24 * 60 * 60, max_day - min_day + 1))
for i in range(len(df['freq'])):
    x = df['d_since_start'][i]
    y = df['s_since_midnight'][i]
    #print i, x, y
    datamatrix[y, x] = df['freq'][i]
#color_map = plt.cm.Spectral_r
color_map = b2m.brewer2mpl.get_map("Spectral", "Diverging", 11).mpl_colormap
print "plotting."
p = plt.pcolormesh(datamatrix,
                   cmap=color_map,
                   norm=LogNorm(vmin=np.min(df['freq']),
                                vmax=np.max(df['freq'])))
freqticks = np.linspace(minfreq, maxfreq, 7)
ticklabels = ["%.3f" % s for s in freqticks]
cbar = plt.colorbar(p, spacing='log', ticks=freqticks)
cbar.ax.set_yticklabels(ticklabels)
cbar.set_label("Frequenz")
plt.ylim(0, 24 * 60 * 60)
ylocs = np.arange(0, 24 * 60 * 60, 60 * 60)
ylocs, ylabels = plt.yticks(
    ylocs, map(lambda y: datatool.seconds_to_timeofday(y), ylocs))
xlocs = np.arange(min_day, max_day + 1, 7)
xlocs, xlabels = plt.xticks(xlocs, map(lambda x: x, xlocs))
#verticalalignment = 'bottom')
#plt.setp(xlabels, rotation=45)
plt.ylabel("Uhrzeit (UTC)")
plt.xlabel("Tag")
plt.savefig("images/freq-heatmap.png", bbox_inches='tight')
for i in range(len(df['freq'])):
  x = df['d_since_start'][i]
  y = df['s_since_midnight'][i]
  #print i, x, y
  datamatrix[y, x] = df['freq'][i]
#color_map = plt.cm.Spectral_r
color_map = b2m.brewer2mpl.get_map("Spectral", "Diverging",
    11).mpl_colormap
print "plotting."
p=plt.pcolormesh(datamatrix, 
    cmap=color_map,
    norm=LogNorm(vmin=np.min(df['freq']), vmax=np.max(df['freq']))
    )
freqticks = np.linspace(minfreq, maxfreq, 7)
ticklabels = ["%.3f" % s for s in freqticks]
cbar = plt.colorbar(p, spacing='log', ticks=freqticks)
cbar.ax.set_yticklabels(ticklabels)
cbar.set_label("Frequenz")
plt.ylim(0, 24*60*60)
ylocs = np.arange(0, 24*60*60, 60*60)
ylocs, ylabels = plt.yticks(ylocs, 
    map(lambda y: datatool.seconds_to_timeofday(y), ylocs))
xlocs = np.arange(min_day, max_day+1, 7)
xlocs, xlabels = plt.xticks(xlocs,
    map(lambda x: x, xlocs))
    #verticalalignment = 'bottom')
#plt.setp(xlabels, rotation=45)
plt.ylabel("Uhrzeit (UTC)")
plt.xlabel("Tag")
plt.savefig("images/freq-heatmap.png", bbox_inches='tight')