gridspec_kw={'height_ratios': height_ratio},
                             figsize=(12, 5))
plt.subplots_adjust(hspace=.2, left=None, bottom=None, right=None, top=None)

indices = [3, 2]
rescaled = temperatures_spatial_demeaned.copy()
rescaled[:, indices] = rescaled[:, indices] + np.linspace(
    -1,
    len(indices) - 1, len(indices)) * 2.5
fig_1 = EvT.plot_raw_TS(
    rescaled,
    indices=indices,
    start_plot=1880,
    stop_plot=2010,
    xlab=None,
    ylab="°C",
    ylab_fontsize=17,
    yticks_fontsize=15,
    ylabel_coords=ylabel_coords,
    custom_colors_series=["black"] *
    6,  #["black","lightgray",  "darkgray", "dimgray", "black"]*len(indices))
    ax=ax_array[0])

period_time_list = [[1880, 1914], [1950, 1973], [1987, 2010]]
label_list = ["1", "2", "3"]

fig_2 = EvT.plot_model_posterior(
    indices=mods,  #mods, #mods, #relevant_models, 
    plot_type="MAP",
    y_axis_labels=[  #"AR(1)", 
        "M(5+)", "M(6)", "M(6+)", "M(7)", "M(7+)"
Esempio n. 2
0
fig, ax_array = plt.subplots(2,
                             figsize=(8, 5),
                             sharex=True,
                             gridspec_kw={'height_ratios': height_ratio})
plt.subplots_adjust(hspace=.35, left=None, bottom=None, right=None, top=None)
ylabel_coords = [-0.065, 0.5]

#Plot of raw Time Series
EvT.plot_raw_TS(
    data.reshape(T, S1, S2),
    indices=[0, 1],
    xlab=None,
    show_MAP_CPs=True,
    time_range=np.linspace(1, T, T, dtype=int),
    print_plt=False,
    ylab="value",
    ax=ax_array[0],
    #all_dates = np.linspace(622 + 1, 1284, 1284 - (622 + 1), dtype = int),
    custom_colors_series=["black"] * 4,
    custom_colors_CPs=["blue", "blue"] * 100,
    custom_linestyles=["solid"] * 100,
    ylab_fontsize=14,
    ylabel_coords=ylabel_coords)

#Run length distribution plot
EvT.plot_run_length_distr(
    buffer=0,
    show_MAP_CPs=False,
    mark_median=False,
    mark_max=True,
    upper_limit=1000,
 ax_arrays = np.array([np.array([ax1, ax2]), np.array([ax3, ax4])])
 
 plt.subplots_adjust(hspace = .05, wspace = .05, left = None, bottom = None,
                     right = None, top = None)
 
 ylabel_coords = [-0.15, 0.5]
 
 #for (ax_array, EvT) in zip(ax_arrays, (EvTKL, EvTDPD)):
     #Plot of raw Time Series
 EvTKL.plot_raw_TS(data.reshape(T,1), indices = [0], 
         xlab = None, 
         show_MAP_CPs = True, 
         time_range = np.linspace(1,T, T, dtype=int), 
         print_plt = False,
         ylab = "Nuclear Response", 
         ax = ax_arrays[0][0],
         #all_dates = np.linspace(622 + 1, 1284, 1284 - (622 + 1), dtype = int),
         custom_colors_series = ["black"],
         custom_colors_CPs = ["blue", "blue"]* 100,
         custom_linestyles = [":"]*100,
         custom_linewidth = 1.5,
         ylab_fontsize = 12,
         ylabel_coords = ylabel_coords)
 
 EvTDPD.plot_raw_TS(data.reshape(T,1), indices = [0], 
         xlab = "Time", 
         show_MAP_CPs = True, 
         time_range = np.linspace(1,T, T, dtype=int), 
         print_plt = False,
         ylab = "", 
         ax = ax_arrays[0][1],
         #all_dates = np.linspace(622 + 1, 1284, 1284 - (622 + 1), dtype = int),
#INSERT THE ADDITIONAL CPs KL DECLARES AS VERTICAL LINES

#Plot of raw Time Series
if singlePlot:

    EvTKL.plot_raw_TS(
        data.reshape(T, S1, S2),
        indices=[0, 1, 2, 3, 4],
        show_MAP_CPs=True,
        time_range=np.linspace(1, T, T, dtype=int),
        print_plt=False,
        ylab="",
        xlab="Time",
        ax=ax,  #ax_array[0],
        #all_dates = np.linspace(622 + 1, 1284, 1284 - (622 + 1), dtype = int),
        custom_colors_series=["black"] * 5,
        custom_colors_CPs=["red"] * 100,
        custom_linestyles=[":"] * 100,
        custom_linewidth=2,
        ylab_fontsize=14,
        xlab_fontsize=14,
        ylabel_coords=ylabel_coords,
        additional_CPs=EvTDPD.results[EvTDPD.names.index("MAP CPs")][-2],
        custom_colors_additional_CPs=["blue"] * 100,
        custom_linewidth_additional_CPs=5.0,
        custom_linestyles_additional_CPs=["-"] * 10)

    fig.savefig(result_path + "5SeriesRes_solidline.pdf",
                format="pdf",
                dpi=800)
elif doublePlot:
    num_subplots = 6

"""set ylabel position"""
#paper: ylabel_coords = [-0.09, 0.5] poster: ylabel_coords = [-0.045, 0.5]
ylabel_coords = [-0.09, 0.5]
yticks_fontsize = 10

#paper: figsize argument left out poster: figsize = (12,5)
fig, ax_array = plt.subplots(num_subplots, sharex = True, 
                             gridspec_kw = {'height_ratios':height_ratio})#,
                             #figsize = (12,5))
plt.subplots_adjust(hspace = .185, left = None, bottom = None, right = None, top = None)

"""plot raw data"""
fig_1 = EvT.plot_raw_TS(data, indices=[0,2,4], 
                        custom_colors_series = custom_colors_series,
                        ax = ax_array[0],xlab=None,
                        ylabel_coords = ylabel_coords) #ax_array[0])

"""Plot + save pics (4) prediction + error"""
fig_2 = EvT.plot_prediction_error(show_var= True, data = data_original, 
                                  indices = [0], 
                                  custom_colors = ['black', 'darkgray'],
                                  ax=ax_array[1], 
                                  time_range = np.linspace(1,T-2,T-2,dtype=int),
                                  aspect_ratio = 'auto', xlab = None, ylab = "PE",
                                  ylabel_coords = ylabel_coords)

"""Plot + save pictures: (3) model posteriors"""
"""Plot + save pictures: (2) Raw TS with MAP CPs"""
#backconverter = tick/C2-C1 (backconv+C1)*C2 = tick
C1, C2 = 100, 1
Esempio n. 6
0
                             figsize=(8, 5),
                             sharex=True,
                             gridspec_kw={'height_ratios': height_ratio})
plt.subplots_adjust(hspace=.35, left=None, bottom=None, right=None, top=None)
ylabel_coords = [-0.065, 0.5]

#Plot of raw Time Series
EvT.plot_raw_TS(river_height[2:].reshape(T - 2, 1),
                indices=[0],
                xlab=None,
                show_MAP_CPs=True,
                time_range=np.linspace(1, T - 2, T - 2, dtype=int),
                print_plt=False,
                ylab="River Height",
                ax=ax_array[0],
                all_dates=np.linspace(622 + 1,
                                      1284,
                                      1284 - (622 + 1),
                                      dtype=int),
                custom_colors_series=["black"],
                custom_colors_CPs=["blue", "blue"] * 10,
                custom_linestyles=["solid"] * 10,
                ylab_fontsize=14,
                ylabel_coords=ylabel_coords)

#Run length distribution plot
EvT.plot_run_length_distr(buffer=0,
                          show_MAP_CPs=True,
                          mark_median=False,
                          mark_max=True,
                          upper_limit=660,
fig, ax_array = plt.subplots(num_subplots,
                             sharex=True,
                             gridspec_kw={'height_ratios': height_ratio},
                             figsize=(8, 5))
plt.subplots_adjust(hspace=.2, left=None, bottom=None, right=None, top=None)

off = 5
time_range = np.linspace(10, T - 2, T - 2 - off, dtype=int)
all_dates = all_dates[-len(time_range):]

fig_1 = EvT.plot_raw_TS(data[-len(time_range):, :].reshape(
    len(time_range), 29),
                        all_dates=all_dates,
                        ax=ax_array[0],
                        time_range=time_range,
                        custom_colors_series=["black"] * 10,
                        ylab_fontsize=14,
                        yticks_fontsize=14,
                        ylab="NOX",
                        xlab=None,
                        ylabel_coords=ylabel_coords,
                        true_CPs=true_CPs)

mod = [17, 21]
EvT.plot_model_posterior(
    indices=mod,  #mods, #mods, #relevant_models, 
    plot_type="trace",  #"MAPVariance1_trace",
    #y_axis_labels = [str(e) for e in all_models],#[#"AR(1)",
    #"M(5+)", "M(6)",
    # "M(6+)",
    # "M(7)", "M(7+)"],#relevant_models],
    time_range=time_range,
# Prepare the axes
fig, ax_array = plt.subplots(2, figsize=(8, 5), sharex=True,
                             gridspec_kw={'height_ratios': [10, 14]})
plt.subplots_adjust(hspace=.35, left=None, bottom=None, right=None, top=None)

# Placement of y-labels
ylabel_coords = [-0.065, 0.5]

# Upper panel: plot the time-series
EvT.plot_raw_TS(river_height[2:].reshape(T-2, 1),
                indices=[0],
                xlab=None,
                show_MAP_CPs=True,
                time_range=np.linspace(1, T-2, T-2, dtype=int),
                print_plt=False,
                ylab="River Height", ax=ax_array[0],
                all_dates=np.linspace(int(dates[1]), int(dates[-2]), T-2, dtype=int),
                custom_colors_series=["black"],
                custom_colors_CPs=["blue", "blue"],
                custom_linestyles=["solid"] * 2,
                ylab_fontsize=14,
                ylabel_coords=ylabel_coords,
                set_ylims=(-2.75, 3.95))

# Lower panel: plot the run length distribution
EvT.plot_run_length_distr(buffer=0,
                          show_MAP_CPs=True,
                          mark_median=False,
                          mark_max=True,
                          upper_limit=660,
                          print_colorbar=True,
                          colorbar_location='bottom',
    S1=S1,
    S2=S2,
    T=T,
    store_rl=True,
    store_mrl=True,
    trim_type="keep_K",
    threshold=200,
    training_period=25,  #i.e., we let 2 years pass before MSE computed
    notifications=1500,
    save_performance_indicators=True)
detector.run()
"""Store results + real CPs into EvaluationTool obj"""
EvT = EvaluationTool()
EvT.build_EvaluationTool_via_run_detector(detector)
"""plot transformed data"""
fig = EvT.plot_raw_TS(data.reshape(T, 1))
"""plot prediction error"""
fig = EvT.plot_prediction_error(data,
                                indices=[0],
                                print_plt=True,
                                time_range=np.linspace(2 * 365,
                                                       T - upper_AR - 1,
                                                       T - upper_AR - 1 -
                                                       2 * 365,
                                                       dtype=int))
"""plot predictions themselves"""
fig = EvT.plot_predictions(indices=[0],
                           print_plt=True,
                           legend=False,
                           legend_labels=None,
                           legend_position=None,
fig.subplots_adjust(hspace = .05,
                    left = None, bottom = None,
                    right = None, top = None)
ylabel_coords = [0.0, 0.25] 


EvTDPD.plot_raw_TS(data.reshape(T,S1*S2), indices = [0], xlab = None, 
        show_MAP_CPs = True, 
        time_range = np.linspace(1,T, T, dtype=int), 
        print_plt = False,
        ylab = "Response", 
        ax = ax_array[0], 
        custom_colors_series = ["black"]*5,
        custom_colors_CPs = [DPD_CP_color]* 100,
        custom_linestyles = [CP_style_DPD]*100,
        custom_linewidth = CP_linewidth_DPD,
        custom_transparency = CP_transparence_DPD,
        ylab_fontsize = ylabsize,
        yticks_fontsize = ticksize,
        ylabel_coords = [-0.06,0.5], 
        additional_CPs = additional_CPs,
        custom_colors_additional_CPs = [KL_CP_color] * 100,
        custom_linewidth_additional_CPs = CP_linewidth_KL,
        custom_linestyles_additional_CPs = [CP_style_KL] * 10,
        custom_transparency_additional_CPs = CP_transparence_KL)


EvTDPD.plot_run_length_distr(buffer=0, show_MAP_CPs = show_CPs_in_rld, 
    mark_median = False, 
    mark_max = True, 
    upper_limit = 1300,