Esempio n. 1
0
def plot_events(real,pred,meta,real_,pred_, label=None):
    from matplotlib.pylab import plt
    import random
    fig,ax = plt.subplots(figsize=(15, .8))
    ax.set_title(label)
    plt.xlim(0,max(meta[1],10))
    ax.set_xticks(np.arange(0,max(real[-1][1],10),.1),minor=True)
    maxsize=20
# random.random()/4
    for i in range(min(maxsize,len(pred_))):
        d = pred_[i]
        plt.axvspan(d[0], d[1], 0, 0.6,linewidth=0,edgecolor='k',facecolor='#edb4b4', alpha=.6)
        plt.text((d[1] + d[0]) / 2, 0.2,f'{i}' , horizontalalignment='center', verticalalignment='center')
    for i in range(min(maxsize,len(pred))):
        d = pred[i]
        plt.axvspan(d[0], d[1], 0.0, 0.6,linewidth=0,edgecolor='k',facecolor='#a31f1f', alpha=.6)
        plt.text((d[1] + d[0]) / 2, 0.2,f'{i}' , horizontalalignment='center', verticalalignment='center')
#     maxsize=len(real)
    for i in range(min(maxsize,len(real_))):
        gt = real_[i]
        plt.axvspan(gt[0], gt[1], 0.4, 1,linewidth=0,edgecolor='k',facecolor='#d2f57a', alpha=.6)
        plt.text((gt[1] + gt[0]) / 2, 0.8,f'{i}' , horizontalalignment='center', verticalalignment='center')
        
    for i in range(min(maxsize,len(real))):
        gt = real[i]
        plt.axvspan(gt[0], gt[1], 0.4, 1,linewidth=0,edgecolor='k',facecolor='#1fa331', alpha=.6)
        plt.text((gt[1] + gt[0]) / 2, 0.8,f'{i}' , horizontalalignment='center', verticalalignment='center')
    # plt.grid(True)
    plt.minorticks_on()
    ax.set(yticks=[.25,.75], yticklabels=['P','R'])
    # plt.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.2)
    plt.show()
Esempio n. 2
0
def getGraph():
    for i, clf in enumerate((svm, rbf_svc, rbf_svc_tunning)):
        # Se grafican las fronteras
        plt.subplot(2, 2, i + 1)
        plt.subplots_adjust(wspace=0.4, hspace=0.4)

        Z = clf.predict(np.c_[x_matrizSetEntrenamientoVect, y_clases])

        #Color en las gráficas
        Z = Z.reshape(x_matrizSetEntrenamientoVect.shape)
        plt.contourf(x_matrizSetEntrenamientoVect,
                     y_clases,
                     Z,
                     cmap=plt.cm.Paired,
                     alpha=0.8)

        #Puntos de entrenamiento
        plt.scatter(x_matrizSetEntrenamientoVect[:, 0],
                    x_matrizSetEntrenamientoVect[:, 1],
                    c=y_clases,
                    cmap=plt.cm.Paired)
        plt.xlabel('Longitud Sepal')
        plt.ylabel('Peso Sepal')
        plt.xlim(x_matrizSetEntrenamientoVect.min(),
                 x_matrizSetEntrenamientoVect.max())
        plt.ylim(y_clases.min(), y_clases.max())
        plt.xticks(())
        plt.yticks(())
        plt.title(titles[i])

    plt.show()
Esempio n. 3
0
def plot_events(real, pred, real_, pred_, label=None):
    from matplotlib.pylab import plt
    import random
    fig, ax = plt.subplots(figsize=(10, 2))
    ax.set_title(label)
    plt.xlim(0, max(real[-1][1], 10))
    ax.set_xticks(np.arange(0, max(real[-1][1], 10), .1), minor=True)
    maxsize = 20
    for i in range(min(maxsize, len(pred_))):
        d = pred_[i]
        plt.axvspan(d[0],
                    d[1],
                    0,
                    0.4,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='m',
                    alpha=.6)

    for i in range(min(maxsize, len(pred))):
        d = pred[i]
        plt.axvspan(d[0],
                    d[1],
                    0.1,
                    0.5,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='r',
                    alpha=.6)


#     maxsize=len(real)
    for i in range(min(maxsize, len(real_))):
        gt = real_[i]
        plt.axvspan(gt[0],
                    gt[1],
                    0.6,
                    1,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='y',
                    alpha=.6)

    for i in range(min(maxsize, len(real))):
        gt = real[i]
        plt.axvspan(gt[0],
                    gt[1],
                    0.5,
                    .9,
                    linewidth=1,
                    edgecolor='k',
                    facecolor='g',
                    alpha=.6)
    plt.grid(True)
    plt.minorticks_on()
    plt.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.2)
Esempio n. 4
0
 def plot_spectrum():
     # Plot telluric lines and fits
     plt.plot(spec['w'], spec['s'], label='Stellar Spectrum')
     plt.plot(spec['w'], mod, label='Telluric Model')
     plt.plot(spec['w'], spec['s'] - mod + 0.5, label='Residuals')
     plt.xlim(6275, 6305)
     plt.ylim(0.0, 1.05)
     plt.xlabel('Wavelength (A)')
     plt.ylabel('Intensity')
     plt.title('Telluric Lines')
Esempio n. 5
0
 def plot_spectrum():
     # Plot telluric lines and fits
     plt.plot(spec['w'],spec['s'],label='Stellar Spectrum')
     plt.plot(spec['w'],mod,label='Telluric Model')
     plt.plot(spec['w'],spec['s']-mod+0.5,label='Residuals')
     plt.xlim(6275,6305)
     plt.ylim(0.0,1.05)
     plt.xlabel('Wavelength (A)')
     plt.ylabel('Intensity')
     plt.title('Telluric Lines')
Esempio n. 6
0
def plot_score_dist(spacing, std_along, prob_miss, max_distance):
    from matplotlib.pylab import plt
    plt.close("Score Dist")
    plt.figure("Score Dist")
    d = np.linspace(0, max_distance, 500)
    plt.plot(d, [score_dist(di, spacing, std_along, prob_miss) for di in d])
    plt.vlines(spacing, 0, 1)
    plt.vlines(spacing * 2, 0, 1, ls='--')
    plt.annotate("Miss-detect the next mine", (spacing * 2, 0.5), (12, 0),
                 textcoords='offset points')
    plt.ylabel('$p(d)$')
    plt.xlabel('$d$')
    plt.grid()
    plt.xticks(np.arange(max_distance))
    plt.xlim(0, max_distance)
    plt.savefig('score_dist.pdf')
Esempio n. 7
0
def plot_piledspectra():
    fig = plt.figure(figsize = (6,8)) 
    plt.xlim(5000,9000)
    
    specindex = range(0,100,10)
    offset = np.arange(0,len(specindex)) * 0.5
    ylim = [0.5, offset[-1] + 1.3]
    plt.ylim(ylim[0], ylim[1])
    
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')
    
    plt.xlabel(r'Restrame Wavelength [ \AA\ ]')
    plt.ylabel(r'Flux')
    
    line_wave = [5175., 5892., 6562.8, 8498., 8542., 8662.] 
        #       ['Mgb', 'NaD', 'Halpha', 'CaT', 'CaT', 'CaT']
    for line in line_wave:
            x = [line, line]
            y = [ylim[0], ylim[1]]
            plt.plot(x, y, c= 'gray', linewidth=1.0)
    
    plt.annotate(r'CaT', xy=(8540.0, ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'H$\alpha$', xy=(6562.8, ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'NaD', xy=(5892., ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'Mg$\beta$', xy=(5175., ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    
    for i,j in zip(specindex,offset):
        iraf.noao.onedspec.continuum(input = GCssorted.ORIGINALFILE.iloc[i] + '[1]', output = '/Volumes/VINCE/OAC/continuum.fits',
            type = 'ratio', naverage = '3', function = 'spline3',
            order = '5', low_reject = '2.0', high_reject = '2.0', niterate = '10')
    
        data = fits.getdata('/Volumes/VINCE/OAC/continuum.fits', 0)
        
        hdu = fits.open(GCssorted.ORIGINALFILE.iloc[i])
        header1 = hdu[1].header
        lamRange = header1['CRVAL1']  + np.array([0., header1['CD1_1'] * (header1['NAXIS1'] - 1)]) 
        wavelength = np.linspace(lamRange[0],lamRange[1], header1['NAXIS1'])
        hdu.close()
    
        zp = 1. + (GCssorted.VREL.iloc[i] / 299792.458)
      
        plt.plot(wavelength/zp, gaussian_filter(data,2) + j, c = 'black', lw=1)
        os.remove('/Volumes/VINCE/OAC/continuum.fits')
def getGraph():
    for i, clf in enumerate((svm, rbf_svc, rbf_svc_tunning)):
     # Se grafican las fronteras 
     plt.subplot(2, 2, i + 1)
     plt.subplots_adjust(wspace=0.4, hspace=0.4)
    
     Z = clf.predict(np.c_[x_matrizSetEntrenamientoVect, y_clases])
    
     #Color en las gráficas
     Z = Z.reshape(x_matrizSetEntrenamientoVect.shape)
     plt.contourf(x_matrizSetEntrenamientoVect, y_clases, Z, cmap=plt.cm.Paired, alpha=0.8)
    
     #Puntos de entrenamiento
     plt.scatter(x_matrizSetEntrenamientoVect[:, 0], x_matrizSetEntrenamientoVect[:, 1], c=y_clases, cmap=plt.cm.Paired)
     plt.xlabel('Longitud Sepal')
     plt.ylabel('Peso Sepal')
     plt.xlim(x_matrizSetEntrenamientoVect.min(), x_matrizSetEntrenamientoVect.max())
     plt.ylim(y_clases.min(), y_clases.max())
     plt.xticks(())
     plt.yticks(())
     plt.title(titles[i])
    
    plt.show()
Esempio n. 9
0
GCs = pd.read_csv('/Volumes/VINCE/OAC/GCs_903.csv', dtype = {'ID': object}, comment = '#')

# ----------------------------------
rep1 = GCs[GCs.Alt1.isin(GCs.ID)]
df1 = pd.DataFrame()
df2 = pd.DataFrame()
for j in range(0,len(rep1)):
	df1.iloc[j] = rep1.iloc[j]



x = VIMOS['VREL_helio'] 
xerr = VIMOS['VERR'] 
y = SchuberthMatch['HRV'] 
yerr = SchuberthMatch['e.1'] 

print 'rms (VIMOS - Schuberth) GCs = ', np.std(x-y)

plt.close('all')
plt.figure(figsize=(6,6))
plt.errorbar(x, y, yerr= yerr, xerr = xerr, fmt = 'o', c ='black', label = 'Schuberth et al.')
plt.plot([-200, 2200], [-200, 2200], '--k')
plt.xlim(-200,2200)
plt.ylim(-200,2200)

x = VIMOS['r_auto'] 
y = SchuberthMatch['Rmag'] 

plt.scatter(x, y, c ='black')

Esempio n. 10
0
mask = (((result['g_auto'] - result['r_auto']) < (0.2 + 0.6 * (result['g_auto'] - result['i_auto']))) &
        ((result['g_auto'] - result['r_auto']) > (-0.2 + 0.6 * (result['g_auto'] - result['i_auto']))) &
        ((result['g_auto'] - result['i_auto']) > 0.5) & 
        ((result['g_auto'] - result['i_auto']) < 1.3) &
        ((result['i_auto']) < 24))

subset = result[mask]
subset = subset.sample(n=1000)

plt.figure()
plt.scatter(result['g_auto'] - result['i_auto'], result['g_auto'] - result['r_auto'], s=10, c='gray', edgecolor='none', alpha = 0.5)
plt.scatter(subset['g_auto'] - subset['i_auto'], subset['g_auto'] - subset['r_auto'], s=20, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['i_auto'], GCs['g_auto'] - GCs['r_auto'], s=10, c='red', edgecolor='none')
plt.xlabel('(g - i)')
plt.ylabel('(g - r)')
plt.xlim(-1,4)
plt.ylim(-1,4)

plt.figure()
plt.scatter(subset['g_auto'] - subset['r_auto'], subset['r_auto'], s=30, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['r_auto'], GCs['i_auto'], s=8, c='red', edgecolor='none')
plt.ylim(13,24)
plt.gca().invert_yaxis()
plt.xlabel('(g - i)')
plt.ylabel('i')

plt.figure()
plt.scatter(result['g_auto'] - result['u_auto'], result['g_auto'] - result['r_auto'], s=10, c='gray', edgecolor='none', alpha = 0.5)
plt.scatter(subset['g_auto'] - subset['u_auto'], subset['g_auto'] - subset['r_auto'], s=20, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['u_auto'], GCs['g_auto'] - GCs['r_auto'], s=10, c='red', edgecolor='none')
plt.scatter(galaxies['g_auto'] - galaxies['u_auto'], galaxies['g_auto'] - galaxies['r_auto'], s=10, c='green', edgecolor='none')
            color='firebrick',
            linestyle='--')
sns.kdeplot(APDF2,
            bw=1.5,
            linewidth=3,
            label='APDF2',
            color='mediumseagreen',
            linestyle='--')
sns.kdeplot(APDF3,
            bw=1.5,
            linewidth=3,
            label='APDF3',
            color='goldenrod',
            linestyle='--')
plt.xlabel('Temperature ($^{\circ}$C)', fontsize=18, **hfont)
plt.xlim(1, 20)
for tick in ax.xaxis.get_major_ticks():
    tick.label.set_fontsize(16)
for tick in ax.yaxis.get_major_ticks():
    tick.label.set_fontsize(16)
plt.title('(b)', fontsize=18, **hfont)
#%%
xL = 0
yL = 0
sigma = 6
bias = 20

res = 3

x1 = np.random.normal(xL + bias, sigma, 3000)[::res]
x2 = np.append(np.random.normal(xL, sigma, 2000),
Esempio n. 12
0
assert data.shape == (240, len(headers))

# In[100]:

get_ipython().run_cell_magic(
    'latex', '',
    '$\\textbf{Visualize the Correlations}: $\n$\\text{Cor}(X_i,Y_j) = \\frac{\\text{Cov}(X_i,Y_j)}{\\sigma_{X_i}\\sigma_{Y_j}}$'
)

# In[101]:

R = np.corrcoef(data.T)
plt.figure(figsize=(10, 8))
plt.pcolor(R)
plt.colorbar()
plt.xlim([0, len(headers)])
plt.ylim([0, len(headers)])
plt.xticks(np.arange(32) + 0.5, np.array(headers), rotation='vertical')
plt.yticks(np.arange(32) + 0.5, np.array(headers))
plt.show()

# In[108]:

#Lets fit both the models using PCA/FA down to two dimensions.

#construct a function implementing the factor analysis which returns a vector of n_components largest
# variances and the corresponding components (as column vectors in a matrix). You can
# check your work by using decomposition.FactorAnalysis from sklearn


#### ~THIS FUNCTION IS WAS A STAB, NEW CODE HERE: ###########
Esempio n. 13
0
y = SchuberthMatch['HRV']
yerr = SchuberthMatch['e.1']

print 'rms (VIMOS - Schuberth) GCs = ', np.std(x - y)

plt.close('all')
plt.figure(figsize=(6, 6))
plt.errorbar(x,
             y,
             yerr=yerr,
             xerr=xerr,
             fmt='o',
             c='black',
             label='Schuberth et al.')
plt.plot([-200, 2200], [-200, 2200], '--k')
plt.xlim(-200, 2200)
plt.ylim(-200, 2200)

x = VIMOS['r_auto']
y = SchuberthMatch['Rmag']

plt.scatter(x, y, c='black')

# ----------------------------------
# ----------------------------------

cat1 = coords.SkyCoord(stars['RA_g'],
                       stars['DEC_g'],
                       unit=(u.degree, u.degree))
cat2 = coords.SkyCoord(S_Stars['RA'],
                       S_Stars['DEC'],
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)
plt.grid()

plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                 train_scores_mean + train_scores_std, alpha=0.1,
                 color="r")
plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
                 test_scores_mean + test_scores_std, alpha=0.1, color="g")
plt.plot(train_sizes, train_scores_mean, '-', color="r",
         label="Training score")
plt.plot(train_sizes, test_scores_mean, '-', color="g",
         label="Cross-validation score")
plt.ylim(0,1.2)
plt.xlim(0,200)
plt.legend(loc="best")
plt.xlabel("Train test size")
plt.savefig("learning_curves.png")
plt.close("all")


# plot the model vs the predictions

for what_plot in [0,1,2,3]:
    fig=plt.figure(figsize=(16,8))
    #
    ax1 = fig.add_subplot(1,2,1); ax2 = fig.add_subplot(1,2,2)
    ax1.tick_params(labelsize=20); ax2.tick_params(labelsize=20)
    #
    if(what_plot==3):
Esempio n. 15
0
recorded_h = df['EOG_H'].as_matrix()

classifier = cal_mod.OrbitClassify(300, 200, 0.6, 0.5)
classifier.setLowPassfilter(2, 0.17)
rec_v = classifier.LowPassFilter(df['EOG_V'].as_matrix())

plt.subplot(3, 1, 1)
plt.plot(rec_v)

maxtab, mintab = peak_example.peakdet(rec_v, .3)

plt.subplot(3, 1, 2)
plt.plot(rec_v)
plt.scatter(np.array(maxtab)[:, 0], np.array(maxtab)[:, 1], color='blue')
plt.scatter(np.array(mintab)[:, 0], np.array(mintab)[:, 1], color='red')
plt.xlim(0, 900)
""" buffer  Murtaza """
# buffer_vv = np.array([])
# for i in range(0,len(rec_v)):
#     if len(buffer_vv) < 50:
#         buffer_vv = np.append(buffer_vv,rec_v)
#     else:
#         buffer_vv = buffer_vv[1:]
#         buffer_vv = np.append(buffer_vv,rec_v)

#     if len(buffer_vv) > 1:
#         rec_v = rec_v - np.mean(buffer_vv)
""" Simple Moving Average """

Nma1 = 20
A1 = np.ones(Nma1) / 20.0
Esempio n. 16
0
 def drawErrorPlot(self, error_list):
     plt.xlim(0, len(error_list))
     plt.xlabel('Squared Error')
     plt.plot(error_list)
     plt.show()
Esempio n. 17
0
#graph 2 (contour graph)
x = np.arange(-5, 5, 0.01)
y = np.arange(-5, 5, 0.01)

X, Y = np.meshgrid(x, y)
Z = function_1(np.array([X, Y]))

idx = 1
plt.subplot(2, 2, idx)
idx += 1
plt.plot( x_process[:,0], x_process[:,1], '.-', color="blue") #수렴과정
plt.contour(X, Y, Z)

plt.ylim(-5, 5)
plt.xlim(-5, 5)

plt.plot(0, 0, '+', color = "red")  #극소점
plt.show()


#graph 3 (3 dimensional graph)
x, x_process = gradient_descent_process(function_1, np.array([-3.0, 4.0]), L = 0.1, I = 50 )

x = np.arange(-5, 5, 0.01)
y = np.arange(-5, 5, 0.01)
x, y = np.meshgrid(x, y)
z = function_1(np.array([X, Y]))


fig = plt.figure()
Esempio n. 18
0
import numpy as np
from matplotlib.pylab import plt


fig, ax = plt.subplots()
plt.legend()
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
plt.grid()
plt.ylim(-4.5,4.5)
plt.xlim(-5.5,5.5)
ax.xaxis.set_ticks([-5,-4,-3,-2,-1,0,1,2,3,4,5])
plt.show()	

Esempio n. 19
0
         color='k',
         alpha=0.8)
plt.scatter(x1, y1, color=firstcloudcolor, alpha=1, label='first distribution')
plt.scatter(x2,
            y2,
            color=secondcloudcolor,
            alpha=1,
            marker='+',
            s=60,
            label='second distribution')
plt.scatter(xL, yL, color='k', marker='P', s=135, label='release location')

plt.xlabel('$^{\circ}$E', fontsize=18)
ax.tick_params(labelbottom=False, labelleft=False)
plt.title('(c)', fontsize=18)
plt.xlim(-40, 40)
plt.ylim(-40, 40)

plt.legend(bbox_to_anchor=(1.92, 1.05))

step = 8
xs, ys = np.mgrid[-44:48:step, -44:48:step]
vs = np.ones(xs.shape, dtype=bool)

xss = xs[:, 0]
yss = ys[0]

boxes = []
for i in range(len(x1)):
    nex = find_nearest_index(xss, x1[i])
    ney = find_nearest_index(yss, y1[i])
Esempio n. 20
0
import numpy as np
from matplotlib.pylab import plt


def relu(_x):
    '''nn一个激活函数'''
    return np.maximum(0, _x)


if __name__ == "__main__":
    x = np.arange(-5.0, 5.0, 0.1)
    y = relu(x)
    plt.plot(x, y)
    plt.xlim(-6, 6)
    plt.show()
Esempio n. 21
0
 def drawErrorPlot(self, error_list):
     plt.xlim(0, len(error_list))
     plt.xlabel('Squared Error')
     plt.plot(error_list)
     plt.show()
Esempio n. 22
0
    Y = np.arange(-10, 10, 0.01)

    X, Y = np.meshgrid(X, Y)
    Z = function_1(np.array([X, Y]))

    # 외곽선 단순화
    mask = Z > 10
    Z[mask] = 0

    plt.subplot(2, 3, idx)
    idx += 1
    plt.plot(x_process[:, 0], x_process[:, 1], '.-', color="blue")
    plt.contour(X, Y, Z)

    plt.ylim(-10, 10)
    plt.xlim(-10, 10)

    plt.plot(0, 0, '+', color="red")  # 극소점
    plt.title(key)

plt.show()

#graph comparision _2 (2 dimensional)

idx = 1
for key in optimizers:
    optimizer = optimizers[key]

    def process(f, init_x, I=100):
        x = init_x
        process = []
Esempio n. 23
0
# data_name = "blinkfrequency.csv"
# data_name = "jun_video.csv"

df = pd.DataFrame.from_csv(data_path + data_name)
# df.index = pd.to_datetime(df['DATE'], unit='s')
recorded_v = df['EOG_V'].as_matrix()
recorded_h = df['EOG_H'].as_matrix()
"""Show Original Data"""
plt.plot(recorded_v, label="Vertical EOG")
plt.plot(recorded_h, label="Horizental EOG")
plt.legend()
plt.title("Original Data", fontsize=25)
plt.xlabel("Time", fontsize=20)
plt.ylabel("EOG Level ( Range in $\mu$$V$ )", fontsize=20)
plt.xlim(0, 1200)
plt.show()
"""Simple Moving Average"""
Nma1 = 10
A1 = np.ones(Nma1) / 10.0
Vv_SMA = np.convolve(recorded_v, A1, 'valid')
Vh_SMA = np.convolve(recorded_h, A1, 'valid')
plt.plot(Vv_SMA, label="Vertical EOG")
plt.plot(Vh_SMA, label="Horizental EOG")
plt.legend()
plt.title("SMA Data", fontsize=25)
plt.xlabel("Time", fontsize=20)
plt.ylabel("EOG Level ( Range in $\mu$$V$ )", fontsize=20)
plt.xlim(0, 1200)
plt.show()
"""Sampling windows size 10 , 0.1 sec"""