Example #1
0
    def compute(self):
        signal = self.get_input("Input").get_array()
        ptx = self.get_input("X")
        pty = self.get_input("Y")
        ptz = self.get_input("Z")

        lof = self.get_input("Low Freq")
        hif = self.get_input("High Freq")

        sigx = signal[ptz,pty,:]
        sigy = signal[ptz,:,ptx]
        sigz = signal[:,pty,ptx]

        tx = st.st(sigx, lof, hif)
        ty = st.st(sigy, lof, hif)
        tz = st.st(sigz, lof, hif)

        tx = tx * tx.conjugate()
        ty = ty * ty.conjugate()
        tz = tz * tz.conjugate()

        out_ar = tx.real + ty.real + tz.real
        out = NDArray()
        out.set_array(out_ar)
        self.set_output("Output", out)
Example #2
0
    def compute(self):
        signal = self.getInputFromPort("Input").get_array()
        ptx = self.getInputFromPort("X")
        pty = self.getInputFromPort("Y")
        ptz = self.getInputFromPort("Z")

        lof = self.getInputFromPort("Low Freq")
        hif = self.getInputFromPort("High Freq")

        sigx = signal[ptz, pty, :]
        sigy = signal[ptz, :, ptx]
        sigz = signal[:, pty, ptx]

        tx = st.st(sigx, lof, hif)
        ty = st.st(sigy, lof, hif)
        tz = st.st(sigz, lof, hif)

        tx = tx * tx.conjugate()
        ty = ty * ty.conjugate()
        tz = tz * tz.conjugate()

        out_ar = tx.real + ty.real + tz.real
        out = NDArray()
        out.set_array(out_ar)
        self.setResult("Output", out)
Example #3
0
    def compute(self):
        signal = self.getInputFromPort("Input").get_array()
        lof = self.getInputFromPort("Low Freq")
        hif = self.getInputFromPort("High Freq")

        num_pts = signal.size
        min_s = signal.min()
        max_s = signal.max()
        d = max_s - min_s
        print "Accumulating over " + str(num_pts) + " points"
        histo = numpy.zeros((512, hif - lof + 1))
        print "Histo: ", histo.shape
        dist = numpy.zeros(512)
        for z in range(signal.shape[2]):
            for y in range(signal.shape[1]):
                for x in range(signal.shape[0]):
                    sigx = signal[z, y, :]
                    sigy = signal[z, :, x]
                    tx = st.st(sigx, lof, hif)
                    ty = st.st(sigy, lof, hif)
                    sigz = signal[:, y, z]
                    tz = st.st(sigz, lof, hif)
                    tz = tz[:, x].squeeze()
                    tz = tz * tz.conjugate()
                    tx = tx[:, z].squeeze()
                    ty = ty[:, y].squeeze()
                    tx = tx * tx.conjugate()
                    ty = ty * ty.conjugate()

                    ar = tx.real + ty.real + tz.real
                    ar = ar / ar.sum()
                    #                    ar = ar.sum(axis=1)
                    #                    print "ar: ", ar.shape
                    #                    ar.shape = (ar.shape[0],1)
                    scalar = signal[z, y, x]
                    try:
                        bin = int((scalar - min_s) / d * 511.)
                        #                        dist[bin] += 1
                        #                        print bin, scalar, ar
                        sigma = self.forceGetInputFromPort("Sigma")
                        if sigma:
                            ar = scipy.signal.gaussian(ar.size, sigma) * ar
                        histo[bin, :] += ar
                    except:
                        print "Cannot assign to bin: " + str(
                            bin) + ", scalar: " + str(scalar)
                        print "location = ", x, y, z
                        raise ModuleError("Cannot assign to bin: " + str(bin) +
                                          ", scalar: " + str(scalar))


#                print "done with y = ", y
            print "done with z = ", z

        out = NDArray()
        out.set_array(histo)  # / dist)
        self.setResult("Output", out)
Example #4
0
    def compute(self):
        signal = self.get_input("Input").get_array()
        lof = self.get_input("Low Freq")
        hif = self.get_input("High Freq")

        num_pts = signal.size
        min_s = signal.min()
        max_s = signal.max()
        d = max_s - min_s
        print "Accumulating over " + str(num_pts) + " points"
        histo = numpy.zeros((512,hif-lof+1))
        print "Histo: ",histo.shape
        dist = numpy.zeros(512)
        for z in range(signal.shape[2]):
            for y in range(signal.shape[1]):
                for x in range(signal.shape[0]):
                    sigx = signal[z,y,:]
                    sigy = signal[z,:,x]
                    tx = st.st(sigx, lof, hif)
                    ty = st.st(sigy, lof, hif)
                    sigz = signal[:,y,z]
                    tz = st.st(sigz, lof, hif)
                    tz = tz[:,x].squeeze()
                    tz = tz * tz.conjugate()
                    tx = tx[:,z].squeeze()
                    ty = ty[:,y].squeeze()
                    tx = tx * tx.conjugate()
                    ty = ty * ty.conjugate()

                    ar = tx.real + ty.real + tz.real
                    ar = ar / ar.sum()
#                    ar = ar.sum(axis=1)
#                    print "ar: ", ar.shape
#                    ar.shape = (ar.shape[0],1)
                    scalar = signal[z,y,x]
                    try:
                        bin = int((scalar - min_s) / d * 511.)
#                        dist[bin] += 1
#                        print bin, scalar, ar
                        sigma = self.force_get_input("Sigma")
                        if sigma:
                            ar = scipy.signal.gaussian(ar.size, sigma) * ar
                        histo[bin,:] += ar
                    except:
                        print "Cannot assign to bin: " + str(bin) +", scalar: " +str(scalar)
                        print "location = ", x, y, z
                        raise ModuleError("Cannot assign to bin: " + str(bin) +", scalar: " +str(scalar))
                    
#                print "done with y = ", y
            print "done with z = ", z

        out = NDArray()
        out.set_array(histo)# / dist)
        self.set_output("Output", out)
Example #5
0
def funhv(Mv,Mn,Me,fi,ff,fmm):
    stV,t,f=st(Mv.transpose(),fi,ff,fmm)# S-transform de V
    stN,t,f=st(Mn.transpose(),fi,ff,fmm)# S-transform de N
    stE,t,f=st(Me.transpose(),fi,ff,fmm)# S-transform de E

    a = np.absolute(stN)
    b = np.absolute(stE)
    c = np.absolute(stV)
    a = np.power(a,2)
    b = np.power(b,2)
    hv = np.power((a+b)/2,0.5)
    hv = hv/c

    return hv.T
Example #6
0
    def compute(self):
        vol = self.getInputFromPort("Input").get_array()
        lof = self.getInputFromPort("Low Freq")
        hif = self.getInputFromPort("Hi Freq")
        sigma = self.forceGetInputFromPort("Sigma")
        out_vol = numpy.zeros(vol.shape)

        (slices, rows, cols) = vol.shape
        for z in range(slices):
            t = time.time()
            for y in range(rows):
                for x in range(cols):
                    # grab our 3 rays
                    xray = vol[z, y, :].squeeze()
                    yray = vol[z, :, x].squeeze()
                    zray = vol[:, y, x].squeeze()

                    # Transform each ray
                    xt = st.st(xray, lof, hif)
                    yt = st.st(yray, lof, hif)
                    zt = st.st(zray, lof, hif)

                    # Grab the point at all valid scales
                    xpt = xt[:, x]
                    ypt = yt[:, y]
                    zpt = zt[:, z]

                    # Take the magnitude
                    xpt = xpt * xpt.conjugate()
                    ypt = ypt * ypt.conjugate()
                    zpt = zpt * zpt.conjugate()

                    scale_vec = xpt.real + ypt.real + zpt.real
                    if sigma:
                        scale_vec = scale_vec * scipy.signal.gaussian(
                            scale_vec.shape[0], sigma)

                    scale = scale_vec.argmax()
                    out_vol[x, y, z] = scale
            print "done z = ", z
            print "took: ", (time.time() - t) * 1000.

        out = NDArray()
        out.set_array(out_vol)
        self.setResult("Output", out)
Example #7
0
    def compute(self):
        vol = self.get_input("Input").get_array()
        lof = self.get_input("Low Freq")
        hif = self.get_input("Hi Freq")
        sigma = self.force_get_input("Sigma")
        out_vol = numpy.zeros(vol.shape)

        (slices,rows,cols) = vol.shape
        for z in range(slices):
            t = time.time()
            for y in range(rows):
                for x in range(cols):
                    # grab our 3 rays
                    xray = vol[z,y,:].squeeze()
                    yray = vol[z,:,x].squeeze()
                    zray = vol[:,y,x].squeeze()
                    
                    # Transform each ray
                    xt = st.st(xray,lof,hif)
                    yt = st.st(yray,lof,hif)
                    zt = st.st(zray,lof,hif)

                    # Grab the point at all valid scales
                    xpt = xt[:,x]
                    ypt = yt[:,y]
                    zpt = zt[:,z]

                    # Take the magnitude
                    xpt = xpt * xpt.conjugate()
                    ypt = ypt * ypt.conjugate()
                    zpt = zpt * zpt.conjugate()

                    scale_vec = xpt.real + ypt.real + zpt.real
                    if sigma:
                        scale_vec = scale_vec * scipy.signal.gaussian(scale_vec.shape[0], sigma)

                    scale = scale_vec.argmax()
                    out_vol[x,y,z] = scale
            print "done z = ", z
            print "took: ", (time.time() - t) * 1000.

        out = NDArray()
        out.set_array(out_vol)
        self.set_output("Output", out)
Example #8
0
    def compute(self):
        in_ar = self.getInputFromPort("Input").get_array()
        lo_f = self.getInputFromPort("Low Freq")
        hi_f = self.getInputFromPort("High Freq")
        num_f = hi_f - lo_f + 1

        (slices, rows, cols) = in_ar.shape
        out_ar = numpy.zeros((num_f, slices, rows, cols))
        for s in range(slices):
            for r in range(rows):
                sig = in_ar[s, r, :]
                t = st.st(sig, lo_f, hi_f)
                t = t.conjugate() * t
                t = t.real
                for f in range(t.shape[0]):
                    out_ar[f, s, r, :] = t[f, :]

        print "done dim 1"
        for s in range(slices):
            for c in range(cols):
                sig = in_ar[s, :, c]
                t = st.st(sig, lo_f, hi_f)
                t = t.conjugate() * t
                t = t.real
                for f in range(t.shape[0]):
                    out_ar[f, s, :, c] += t[f, :]

        print "done dim 2"
        for r in range(rows):
            for c in range(cols):
                sig = in_ar[:, r, c]
                t = st.st(sig, lo_f, hi_f)
                t = t.conjugate() * t
                t = t.real
                for f in range(t.shape[0]):
                    out_ar[f, :, r, c] += t[f, :]

        print "done dim 3"
        #        out_ar = out_ar * out_ar.conjugate()
        out = NDArray()
        out.set_array(out_ar)
        self.setResult("Output", out)
Example #9
0
    def compute(self):
        in_ar = self.get_input("Input").get_array()
        lo_f  = self.get_input("Low Freq")
        hi_f  = self.get_input("High Freq")
        num_f = hi_f - lo_f + 1

        (slices, rows, cols) = in_ar.shape
        out_ar = numpy.zeros((num_f, slices, rows, cols))
        for s in range(slices):
            for r in range(rows):
                sig = in_ar[s,r,:]
                t = st.st(sig,lo_f,hi_f)
                t = t.conjugate() * t
                t = t.real
                for f in range(t.shape[0]):
                    out_ar[f,s,r,:] = t[f,:]

        print "done dim 1"
        for s in range(slices):
            for c in range(cols):
                sig = in_ar[s,:,c]
                t = st.st(sig,lo_f,hi_f)
                t = t.conjugate() * t
                t = t.real
                for f in range(t.shape[0]):
                    out_ar[f,s,:,c] += t[f,:]

        print "done dim 2"
        for r in range(rows):
            for c in range(cols):
                sig = in_ar[:,r,c]
                t = st.st(sig,lo_f,hi_f)
                t = t.conjugate() * t
                t = t.real
                for f in range(t.shape[0]):
                    out_ar[f,:,r,c] += t[f,:]

        print "done dim 3"
#        out_ar = out_ar * out_ar.conjugate()
        out = NDArray()
        out.set_array(out_ar)
        self.set_output("Output", out)
def mtst(K, tapers, x, lo, hi):
	N = len(x)
	K2 = float(K * K)
	s = 0.
	n = 0.
	for k in range(K):
		X = st(tapers[k] * x, lo, hi)
		mu = 1. - k * k / K2
		s += mu * abs(X)**2
		n += mu
	s *= N / n
	return s
Example #11
0
def mtst(K, tapers, x, lo, hi):
    N = len(x)
    K2 = float(K * K)
    s = 0.
    n = 0.
    for k in range(K):
        X = st(tapers[k] * x, lo, hi)
        mu = 1. - k * k / K2
        s += mu * abs(X)**2
        n += mu
    s *= N / n
    return s
Example #12
0
    def compute(self):
        trial_ar = self.getInputFromPort("Single Trials").get_array()
        print "trial_ar.shape = ", trial_ar.shape
        self.lof = self.getInputFromPort("Low Freq")
        self.hif = self.getInputFromPort("High Freq")
        sensor_list = self.forceGetInputListFromPort("Sensors")

        if len(trial_ar.shape) != 3:
            raise ModuleError("Cannot process input with rank not 3")

        (trials, sensors, sig_len) = trial_ar.shape
        if sensor_list == None:
            sensor_list = numpy.arange(sensors)
        else:
            sensor_list = numpy.array(sensor_list)

        # Compute the TFR for a single sensor across all trials
        freq_range = self.hif - self.lof
        out_ar = numpy.zeros(
            (sensor_list.shape[0], sig_len, freq_range + 1, freq_range + 1))
        print "sensor list = ", sensor_list

        # For each sensor to consider, extract the signal array
        for i in range(sensor_list.shape[0]):
            tmp_sig = trial_ar[:, sensor_list[i], :].squeeze()
            # For each trial, extract the signal
            for j in range(trials):
                sig = tmp_sig[j, :].squeeze()
                tfr = st.st(sig, self.lof, self.hif)

                # Compute the phase for the Time-freq plane
                p = numpy.arctan2(tfr.real, tfr.imag)

                # the ordering of p is:  (freqs,times) = p.shape
                dphi_ar = numpy.array(0. - 1.j * self.make_delta_phi(p.real))
                dphi_ar = numpy.exp(dphi_ar)
                out_ar[i, :, :, :] += dphi_ar

                print "Trial " + str(j) + " done processing..."
            print "out_ar done with all trials"
            out_ar[i, :, :, :] /= float(trials)
            out_ar[i, :, :, :] = out_ar[i, :, :, :] * out_ar[
                i, :, :, :].conjugate()
            out_ar[i, :, :, :] = out_ar[i, :, :, :].real
            print "min,max,mean = ", out_ar[i].min(), out_ar[i].max(
            ), out_ar[i].mean()
        out = NDArray()
        out.set_array(out_ar)
        self.setResult("Output", out)
def svt(X, tau):
    """
    Singular value thresholding operator

    Syntax:     Xs = svt(X, tau)

    Inputs:
        :param X: The input matrix
        :param tau: The input shrinkage parameter

    Output: 
        Xs is the result of applying singular value thresholding to X
    """
    U, S, Vt = la.svd(X, full_matrices=False)
    Xs = np.dot(U * st(S, tau), Vt)
    return Xs
Example #14
0
    def compute(self):
        trial_ar = self.get_input("Single Trials").get_array()
        print "trial_ar.shape = ", trial_ar.shape
        self.lof = self.get_input("Low Freq")
        self.hif = self.get_input("High Freq")
        sensor_list = self.force_get_input_list("Sensors")
        
        if len(trial_ar.shape) != 3:
            raise ModuleError("Cannot process input with rank not 3")

        (trials, sensors, sig_len) = trial_ar.shape
        if sensor_list == None:
            sensor_list = numpy.arange(sensors)
        else:
            sensor_list = numpy.array(sensor_list)
            
        # Compute the TFR for a single sensor across all trials
        freq_range = self.hif - self.lof
        out_ar = numpy.zeros((sensor_list.shape[0], sig_len, freq_range+1, freq_range+1))
        print "sensor list = ", sensor_list
        
        # For each sensor to consider, extract the signal array
        for i in range(sensor_list.shape[0]):
            tmp_sig = trial_ar[:,sensor_list[i],:].squeeze()
            # For each trial, extract the signal
            for j in range(trials):
                sig = tmp_sig[j,:].squeeze()
                tfr = st.st(sig, self.lof, self.hif)

                # Compute the phase for the Time-freq plane
                p = numpy.arctan2(tfr.real, tfr.imag)
                
                # the ordering of p is:  (freqs,times) = p.shape
                dphi_ar = numpy.array(0.-1.j*self.make_delta_phi(p.real))
                dphi_ar = numpy.exp(dphi_ar)
                out_ar[i,:,:,:] += dphi_ar

                print "Trial " + str(j) + " done processing..."
            print "out_ar done with all trials"
            out_ar[i,:,:,:] /= float(trials)
            out_ar[i,:,:,:] = out_ar[i,:,:,:] * out_ar[i,:,:,:].conjugate()
            out_ar[i,:,:,:] = out_ar[i,:,:,:].real
            print "min,max,mean = ", out_ar[i].min(), out_ar[i].max(), out_ar[i].mean()
        out = NDArray()
        out.set_array(out_ar)
        self.set_output("Output", out)
Example #15
0
    def compute(self):
        t = time.time()
        signals = self.getInputFromPort("Signals").get_array()
        lof = self.getInputFromPort("Low Freq")
        hif = self.getInputFromPort("Hi Freq")
        if len(signals.shape) == 1:
            signals.shape = (1, signals.shape[0])

        outl = []
        for i in xrange(signals.shape[0]):
            sig_ar = signals[i]
            x = st.st(sig_ar, lof, hif)
            outl.append(x)

        out_ar = numpy.array(outl).squeeze()
        print "c time = ", (time.time() - t) * 1000.
        out = NDArray()
        out.set_array(out_ar)
        self.setResult("Output", out)
Example #16
0
    def compute(self):
        t = time.time()
        signals = self.get_input("Signals").get_array()
        lof = self.get_input("Low Freq")
        hif = self.get_input("Hi Freq")
        if len(signals.shape) == 1:
            signals.shape = (1, signals.shape[0])

        outl = []
        for i in xrange(signals.shape[0]):
            sig_ar = signals[i]
            x = st.st(sig_ar, lof, hif)
            outl.append(x)

        out_ar = numpy.array(outl).squeeze()
        print "c time = ", (time.time() - t) * 1000.
        out = NDArray()
        out.set_array(out_ar)
        self.set_output("Output", out)
Example #17
0
    def compute(self):
        vol = self.get_input("Input").get_array()
        lof = self.get_input("Low Freq")
        hif = self.get_input("Hi Freq")
        max_vol = numpy.zeros(vol.shape)
        grav_vol = numpy.zeros(vol.shape)

        (slices,rows,cols) = vol.shape
        for z in range(slices):
            tr = time.time()
            for y in range(rows):
                ray = vol[z,y,:].squeeze()
                t = st.st(ray, lof, hif)
                for x in range(cols):
                    scales = t[:,x].squeeze()
                    scales = scales * scales.conjugate()

                    max_vol[x,y,z] = float(scales.argmax())

                    grav = 0.
                    for i in range(scales.shape[0]):
                        v = scales[i]
                        f = lof + i
                        grav += float(v) * float(f)

                    grav_vol[x,y,z] = grav
            
            print "done z = ", z
            print "took: ", (time.time() - tr) * 1000.

        grav_vol = grav_vol - grav_vol.min()
        grav_vol = grav_vol / grav_vol.max()
        grav_vol = grav_vol * float(hif - lof)
        grav_vol = grav_vol + lof
        max_out = NDArray()
        max_out.set_array(max_vol)
        grav_out = NDArray()
        grav_out.set_array(grav_vol)
        self.set_output("Max Output", max_out)
        self.set_output("Grav Output", grav_out)
Example #18
0
    def compute(self):
        vol = self.getInputFromPort("Input").get_array()
        lof = self.getInputFromPort("Low Freq")
        hif = self.getInputFromPort("Hi Freq")
        max_vol = numpy.zeros(vol.shape)
        grav_vol = numpy.zeros(vol.shape)

        (slices, rows, cols) = vol.shape
        for z in range(slices):
            tr = time.time()
            for y in range(rows):
                ray = vol[z, y, :].squeeze()
                t = st.st(ray, lof, hif)
                for x in range(cols):
                    scales = t[:, x].squeeze()
                    scales = scales * scales.conjugate()

                    max_vol[x, y, z] = float(scales.argmax())

                    grav = 0.
                    for i in range(scales.shape[0]):
                        v = scales[i]
                        f = lof + i
                        grav += float(v) * float(f)

                    grav_vol[x, y, z] = grav

            print "done z = ", z
            print "took: ", (time.time() - tr) * 1000.

        grav_vol = grav_vol - grav_vol.min()
        grav_vol = grav_vol / grav_vol.max()
        grav_vol = grav_vol * float(hif - lof)
        grav_vol = grav_vol + lof
        max_out = NDArray()
        max_out.set_array(max_vol)
        grav_out = NDArray()
        grav_out.set_array(grav_vol)
        self.setResult("Max Output", max_out)
        self.setResult("Grav Output", grav_out)
Example #19
0
def pcp(Y):
    """
    Principal Component Pursuit solved with ADMM

    Syntax:     L, S = pcp(Y)

    Inputs:     
        :param Y: A matrix of size [D, N]

    Ouputs:
        L: The low rank matrix with size [D, N]
        S: The sparse matrix with size [D, N]
    """
    ### Parameters that we'll use
    D, N = np.shape(Y)
    normY = norm(Y, ord='fro')

    ### Algorithm parameters
    lam = 1 / sqrt(max(D, N))
    rho = 10 * lam
    tol = 1e-4
    maxIter = 1000

    ### Initialize the variables of optimization
    L = zeros([D, N])
    S = zeros([D, N])
    Z = zeros([D, N])

    ### ADMM Iterations
    for ii in range(maxIter):
        L = svt((Y - S + (1 / rho) * Z), 1 / rho)
        S = st((Y - L + (1 / rho) * Z), lam / rho)
        Z = Z + rho * (Y - L - S)

        ## Calculate error and output at each iteration:
        err = norm(Y - L - S, ord='fro')
        if err < tol:
            break

    return L, S
Example #20
0
    def compute(self):
        vol = self.get_input("Input").get_array()
        lof = self.get_input("Low Freq")
        hif = self.get_input("Hi Freq")
        sigma = self.force_get_input("Sigma")
        max_vol = numpy.zeros(vol.shape)
        grav_vol = numpy.zeros(vol.shape)

        (slices,rows,cols) = vol.shape
        for z in range(slices):
            t = time.time()
            for y in range(rows):
                for x in range(cols):
                    # grab our 3 rays
                    xray = vol[z,y,:].squeeze()
                    yray = vol[z,:,x].squeeze()
                    zray = vol[:,y,x].squeeze()
                    
                    # Transform each ray
                    xt = st.st(xray,lof,hif)
                    yt = st.st(yray,lof,hif)
                    zt = st.st(zray,lof,hif)

                    # Grab the point at all valid scales
                    xpt = xt[:,x]
                    ypt = yt[:,y]
                    zpt = zt[:,z]

                    # Take the magnitude
                    xpt = xpt * xpt.conjugate()
                    ypt = ypt * ypt.conjugate()
                    zpt = zpt * zpt.conjugate()

                    scale_vec = xpt.real + ypt.real + zpt.real
                    if sigma:
                        scale_vec = scale_vec * scipy.signal.gaussian(scale_vec.shape[0], sigma)

                    scale = scale_vec.argmax()
                    max_vol[x,y,z] = scale

#                    scale_vec = 
#                    scale_vec = scale_vec / scale_vec.sum()


                    grav = 0
                    for s in range(scale_vec.shape[0]):
                        v = scale_vec[s]
                        f = lof + s
                        grav += float(f) * float(v)

#                    grav = grav / float(scale_vec.shape[0])
                    
                    grav_vol[x,y,z] = grav
                    
            print "done z = ", z
            print "took: ", (time.time() - t) * 1000.

        grav_vol = grav_vol - grav_vol.min()
        grav_vol = grav_vol / grav_vol.max()
        grav_vol = grav_vol * float(hif - lof)
        grav_vol = grav_vol + lof
        max_out = NDArray()
        max_out.set_array(max_vol)
        grav_out = NDArray()
        grav_out.set_array(grav_vol)
        self.set_output("Max Output", max_out)
        self.set_output("Grav Output", grav_out)
Example #21
0
    def compute(self):
        vol = self.getInputFromPort("Input").get_array()
        lof = self.getInputFromPort("Low Freq")
        hif = self.getInputFromPort("Hi Freq")
        sigma = self.forceGetInputFromPort("Sigma")
        max_vol = numpy.zeros(vol.shape)
        grav_vol = numpy.zeros(vol.shape)

        (slices, rows, cols) = vol.shape
        for z in range(slices):
            t = time.time()
            for y in range(rows):
                for x in range(cols):
                    # grab our 3 rays
                    xray = vol[z, y, :].squeeze()
                    yray = vol[z, :, x].squeeze()
                    zray = vol[:, y, x].squeeze()

                    # Transform each ray
                    xt = st.st(xray, lof, hif)
                    yt = st.st(yray, lof, hif)
                    zt = st.st(zray, lof, hif)

                    # Grab the point at all valid scales
                    xpt = xt[:, x]
                    ypt = yt[:, y]
                    zpt = zt[:, z]

                    # Take the magnitude
                    xpt = xpt * xpt.conjugate()
                    ypt = ypt * ypt.conjugate()
                    zpt = zpt * zpt.conjugate()

                    scale_vec = xpt.real + ypt.real + zpt.real
                    if sigma:
                        scale_vec = scale_vec * scipy.signal.gaussian(
                            scale_vec.shape[0], sigma)

                    scale = scale_vec.argmax()
                    max_vol[x, y, z] = scale

                    #                    scale_vec =
                    #                    scale_vec = scale_vec / scale_vec.sum()

                    grav = 0
                    for s in range(scale_vec.shape[0]):
                        v = scale_vec[s]
                        f = lof + s
                        grav += float(f) * float(v)


#                    grav = grav / float(scale_vec.shape[0])

                    grav_vol[x, y, z] = grav

            print "done z = ", z
            print "took: ", (time.time() - t) * 1000.

        grav_vol = grav_vol - grav_vol.min()
        grav_vol = grav_vol / grav_vol.max()
        grav_vol = grav_vol * float(hif - lof)
        grav_vol = grav_vol + lof
        max_out = NDArray()
        max_out.set_array(max_vol)
        grav_out = NDArray()
        grav_out.set_array(grav_vol)
        self.setResult("Max Output", max_out)
        self.setResult("Grav Output", grav_out)
Example #22
0
import numpy as np
import matplotlib.pyplot as plt
from svt import svt
from st import st

m = 100
n = 50

## test st
x = np.ones(n)
y = np.linspace(-1,1,m)
tau = 0.5

# generate matrix and threshold
A = np.outer(x, y)
As = st(A, tau)

# display results
plt.figure()
plt.imshow(A, extent=[-1,1,0,n], aspect='auto')
plt.clim(-1,1)
plt.set_cmap('gray')
plt.colorbar()
plt.title('original matrix')
plt.show()

plt.figure()
plt.imshow(As, extent=[-1,1,0,n], aspect='auto')
plt.clim(-1,1)
plt.set_cmap('gray')
plt.colorbar()