def gen_nonlin(layer_width):
    std = 0.1
    alpha = 0.00001

    input_set, output_set, valid_in_batches, valid_out_batches, train_ref_std = lowpass(
    )

    ### GEN LAYERS
    x = tf.placeholder(tf.float32, shape=[None, input_set.shape[1]], name='x')
    y = tf.placeholder(tf.float32, shape=[None, output_set.shape[1]], name='y')

    w0 = tf.Variable(tf.truncated_normal([input_set.shape[1], layer_width],
                                         stddev=std),
                     name='w0')
    b0 = tf.Variable(tf.truncated_normal([1, layer_width], stddev=std),
                     name='b0')
    lay0 = tf.matmul(x, w0) + b0
    lay0 = tf.nn.relu(lay0)

    w1 = tf.Variable(tf.truncated_normal([layer_width, layer_width],
                                         stddev=std),
                     name='w1')
    b1 = tf.Variable(tf.truncated_normal([1, layer_width], stddev=std),
                     name='b1')
    lay1 = tf.matmul(lay0, w1) + b1
    lay1 = tf.nn.relu(lay1)

    w2 = tf.Variable(tf.truncated_normal([layer_width, output_set.shape[1]],
                                         stddev=std),
                     name='w2')
    b2 = tf.Variable(tf.truncated_normal([1, output_set.shape[1]], stddev=std),
                     name='b2')
    lay2 = tf.matmul(lay1, w2) + b2

    P = lay2

    MSE = tf.reduce_mean(tf.square(P - y))
    L2 = alpha * (tf.nn.l2_loss(w0) + tf.nn.l2_loss(w1) + tf.nn.l2_loss(w2))

    optimizer = tf.train.AdamOptimizer().minimize(MSE + L2)

    global_step = tf.Variable(0, name='global_step', trainable=False)
    run_time = tf.Variable(0, name='run_time', trainable=False)

    saver = tf.train.Saver({
        "w0": w0,
        "b0": b0,
        "w1": w1,
        "b1": b1,
        "w2": w2,
        "b2": b2,
        "global_step": global_step,
        "run_time": run_time
    })

    return x, y, MSE, P, optimizer, global_step, run_time, saver, input_set, output_set, valid_in_batches, valid_out_batches, train_ref_std
#read_DBY_output=read_DBY(39,1,66.583436840,9,x_max,1) #UF 15-39, RS1
#read_DBY_output=read_DBY(40,3,20.767465080,10,x_max,1) #UF 15-40, RS3
#read_DBY_output=read_DBY(41,1,57.298446790,11,x_max,1) #UF 15-41, RS1
#read_DBY_output=read_DBY(42,4,43.058185590,12,x_max,1) #UF 15-42, RS4
#read_DBY_output=read_DBY(43,4,23.293418545,13,x_max,1) #UF 15-43, RS4
remove_60Hz_slope_output = remove_60Hz_slope(read_DBY_output, x_max)
print('UTC reference time: %s' % remove_60Hz_slope_output[2])
gw_time, gw_data, ir_time, ir_data = chop_gw_ir(remove_60Hz_slope_output)

gw_time = gw_time
gw = gw_data
ir_time = ir_time
ir = ir_data

gw_peak = gw_time[np.argmax(gw)]
print(gw_peak)
#plt.plot(gw_time-gw_peak,gw,ir_time-gw_peak,ir)
#plt.show()

lpf_gw_data = lowpass(gw, 100e3)
lpf_ir_data = lowpass(ir, 100e3)

lpf_gw_peak = gw_time[np.argmax(lpf_gw_data)]
print(lpf_gw_peak)

Dt = (lpf_gw_peak - gw_peak)
print("Time difference between LPF peak and raw peak=%r" % Dt)
plt.plot((gw_time - gw_peak) * 1e6, lpf_gw_data, (ir_time - gw_peak) * 1e6,
         lpf_ir_data)
plt.xlabel("Time in ($\mu s$)")
plt.show()
Пример #3
0
read_DBY_output=read_DBY(38,1,26.522908895,8,x_max,1) #UF 15-38, RS1
#read_DBY_output=read_DBY(39,1,66.583436840,9,x_max,1) #UF 15-39, RS1
#read_DBY_output=read_DBY(40,3,20.767465080,10,x_max,1) #UF 15-40, RS3
#read_DBY_output=read_DBY(41,1,57.298446790,11,x_max,1) #UF 15-41, RS1
#read_DBY_output=read_DBY(42,4,43.058185590,12,x_max,1) #UF 15-42, RS4
#read_DBY_output=read_DBY(43,4,23.293418545,13,x_max,1) #UF 15-43, RS4
remove_60Hz_slope_output=remove_60Hz_slope(read_DBY_output,x_max)
print('UTC reference time: %s' %remove_60Hz_slope_output[2])
gw_time,gw_data,ir_time,ir_data=chop_gw_ir(remove_60Hz_slope_output)

gw_time=gw_time
gw=gw_data
ir_time=ir_time
ir=ir_data

gw_peak=gw_time[np.argmax(gw)]
print(gw_peak)
#plt.plot(gw_time-gw_peak,gw,ir_time-gw_peak,ir)
#plt.show()

lpf_gw_data=lowpass(gw,100e3)
lpf_ir_data=lowpass(ir,100e3)

lpf_gw_peak=gw_time[np.argmax(lpf_gw_data)]
print(lpf_gw_peak)

Dt=(lpf_gw_peak-gw_peak)
print("Time difference between LPF peak and raw peak=%r"%Dt)
plt.plot((gw_time-gw_peak)*1e6,lpf_gw_data,(ir_time-gw_peak)*1e6,lpf_ir_data)
plt.xlabel("Time in ($\mu s$)")
plt.show()
Пример #4
0
def gen_conv(layer_width, filter_size):
    std = 0.1
    alpha = 0.00001

    input_set, output_set, valid_in_batches, valid_out_batches, train_ref_std = lowpass(
    )

    # reshape with channels
    input_set = input_set.reshape(-1, input_set.shape[1], 1)
    output_set = output_set.reshape(-1, output_set.shape[1], 1)
    valid_in_batches = valid_in_batches.reshape(-1, valid_in_batches.shape[1],
                                                1)
    valid_out_batches = valid_out_batches.reshape(-1,
                                                  valid_out_batches.shape[1],
                                                  1)

    ### GEN LAYERS
    x = tf.placeholder(tf.float32,
                       shape=[None, input_set.shape[1], 1],
                       name='x')
    x_4 = tf.expand_dims(x, 1)
    y = tf.placeholder(tf.float32,
                       shape=[None, output_set.shape[1], 1],
                       name='y')
    y_4 = tf.expand_dims(y, 1)

    w0 = tf.Variable(tf.truncated_normal([1, filter_size, 1, layer_width],
                                         stddev=std),
                     name='w0')
    b0 = tf.Variable(tf.truncated_normal([layer_width], stddev=std), name='b0')
    conv_0 = tf.nn.conv2d(x_4, w0, strides=[1, 1, 1, 1], padding='SAME')
    lay0 = conv_0 + b0
    lay0 = tf.nn.relu(lay0)

    w1 = tf.Variable(tf.truncated_normal([layer_width], stddev=std), name='w1')
    b1 = tf.Variable(tf.truncated_normal([layer_width], stddev=std), name='b1')
    lay1 = lay0 * w1 + b1
    lay1 = tf.nn.relu(lay1)

    # required b/c conv2d_transpose does not infer None sized object's sizes at runtime, but we can cheat like this
    dyn_input_shape = tf.shape(x_4)
    batch_size = dyn_input_shape[0]

    # w2 = w0 (because of transpose)
    # w2 = tf.Variable(tf.truncated_normal([1, filter_size, 1, layer_width], stddev=std), name='w2')
    b2 = tf.Variable(tf.truncated_normal([1, 1], stddev=std), name='b2')
    conv_2 = tf.nn.conv2d_transpose(
        lay1,
        w0,
        output_shape=tf.pack([batch_size, 1, output_set.shape[1], 1]),
        strides=[1, 1, 1, 1],
        padding='SAME')
    lay2 = conv_2 + b2

    P = tf.squeeze(lay2)  # drop size 1 dim (channels)

    MSE = tf.reduce_mean(tf.square(lay2 - y_4))
    L2 = alpha * (tf.nn.l2_loss(w0) + tf.nn.l2_loss(w1))

    optimizer = tf.train.AdamOptimizer().minimize(MSE + L2)

    global_step = tf.Variable(0, name='global_step', trainable=False)
    run_time = tf.Variable(0, name='run_time', trainable=False)

    saver = tf.train.Saver({
        "w0": w0,
        "b0": b0,
        "w1": w1,
        "b1": b1,
        "b2": b2,
        "global_step": global_step,
        "run_time": run_time
    })

    return x, y, MSE, P, optimizer, global_step, run_time, saver, input_set, output_set, valid_in_batches, valid_out_batches, train_ref_std
Пример #5
0
    if counter == 0:
        X = np.array(df)
    elif counter == 1:
        X = np.array([X, np.array(df)])
    else:
        X = np.vstack((X, np.array(df)[None]))
        
    counter += 1 

indices = np.arange(X.shape[0])

# Down sampling
if down_sampling:
    X = X[:,::d_s_factor,:]
if lowpass_flag:
    lp = lowpass(X)
    X = lp.butter_lowpass_filter(cutoff=3,fs=25,order=5)

# split
X_train, X_test, y_train, y_test, idx1, idx2 = train_test_split(X, y, indices, test_size=0.4)

if feature_extraction_flag:
    c, K = 1, 'linear'
    # Data Augmentation 
    if data_augmentation_flag:    
        da = data_augmentation(X_train, y_train)
        X_train, y_train = da.adding_noise(mu, sigma, factor)
        X_train, y_train = da.shift_side(steps = [50,100])
        X_train, y_train = da.window_warping(200, 300, window_ratio = [[1,2],[2,1]])
    fe = feature_extraction(X_train)
    X_train, index, cross_corelation = fe.feature_extraction()
Пример #6
0
fNeg = np.multiply(
    np.fliplr([np.arange(0 + df, (df * Nsamples / 2) + df, df)]), -1)
## All frequencies
f = np.concatenate((fNeg, f), axis=None)

## Add noise
noise = noise.noise(Nsamples)

v = np.add(v, noise)

## Demodulate
i = np.multiply(v, cosfc)
q = np.multiply(v, sinfc)

## Lowpass
test1 = lowpass.lowpass(i, Ts, fs, 1000)
test2 = lowpass.lowpass(q, Ts, fs, 1000)

plt.subplot(5, 2, 1)
plt.plot(x)
plt.subplot(5, 2, 2)
plt.plot(y)
plt.subplot(5, 2, 3)
plt.plot(t, np.multiply(x, cosfc))
plt.subplot(5, 2, 4)
plt.plot(t, np.multiply(y, sinfc))
plt.subplot(5, 2, 5)
plt.plot(t, i)
plt.subplot(5, 2, 6)
plt.plot(t, q)
plt.subplot(5, 2, 7)
Пример #7
0
    def drawplot(self, ui, filterfrequency):
        start = float(self.start)
        stop = float(self.end)
        print "start: " + str(start)
        print "stop: " + str(self.end)
        left = start
        right = stop

        matplotlib.pyplot.autoscale(enable=True, axis='both', tight=True)
        xlabel = "Time (s)"
        print xlabel
        ui.progressBar.setMinimum(0)
        ui.progressBar.setMaximum(len(self.signals))
        mplwidget = self.widget
        mplwidget.fig.clear()

        # plot signal from each channel
        for x in range(1, (len(self.signals) + 1)):

            # add subplot and set axes and scale
            self.axes[x] = mplwidget.fig.add_subplot(len(self.signals),
                                                     1,
                                                     x,
                                                     sharex=self.axes[1])
            self.axes[x].set_xlim(left, right)
            self.axes[x].autoscale(enable=True, axis='y', tight=True)

            v = self.signals[x - 1][:].magnitude  # signal to plot
            print "SAMPLING RATE: " + str(
                len(self.signals[x - 1]) /
                self.signals[x - 1].sampling_rate.magnitude)
            self.t = numpy.linspace(
                1,
                len(self.signals[x - 1]) /
                self.signals[x - 1].sampling_rate.magnitude,
                num=len(self.signals[x - 1]))
            self.t = self.t[:]
            print len(self.t)
            if self.ui.actionFilter.isChecked():
                v = lowpass(v, self.signals[x - 1].sampling_rate.magnitude,
                            filterfrequency)

            if self.ui.actionAbsolute_Value_2.isChecked():
                v = numpy.absolute(v)
            matplotlib.pyplot.plot(self.t, v)
            self.datalines.append(self.axes[x].plot(self.t, v))
            self.fitpoints.insert(x, 1)

            #for all plots but the final plot
            if x < len(self.signals):
                matplotlib.artist.setp(self.axes[x].get_xticklabels(),
                                       visible=False)  #don't draw x ticks

            #for only the final plot
            if x >= len(self.signals):
                self.axes[x].set_xlabel(xlabel)

            if not ui.actionShow_Axes.isChecked():
                self.axes[x].set_axis_off()
            elif ui.actionShow_Axes.isChecked():
                self.axes[x].set_axis_on()

            self.axes[x].set_ylabel(str(self.signals[x - 1].name))

            max_yticks = 2
            yloc = plt.MaxNLocator(max_yticks)
            self.axes[x].yaxis.set_major_locator(yloc)
            ui.progressBar.setValue(x)

        self.show_markers(ui)
        matplotlib.pyplot.autoscale(enable=True, axis='both', tight=True)
        textstr = ""
        self.speedtext = self.widget.fig.text(0.05,
                                              0.95,
                                              textstr,
                                              fontsize=14,
                                              verticalalignment='top',
                                              bbox=self.props)
        mplwidget.canvas.draw()
        ui.progressBar.setValue(len(self.signals))
Пример #8
0
#ir_time=remove_60Hz_slope_output[0][n/2:]
#ir=remove_60Hz_slope_output[1][n/2:]
#plt.plot(gw_time*1e6,gw,ir_time*1e6,ir)
#plt.show()

#Uncomment for LPF 
GW_five_percent=read_DBY_output[13]
print("5-pk")
print(GW_five_percent)
gw_time=gw_time
gw=gw_data
ir_time=ir_time
ir=ir_data


lpf_ir_data=lowpass(ir,300e3)
lpf_gw_data=lowpass(gw,700e3)
plt.plot(gw_time*1e6,lpf_gw_data,ir_time[50:]*1e6,lpf_ir_data[50:])
plt.plot([gw_time[0]*1e6,gw_time[-1]*1e6],[0.05*np.max(lpf_gw_data),0.05*np.max(lpf_gw_data)],'r-')
plt.xlabel('Time ($\mu s$)')
plt.ylabel('data 1 Uncalibrated Ez from DBY station')
plt.show()

#read_DBY_output=read_DBY(38,1,26.522908895,8,x_max,1) #UF 15-38, RS1
#read_DBY_output=read_DBY(38,2,26.579535265,8,x_max,1) #UF 15-38, RS2
#read_DBY_output=read_DBY(38,3,26.691097980,8,x_max,1) #UF 15-38, RS3
#read_DBY_output=read_DBY(38,4,26.734557870,8,x_max,1) #UF 15-38, RS4
#read_DBY_output=read_DBY(38,5,26.764446000,8,x_max,1) #UF 15-38, RS5
#read_DBY_output=read_DBY(39,1,66.583436840,9,x_max,1) #UF 15-39, RS1
#read_DBY_output=read_DBY(39,2,66.586552840,9,x_max,1) #UF 15-39, RS2
#read_DBY_output=read_DBY(39,3,66.633136315,9,x_max,1) #UF 15-39, RS3