Update application source code (v2.62)
This commit is contained in:
		
							
								
								
									
										184
									
								
								src/Mmax.py
									
									
									
									
									
								
							
							
						
						
									
										184
									
								
								src/Mmax.py
									
									
									
									
									
								
							@@ -1,12 +1,12 @@
 | 
			
		||||
import sys
 | 
			
		||||
import numpy as np
 | 
			
		||||
import matplotlib.pyplot as plt
 | 
			
		||||
import pandas as pd
 | 
			
		||||
# import os
 | 
			
		||||
import scipy.io
 | 
			
		||||
import logging
 | 
			
		||||
from geopy.distance import geodesic
 | 
			
		||||
from geopy.point import Point
 | 
			
		||||
 | 
			
		||||
from util.base_logger import getDefaultLogger
 | 
			
		||||
 | 
			
		||||
def main(Input_catalog, Input_injection_rate, time_win_in_hours, time_step_in_hour, time_win_type,
 | 
			
		||||
@@ -68,7 +68,8 @@ def main(Input_catalog, Input_injection_rate, time_win_in_hours, time_step_in_ho
 | 
			
		||||
    # Importing data
 | 
			
		||||
    logger.info("Import data")
 | 
			
		||||
    mat = scipy.io.loadmat(Input_catalog)
 | 
			
		||||
    Cat_structure = mat['Catalog']
 | 
			
		||||
    Cat_structure_name = scipy.io.whosmat(Input_catalog)[0][0]
 | 
			
		||||
    Cat_structure = mat[Cat_structure_name]
 | 
			
		||||
    Cat_id, Cat_t, Cat_m = [], [], []
 | 
			
		||||
    Cat_x, Cat_y, Cat_z = [], [], []
 | 
			
		||||
    Cat_lat, Cat_lon, Cat_elv, Cat_depth = [], [], [], []
 | 
			
		||||
@@ -475,181 +476,6 @@ def main(Input_catalog, Input_injection_rate, time_win_in_hours, time_step_in_ho
 | 
			
		||||
 | 
			
		||||
        return In_arr[:i_row,:]
 | 
			
		||||
 | 
			
		||||
    # Plotting models and parameters
 | 
			
		||||
    def Plot_feature(Model_Param_array,Output_dict):
 | 
			
		||||
        myVars = locals()
 | 
			
		||||
 | 
			
		||||
        # Function for findin min-max of all similar parameters
 | 
			
		||||
        def Extermom4All(Model_Param_array, itr_loc):
 | 
			
		||||
            Mat1D = np.reshape(Model_Param_array[:,itr_loc], -1)
 | 
			
		||||
            NotNone = np.isfinite(Mat1D)
 | 
			
		||||
            if np.min(Mat1D[NotNone])>0:
 | 
			
		||||
                return [np.min(Mat1D[NotNone])*0.95, np.max(Mat1D[NotNone])*1.05]
 | 
			
		||||
            elif np.min(Mat1D[NotNone])<0 and np.max(Mat1D[NotNone])>0:
 | 
			
		||||
                return [np.min(Mat1D[NotNone])*1.05, np.max(Mat1D[NotNone])*1.05]
 | 
			
		||||
            elif np.max(Mat1D[NotNone])<0:
 | 
			
		||||
                return [np.min(Mat1D[NotNone])*1.05, np.max(Mat1D[NotNone])*0.95]
 | 
			
		||||
 | 
			
		||||
        # Function for setting relevant lagends in the plot
 | 
			
		||||
        def Legend_label(loc):
 | 
			
		||||
            l = Output_dict_c['label'][loc]
 | 
			
		||||
            if Output_dict_c['b_method'][loc]:
 | 
			
		||||
                if Output_dict_c['cl'][loc]:
 | 
			
		||||
                    l+='('+Output_dict_c['b_method'][loc]+', cl='+str(Output_dict_c['cl'][loc])+')'
 | 
			
		||||
                else:
 | 
			
		||||
                    l+='('+Output_dict_c['b_method'][loc]+')'
 | 
			
		||||
 | 
			
		||||
            return l
 | 
			
		||||
 | 
			
		||||
        c_NotNone = [] # Removing all parameters with None or constant value
 | 
			
		||||
        for i in range(Model_Param_array.shape[1]):
 | 
			
		||||
            NotNone = np.isfinite(Model_Param_array[:,i])
 | 
			
		||||
            Eq_value = np.mean(Model_Param_array[:,i])
 | 
			
		||||
            if any(NotNone) and Eq_value != Model_Param_array[0,i]:
 | 
			
		||||
                c_NotNone.append(i)
 | 
			
		||||
            else:
 | 
			
		||||
                logger.info(f"No-PLOT: All values of {Output_dict['Type'][i]} are {Model_Param_array[0,i]}!")
 | 
			
		||||
 | 
			
		||||
        if len(c_NotNone) > 1:
 | 
			
		||||
            Model_Param_array = Model_Param_array[:,c_NotNone]
 | 
			
		||||
            # New output dictionary based on valid parameters for plotting
 | 
			
		||||
            Output_dict_c = {'Type':[], 'label':[], 'b_method':[], 'cl':[]}
 | 
			
		||||
            for i in range(len(c_NotNone)):
 | 
			
		||||
                Output_dict_c['Type'].append(Output_dict['Type'][c_NotNone[i]])
 | 
			
		||||
                Output_dict_c['label'].append(Output_dict['label'][c_NotNone[i]])
 | 
			
		||||
                Output_dict_c['b_method'].append(Output_dict['b_method'][c_NotNone[i]])
 | 
			
		||||
                Output_dict_c['cl'].append(Output_dict['cl'][c_NotNone[i]])
 | 
			
		||||
 | 
			
		||||
            coloring=['blue','g','r','c','m','y',
 | 
			
		||||
                        'brown', 'darkolivegreen', 'teal', 'steelblue', 'slateblue',
 | 
			
		||||
                        'purple', 'darksalmon', '#c5b0d5', '#c49c94',
 | 
			
		||||
                        '#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7', '#bcbd22', '#dbdb8d',
 | 
			
		||||
                        '#17becf', '#9edae5',
 | 
			
		||||
                        'brown', 'darkolivegreen', 'teal', 'steelblue', 'slateblue',]
 | 
			
		||||
            # All parameters to be plotted
 | 
			
		||||
            All_vars = Output_dict_c['Type'][2:]
 | 
			
		||||
            Uniqe_var = list(dict.fromkeys([s for s in All_vars if 'Standard Error' not in s])) #list(set(All_vars))
 | 
			
		||||
 | 
			
		||||
            # defining handels and labels to make final legend
 | 
			
		||||
            All_handels = ['p0']
 | 
			
		||||
            for i in range(1,len(All_vars)):
 | 
			
		||||
                All_handels.append('p'+str(i))
 | 
			
		||||
            handels = []
 | 
			
		||||
            labels = []
 | 
			
		||||
 | 
			
		||||
            # itr_loc: location of paramteres with similar type
 | 
			
		||||
            itr_loc = np.where(np.array(All_vars) == Uniqe_var[0])[0]+2
 | 
			
		||||
            fig, myVars[Output_dict_c['Type'][0]] = plt.subplots(1,1,figsize=(8+int(len(All_vars)/3),6))
 | 
			
		||||
            fig.subplots_adjust(right=1-len(Uniqe_var)*0.09)
 | 
			
		||||
            if Output_dict_c['label'][itr_loc[0]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
                myVars[All_handels[itr_loc[0]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= 'k', ls='--', lw = 2)
 | 
			
		||||
            else:
 | 
			
		||||
                myVars[All_handels[itr_loc[0]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= coloring[itr_loc[0]])
 | 
			
		||||
            handels.append(All_handels[itr_loc[0]-2])
 | 
			
		||||
            labels.append(Legend_label(itr_loc[0]))
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].set_ylabel(Output_dict_c['Type'][itr_loc[0]])
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].set_ylim(Extermom4All(Model_Param_array, itr_loc)[0], Extermom4All(Model_Param_array, itr_loc)[1])
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].set_xlabel('Day (From start of the recording)')
 | 
			
		||||
            if End_time:
 | 
			
		||||
                myVars[Output_dict_c['Type'][0]].set_xlim(0,End_time)
 | 
			
		||||
 | 
			
		||||
            # Plotting statndard error (if exists)
 | 
			
		||||
            if  itr_loc[0]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[0]+1] == 'Standard Error':
 | 
			
		||||
                myVars[Output_dict_c['Type'][0]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[0]] -  Model_Param_array[:,itr_loc[0]+1],
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[0]] +  Model_Param_array[:,itr_loc[0]+1], color= coloring[itr_loc[0]], alpha=0.1)
 | 
			
		||||
            # Plotting similar parameters on one axis
 | 
			
		||||
            for j in range(1,len(itr_loc)):
 | 
			
		||||
                    if Output_dict_c['label'][itr_loc[j]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
                        myVars[All_handels[itr_loc[j]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= 'k', ls='--', lw = 2)
 | 
			
		||||
                    else:
 | 
			
		||||
                        myVars[All_handels[itr_loc[j]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= coloring[itr_loc[j]])
 | 
			
		||||
                    handels.append(All_handels[itr_loc[j]-2])
 | 
			
		||||
                    labels.append(Legend_label(itr_loc[j]))
 | 
			
		||||
 | 
			
		||||
                    # Plotting statndard error (if exists)
 | 
			
		||||
                    if  itr_loc[0]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[j]+1] == 'Standard Error':
 | 
			
		||||
                        myVars[Output_dict_c['Type'][0]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[j]] -  Model_Param_array[:,itr_loc[j]+1],
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[j]] +  Model_Param_array[:,itr_loc[j]+1], color= coloring[itr_loc[j]], alpha=0.1)
 | 
			
		||||
            first_itr = 0
 | 
			
		||||
            # Check if there is any more parameter to be plotted in second axes
 | 
			
		||||
            # The procedure is similar to last plots.
 | 
			
		||||
            if len(Uniqe_var) > 1:
 | 
			
		||||
                for i in range(1,len(Uniqe_var)):
 | 
			
		||||
                    itr_loc = np.where(np.array(All_vars) == Uniqe_var[i])[0]+2
 | 
			
		||||
                    myVars[Uniqe_var[i]] = myVars[Output_dict_c['Type'][0]].twinx()
 | 
			
		||||
                    # if it is third or more axis, make a distance between them
 | 
			
		||||
                    if first_itr == 0:
 | 
			
		||||
                        first_itr += 1
 | 
			
		||||
                        set_right = 1
 | 
			
		||||
                    else:
 | 
			
		||||
                        set_right = 1 + first_itr*0.2
 | 
			
		||||
                        first_itr += 1
 | 
			
		||||
                        myVars[Uniqe_var[i]].spines.right.set_position(("axes", set_right))
 | 
			
		||||
                    if Output_dict_c['label'][itr_loc[0]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
                        myVars[All_handels[itr_loc[0]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= 'k', ls='--', lw = 2)
 | 
			
		||||
                    else:
 | 
			
		||||
                        myVars[All_handels[itr_loc[0]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= coloring[itr_loc[0]])
 | 
			
		||||
                    handels.append(All_handels[itr_loc[0]-2])
 | 
			
		||||
                    labels.append(Legend_label(itr_loc[0]))
 | 
			
		||||
                    myVars[Uniqe_var[i]].set_ylabel(Output_dict_c['Type'][itr_loc[0]])
 | 
			
		||||
                    myVars[Uniqe_var[i]].yaxis.label.set_color(coloring[itr_loc[0]])
 | 
			
		||||
                    myVars[Uniqe_var[i]].spines["right"].set_edgecolor(coloring[itr_loc[0]])
 | 
			
		||||
                    myVars[Uniqe_var[i]].tick_params(axis='y', colors= coloring[itr_loc[0]])
 | 
			
		||||
                    myVars[Uniqe_var[i]].set_ylim(Extermom4All(Model_Param_array, itr_loc)[0], Extermom4All(Model_Param_array, itr_loc)[1])
 | 
			
		||||
                    if itr_loc[0]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[0]+1] == 'Standard Error':
 | 
			
		||||
                        myVars[Uniqe_var[i]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[0]] -  Model_Param_array[:,itr_loc[0]+1],
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[0]] +  Model_Param_array[:,itr_loc[0]+1], color= coloring[itr_loc[0]], alpha=0.1)
 | 
			
		||||
 | 
			
		||||
                    for j in range(1,len(itr_loc)):
 | 
			
		||||
                        if Output_dict_c['label'][itr_loc[j]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
                            myVars[All_handels[itr_loc[j]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= 'k', ls = '--', lw = 2)
 | 
			
		||||
                        else:
 | 
			
		||||
                            myVars[All_handels[itr_loc[j]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= coloring[itr_loc[j]])
 | 
			
		||||
                        handels.append(All_handels[itr_loc[j]-2])
 | 
			
		||||
                        labels.append(Legend_label(itr_loc[j]))
 | 
			
		||||
                        if itr_loc[j]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[j]+1] == 'Standard Error':
 | 
			
		||||
                            myVars[Uniqe_var[i]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[j]] -  Model_Param_array[:,itr_loc[j]+1],
 | 
			
		||||
                                                            Model_Param_array[:,itr_loc[j]] +  Model_Param_array[:,itr_loc[j]+1], color= coloring[itr_loc[j]], alpha=0.1)
 | 
			
		||||
 | 
			
		||||
            # If there are timing, plot them as vertical lines
 | 
			
		||||
            if time_inj:
 | 
			
		||||
                myVars['l1'], = plt.plot([time_inj,time_inj], [Extermom4All(Model_Param_array, itr_loc)[0],Extermom4All(Model_Param_array, itr_loc)[1]], ls='--', c='k')
 | 
			
		||||
                handels.append('l1')
 | 
			
		||||
                labels.append('Start-inj')
 | 
			
		||||
            if time_shut_in:
 | 
			
		||||
                myVars['l2'], = plt.plot([time_shut_in,time_shut_in], [Extermom4All(Model_Param_array, itr_loc)[0],Extermom4All(Model_Param_array, itr_loc)[1]], ls='-.', c='k')
 | 
			
		||||
                handels.append('l2')
 | 
			
		||||
                labels.append('Shut-in')
 | 
			
		||||
            if time_big_ev:
 | 
			
		||||
                myVars['l3'], = plt.plot([time_big_ev,time_big_ev], [Extermom4All(Model_Param_array, itr_loc)[0],Extermom4All(Model_Param_array, itr_loc)[1]], ls='dotted', c='k')
 | 
			
		||||
                handels.append('l3')
 | 
			
		||||
                labels.append('Large-Ev')
 | 
			
		||||
 | 
			
		||||
            box = myVars[Output_dict_c['Type'][0]].get_position()
 | 
			
		||||
            if len(handels) < 6:
 | 
			
		||||
                myVars[Output_dict_c['Type'][0]].set_position([box.x0, box.y0 + box.height * 0.1,
 | 
			
		||||
                        box.width, box.height * 0.9])
 | 
			
		||||
                plt.legend([myVars[ii] for ii in handels], labels, loc='upper center',
 | 
			
		||||
                        bbox_to_anchor=(0.5+0.06*first_itr, -0.15), fancybox=True, shadow=True, ncol=len(handels))
 | 
			
		||||
            elif len(handels) < 13:
 | 
			
		||||
                myVars[Output_dict_c['Type'][0]].set_position([box.x0, box.y0 + box.height * 0.04*int(len(handels)/2),
 | 
			
		||||
                        box.width, box.height * (1 - 0.04*int(len(handels)/2))])
 | 
			
		||||
                plt.legend([myVars[ii] for ii in handels], labels, loc='upper center',
 | 
			
		||||
                        bbox_to_anchor=(0.5+0.1*first_itr, -0.04*int(len(handels)/2)), fancybox=True, shadow=True, ncol=int(len(handels)/2)+1, handleheight=2)
 | 
			
		||||
            else:
 | 
			
		||||
                myVars[Output_dict_c['Type'][0]].set_position([box.x0, box.y0 + box.height * 0.04*int(len(handels)/2),
 | 
			
		||||
                        box.width, box.height * (1 - 0.04*int(len(handels)/2))])
 | 
			
		||||
                plt.legend([myVars[ii] for ii in handels], labels, loc='upper center',
 | 
			
		||||
                        bbox_to_anchor=(0.6+0.1*first_itr, -0.04*int(len(handels)/2)), fancybox=True, shadow=True, ncol=int(len(handels)/2)+1, handleheight=2)
 | 
			
		||||
            plt.title(Model_name)
 | 
			
		||||
            # plt.savefig(cwd+'/Results/'+Model_name+'.png', dpi=300)
 | 
			
		||||
            plt.savefig('PLOT_Mmax_param.png', dpi=300)
 | 
			
		||||
            # plt.show()
 | 
			
		||||
 | 
			
		||||
    # Run functions based on the configurations -------------------
 | 
			
		||||
    # Computing model
 | 
			
		||||
    if time_step_in_hour > time_win_in_hours:
 | 
			
		||||
@@ -681,7 +507,9 @@ def main(Input_catalog, Input_injection_rate, time_win_in_hours, time_step_in_ho
 | 
			
		||||
    if Plot_flag > 0:
 | 
			
		||||
        if Model_Param_array.any():
 | 
			
		||||
            logger.info("Plotting results")
 | 
			
		||||
            Plot_feature(Model_Param_array, Output_dict)
 | 
			
		||||
 | 
			
		||||
            import Mmax_plot # Import locally to ensure Mmax_plot is required only when Plot_flag > 0
 | 
			
		||||
            Mmax_plot.Plot_feature(Model_Param_array, Output_dict)
 | 
			
		||||
        else:
 | 
			
		||||
            logger.info("Model_Param_array is empty or not enough values to plot. Check 'csv' file.")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										206
									
								
								src/Mmax_plot.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								src/Mmax_plot.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,206 @@
 | 
			
		||||
import matplotlib.pyplot as plt
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def Plot_feature(Model_Param_array,
 | 
			
		||||
                 Output_dict,
 | 
			
		||||
                 End_time=None,
 | 
			
		||||
                 time_inj=None,
 | 
			
		||||
                 time_shut_in=None,
 | 
			
		||||
                 time_big_ev=None,
 | 
			
		||||
                 Model_name="",
 | 
			
		||||
                 logger=None):
 | 
			
		||||
    """
 | 
			
		||||
    Plotting function extracted from Mmax.py for plotting models and parameters.
 | 
			
		||||
 | 
			
		||||
    Parameters
 | 
			
		||||
    ----------
 | 
			
		||||
    Model_Param_array : np.ndarray
 | 
			
		||||
        Computed matrix of model parameters as rows in time.
 | 
			
		||||
    Output_dict : dict
 | 
			
		||||
        Dictionary describing each column in Model_Param_array.
 | 
			
		||||
    End_time : float, optional
 | 
			
		||||
        The last time to show in the X-axis (days), if desired.
 | 
			
		||||
    time_inj : float, optional
 | 
			
		||||
        Time of injection start (days), if you want a vertical line.
 | 
			
		||||
    time_shut_in : float, optional
 | 
			
		||||
        Time of shut-in (days), if you want a vertical line.
 | 
			
		||||
    time_big_ev : float, optional
 | 
			
		||||
        Time of large event (days), if you want a vertical line.
 | 
			
		||||
    Model_name : str, optional
 | 
			
		||||
        Model name used for the plot title.
 | 
			
		||||
    logger : logging.Logger, optional
 | 
			
		||||
        Logger for printing info messages. If None, no logging happens.
 | 
			
		||||
    """
 | 
			
		||||
    myVars = locals()
 | 
			
		||||
 | 
			
		||||
    # Function for findin min-max of all similar parameters
 | 
			
		||||
    def Extermom4All(Model_Param_array, itr_loc):
 | 
			
		||||
        Mat1D = np.reshape(Model_Param_array[:,itr_loc], -1)
 | 
			
		||||
        NotNone = np.isfinite(Mat1D)
 | 
			
		||||
        if np.min(Mat1D[NotNone])>0:
 | 
			
		||||
            return [np.min(Mat1D[NotNone])*0.95, np.max(Mat1D[NotNone])*1.05]
 | 
			
		||||
        elif np.min(Mat1D[NotNone])<0 and np.max(Mat1D[NotNone])>0:
 | 
			
		||||
            return [np.min(Mat1D[NotNone])*1.05, np.max(Mat1D[NotNone])*1.05]
 | 
			
		||||
        elif np.max(Mat1D[NotNone])<0:
 | 
			
		||||
            return [np.min(Mat1D[NotNone])*1.05, np.max(Mat1D[NotNone])*0.95]
 | 
			
		||||
 | 
			
		||||
    # Function for setting relevant lagends in the plot
 | 
			
		||||
    def Legend_label(loc):
 | 
			
		||||
        l = Output_dict_c['label'][loc]
 | 
			
		||||
        if Output_dict_c['b_method'][loc]:
 | 
			
		||||
            if Output_dict_c['cl'][loc]:
 | 
			
		||||
                l+='('+Output_dict_c['b_method'][loc]+', cl='+str(Output_dict_c['cl'][loc])+')'
 | 
			
		||||
            else:
 | 
			
		||||
                l+='('+Output_dict_c['b_method'][loc]+')'
 | 
			
		||||
 | 
			
		||||
        return l
 | 
			
		||||
 | 
			
		||||
    c_NotNone = [] # Removing all parameters with None or constant value
 | 
			
		||||
    for i in range(Model_Param_array.shape[1]):
 | 
			
		||||
        NotNone = np.isfinite(Model_Param_array[:,i])
 | 
			
		||||
        Eq_value = np.mean(Model_Param_array[:,i])
 | 
			
		||||
        if any(NotNone) and Eq_value != Model_Param_array[0,i]:
 | 
			
		||||
            c_NotNone.append(i)
 | 
			
		||||
        else:
 | 
			
		||||
            logger.info(f"No-PLOT: All values of {Output_dict['Type'][i]} are {Model_Param_array[0,i]}!")
 | 
			
		||||
 | 
			
		||||
    if len(c_NotNone) > 1:
 | 
			
		||||
        Model_Param_array = Model_Param_array[:,c_NotNone]
 | 
			
		||||
        # New output dictionary based on valid parameters for plotting
 | 
			
		||||
        Output_dict_c = {'Type':[], 'label':[], 'b_method':[], 'cl':[]}
 | 
			
		||||
        for i in range(len(c_NotNone)):
 | 
			
		||||
            Output_dict_c['Type'].append(Output_dict['Type'][c_NotNone[i]])
 | 
			
		||||
            Output_dict_c['label'].append(Output_dict['label'][c_NotNone[i]])
 | 
			
		||||
            Output_dict_c['b_method'].append(Output_dict['b_method'][c_NotNone[i]])
 | 
			
		||||
            Output_dict_c['cl'].append(Output_dict['cl'][c_NotNone[i]])
 | 
			
		||||
 | 
			
		||||
        coloring=['blue','g','r','c','m','y',
 | 
			
		||||
                  'brown', 'darkolivegreen', 'teal', 'steelblue', 'slateblue',
 | 
			
		||||
                  'purple', 'darksalmon', '#c5b0d5', '#c49c94',
 | 
			
		||||
                  '#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7', '#bcbd22', '#dbdb8d',
 | 
			
		||||
                  '#17becf', '#9edae5',
 | 
			
		||||
                  'brown', 'darkolivegreen', 'teal', 'steelblue', 'slateblue',]
 | 
			
		||||
        # All parameters to be plotted
 | 
			
		||||
        All_vars = Output_dict_c['Type'][2:]
 | 
			
		||||
        Uniqe_var = list(dict.fromkeys([s for s in All_vars if 'Standard Error' not in s])) #list(set(All_vars))
 | 
			
		||||
 | 
			
		||||
        # defining handels and labels to make final legend
 | 
			
		||||
        All_handels = ['p0']
 | 
			
		||||
        for i in range(1,len(All_vars)):
 | 
			
		||||
            All_handels.append('p'+str(i))
 | 
			
		||||
        handels = []
 | 
			
		||||
        labels = []
 | 
			
		||||
 | 
			
		||||
        # itr_loc: location of paramteres with similar type
 | 
			
		||||
        itr_loc = np.where(np.array(All_vars) == Uniqe_var[0])[0]+2
 | 
			
		||||
        fig, myVars[Output_dict_c['Type'][0]] = plt.subplots(1,1,figsize=(8+int(len(All_vars)/3),6))
 | 
			
		||||
        fig.subplots_adjust(right=1-len(Uniqe_var)*0.09)
 | 
			
		||||
        if Output_dict_c['label'][itr_loc[0]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
            myVars[All_handels[itr_loc[0]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= 'k', ls='--', lw = 2)
 | 
			
		||||
        else:
 | 
			
		||||
            myVars[All_handels[itr_loc[0]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= coloring[itr_loc[0]])
 | 
			
		||||
        handels.append(All_handels[itr_loc[0]-2])
 | 
			
		||||
        labels.append(Legend_label(itr_loc[0]))
 | 
			
		||||
        myVars[Output_dict_c['Type'][0]].set_ylabel(Output_dict_c['Type'][itr_loc[0]])
 | 
			
		||||
        myVars[Output_dict_c['Type'][0]].set_ylim(Extermom4All(Model_Param_array, itr_loc)[0], Extermom4All(Model_Param_array, itr_loc)[1])
 | 
			
		||||
        myVars[Output_dict_c['Type'][0]].set_xlabel('Day (From start of the recording)')
 | 
			
		||||
        if End_time:
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].set_xlim(0,End_time)
 | 
			
		||||
 | 
			
		||||
        # Plotting statndard error (if exists)
 | 
			
		||||
        if  itr_loc[0]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[0]+1] == 'Standard Error':
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                          Model_Param_array[:,itr_loc[0]] -  Model_Param_array[:,itr_loc[0]+1],
 | 
			
		||||
                                                          Model_Param_array[:,itr_loc[0]] +  Model_Param_array[:,itr_loc[0]+1], color= coloring[itr_loc[0]], alpha=0.1)
 | 
			
		||||
        # Plotting similar parameters on one axis
 | 
			
		||||
        for j in range(1,len(itr_loc)):
 | 
			
		||||
            if Output_dict_c['label'][itr_loc[j]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
                myVars[All_handels[itr_loc[j]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= 'k', ls='--', lw = 2)
 | 
			
		||||
            else:
 | 
			
		||||
                myVars[All_handels[itr_loc[j]-2]], = myVars[Output_dict_c['Type'][0]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= coloring[itr_loc[j]])
 | 
			
		||||
            handels.append(All_handels[itr_loc[j]-2])
 | 
			
		||||
            labels.append(Legend_label(itr_loc[j]))
 | 
			
		||||
 | 
			
		||||
            # Plotting statndard error (if exists)
 | 
			
		||||
            if  itr_loc[0]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[j]+1] == 'Standard Error':
 | 
			
		||||
                myVars[Output_dict_c['Type'][0]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                              Model_Param_array[:,itr_loc[j]] -  Model_Param_array[:,itr_loc[j]+1],
 | 
			
		||||
                                                              Model_Param_array[:,itr_loc[j]] +  Model_Param_array[:,itr_loc[j]+1], color= coloring[itr_loc[j]], alpha=0.1)
 | 
			
		||||
        first_itr = 0
 | 
			
		||||
        # Check if there is any more parameter to be plotted in second axes
 | 
			
		||||
        # The procedure is similar to last plots.
 | 
			
		||||
        if len(Uniqe_var) > 1:
 | 
			
		||||
            for i in range(1,len(Uniqe_var)):
 | 
			
		||||
                itr_loc = np.where(np.array(All_vars) == Uniqe_var[i])[0]+2
 | 
			
		||||
                myVars[Uniqe_var[i]] = myVars[Output_dict_c['Type'][0]].twinx()
 | 
			
		||||
                # if it is third or more axis, make a distance between them
 | 
			
		||||
                if first_itr == 0:
 | 
			
		||||
                    first_itr += 1
 | 
			
		||||
                    set_right = 1
 | 
			
		||||
                else:
 | 
			
		||||
                    set_right = 1 + first_itr*0.2
 | 
			
		||||
                    first_itr += 1
 | 
			
		||||
                    myVars[Uniqe_var[i]].spines.right.set_position(("axes", set_right))
 | 
			
		||||
                if Output_dict_c['label'][itr_loc[0]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
                    myVars[All_handels[itr_loc[0]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= 'k', ls='--', lw = 2)
 | 
			
		||||
                else:
 | 
			
		||||
                    myVars[All_handels[itr_loc[0]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[0]], c= coloring[itr_loc[0]])
 | 
			
		||||
                handels.append(All_handels[itr_loc[0]-2])
 | 
			
		||||
                labels.append(Legend_label(itr_loc[0]))
 | 
			
		||||
                myVars[Uniqe_var[i]].set_ylabel(Output_dict_c['Type'][itr_loc[0]])
 | 
			
		||||
                myVars[Uniqe_var[i]].yaxis.label.set_color(coloring[itr_loc[0]])
 | 
			
		||||
                myVars[Uniqe_var[i]].spines["right"].set_edgecolor(coloring[itr_loc[0]])
 | 
			
		||||
                myVars[Uniqe_var[i]].tick_params(axis='y', colors= coloring[itr_loc[0]])
 | 
			
		||||
                myVars[Uniqe_var[i]].set_ylim(Extermom4All(Model_Param_array, itr_loc)[0], Extermom4All(Model_Param_array, itr_loc)[1])
 | 
			
		||||
                if itr_loc[0]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[0]+1] == 'Standard Error':
 | 
			
		||||
                    myVars[Uniqe_var[i]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                      Model_Param_array[:,itr_loc[0]] -  Model_Param_array[:,itr_loc[0]+1],
 | 
			
		||||
                                                      Model_Param_array[:,itr_loc[0]] +  Model_Param_array[:,itr_loc[0]+1], color= coloring[itr_loc[0]], alpha=0.1)
 | 
			
		||||
 | 
			
		||||
                for j in range(1,len(itr_loc)):
 | 
			
		||||
                    if Output_dict_c['label'][itr_loc[j]] == 'True Max-Mag': # plot with dash-line
 | 
			
		||||
                        myVars[All_handels[itr_loc[j]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= 'k', ls = '--', lw = 2)
 | 
			
		||||
                    else:
 | 
			
		||||
                        myVars[All_handels[itr_loc[j]-2]], = myVars[Uniqe_var[i]].plot(Model_Param_array[:,1]/24/3600, Model_Param_array[:,itr_loc[j]], c= coloring[itr_loc[j]])
 | 
			
		||||
                    handels.append(All_handels[itr_loc[j]-2])
 | 
			
		||||
                    labels.append(Legend_label(itr_loc[j]))
 | 
			
		||||
                    if itr_loc[j]+1 < len(Output_dict_c['Type']) and Output_dict_c['Type'][itr_loc[j]+1] == 'Standard Error':
 | 
			
		||||
                        myVars[Uniqe_var[i]].fill_between(Model_Param_array[:,1]/24/3600,
 | 
			
		||||
                                                          Model_Param_array[:,itr_loc[j]] -  Model_Param_array[:,itr_loc[j]+1],
 | 
			
		||||
                                                          Model_Param_array[:,itr_loc[j]] +  Model_Param_array[:,itr_loc[j]+1], color= coloring[itr_loc[j]], alpha=0.1)
 | 
			
		||||
 | 
			
		||||
        # If there are timing, plot them as vertical lines
 | 
			
		||||
        if time_inj:
 | 
			
		||||
            myVars['l1'], = plt.plot([time_inj,time_inj], [Extermom4All(Model_Param_array, itr_loc)[0],Extermom4All(Model_Param_array, itr_loc)[1]], ls='--', c='k')
 | 
			
		||||
            handels.append('l1')
 | 
			
		||||
            labels.append('Start-inj')
 | 
			
		||||
        if time_shut_in:
 | 
			
		||||
            myVars['l2'], = plt.plot([time_shut_in,time_shut_in], [Extermom4All(Model_Param_array, itr_loc)[0],Extermom4All(Model_Param_array, itr_loc)[1]], ls='-.', c='k')
 | 
			
		||||
            handels.append('l2')
 | 
			
		||||
            labels.append('Shut-in')
 | 
			
		||||
        if time_big_ev:
 | 
			
		||||
            myVars['l3'], = plt.plot([time_big_ev,time_big_ev], [Extermom4All(Model_Param_array, itr_loc)[0],Extermom4All(Model_Param_array, itr_loc)[1]], ls='dotted', c='k')
 | 
			
		||||
            handels.append('l3')
 | 
			
		||||
            labels.append('Large-Ev')
 | 
			
		||||
 | 
			
		||||
        box = myVars[Output_dict_c['Type'][0]].get_position()
 | 
			
		||||
        if len(handels) < 6:
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].set_position([box.x0, box.y0 + box.height * 0.1,
 | 
			
		||||
                                                           box.width, box.height * 0.9])
 | 
			
		||||
            plt.legend([myVars[ii] for ii in handels], labels, loc='upper center',
 | 
			
		||||
                       bbox_to_anchor=(0.5+0.06*first_itr, -0.15), fancybox=True, shadow=True, ncol=len(handels))
 | 
			
		||||
        elif len(handels) < 13:
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].set_position([box.x0, box.y0 + box.height * 0.04*int(len(handels)/2),
 | 
			
		||||
                                                           box.width, box.height * (1 - 0.04*int(len(handels)/2))])
 | 
			
		||||
            plt.legend([myVars[ii] for ii in handels], labels, loc='upper center',
 | 
			
		||||
                       bbox_to_anchor=(0.5+0.1*first_itr, -0.04*int(len(handels)/2)), fancybox=True, shadow=True, ncol=int(len(handels)/2)+1, handleheight=2)
 | 
			
		||||
        else:
 | 
			
		||||
            myVars[Output_dict_c['Type'][0]].set_position([box.x0, box.y0 + box.height * 0.04*int(len(handels)/2),
 | 
			
		||||
                                                           box.width, box.height * (1 - 0.04*int(len(handels)/2))])
 | 
			
		||||
            plt.legend([myVars[ii] for ii in handels], labels, loc='upper center',
 | 
			
		||||
                       bbox_to_anchor=(0.6+0.1*first_itr, -0.04*int(len(handels)/2)), fancybox=True, shadow=True, ncol=int(len(handels)/2)+1, handleheight=2)
 | 
			
		||||
        plt.title(Model_name)
 | 
			
		||||
        # plt.savefig(cwd+'/Results/'+Model_name+'.png', dpi=300)
 | 
			
		||||
        plt.savefig('PLOT_Mmax_param.png', dpi=300)
 | 
			
		||||
        # plt.show()
 | 
			
		||||
		Reference in New Issue
	
	Block a user