예제 #1
0
def hlsvdfilt_highbw(mrs_data, nc, vals):
    print(vals)
    sig_cx = mrs_data.raw_cx
    #create new window-----------
    fit = np.zeros_like(sig_cx)

    for n in vals:
        observed = sig_cx[n][0:8192]
        step_size = 1000 / mrs_data.bw

        # Call hlsvd()
        results = hlsvd.hlsvd(observed, nc, step_size)


        nsv_found, singular_values, frequencies, \
            damping_factors, amplitudes, phases = results

        estimated = _create_hlsvd_sum_fid(frequencies,
                                          damping_factors, amplitudes, phases,
                                          len(observed), step_size)

        # We're only concerned with the real portion of the data
        sig_cx[n][0:8192] = observed - estimated
        fit[n][0:8192] = estimated

        # The observed values are always noisier, so plotting them first allows
        # the cleaner estimation to be displayed on top.

    return (sig_cx, fit)
예제 #2
0
    def run (self):

        # 1. read data from the socket received from the client until message 'FINISHED' is received
        try:
            print('waiting for data' )
            order = read_string(self.client)
            while  order != 'FINISHED':

                print(order)
                if order == 'writeData':
                    print("real data")
                    realdata = read_1DArrayDouble(self.client)
                    print(realdata)
                    print("imag data")
                    imagdata = read_1DArrayDouble(self.client)
                    print(imagdata)
                    print("nsv_sought")
                    nsv_sought = read_int(self.client)
                    print(nsv_sought)
                    print("dwell_time")
                    dwell_time = read_float(self.client)
                    print(dwell_time)
                    print("m")
                    m = read_int(self.client)
                    print(m)
                order = read_string(self.client)
                if order == 'run':
                    data = realdata + 1j * imagdata
                    npts = len(data)
                    result = hlsvdpro.hlsvd(data, nsv_sought, dwell_time)
                    nsv_found, singvals, freq, damp, ampl, phas = result
                    print(nsv_found)
                    write_int(self.client, nsv_found)
                    write_1DArrayDouble(self.client,singvals)
                    write_1DArrayDouble(self.client,freq)
                    write_1DArrayDouble(self.client,damp)
                    write_1DArrayDouble(self.client,ampl)
                    write_1DArrayDouble(self.client,phas)

                    fid = hlsvdpro.create_hlsvd_fids(result, npts, dwell_time, sum_results=True, convert=False)
                    # chop = ((((np.arange(len(fid)) + 1) % 2) * 2) - 1)
                    # dat = data * chop
                    # fit = fid * chop
                    # dat[0] *= 0.5
                    # fit[0] *= 0.5
                    print(data - fid)
                    # plt.plot(np.fft.fft(dat).real, color='r')
                    # plt.plot(np.fft.fft(fit).real, color='b')
                    # plt.plot(np.fft.fft(dat - fit).real, color='g')
                    # plt.show()
        except Exception as err:   #    except ConnectionResetError: in python 3...
            print('Exception caught: %s\nClosing...' % err)
         # ends connection with the client, waits for a need connection (client = sock.accept()[0] )
        print ('thread closing\n')
        self.client.close()
        count.nClients-=1
예제 #3
0
def hlsvdquant_highbw(mrs_data, nc, vals):
    print(vals)
    #    sig_cx=np.real(mrs_data.raw_cx)+1j*np.imag(mrs_data.raw_cx)

    sig_cx = np.abs(mrs_data.raw_cx) + 0j
    #create new window-----------
    fit = np.zeros_like(sig_cx)
    h2o_amp = np.zeros(shape=mrs_data.nsa) + 0j
    for n in vals:
        nc0 = nc
        observed = sig_cx[n][2:mrs_data.pts_orig]
        step_size = 1000 / mrs_data.bw

        while nc0 > 0:
            # Call hlsvd()
            results = hlsvd.hlsvd(observed, nc0, step_size)


            nsv_found, singular_values, frequencies, \
                damping_factors, amplitudes, phases = results

            if max(damping_factors) > -7.96:
                nc0 = nc0 - 1
                continue
            else:
                estimated = _create_hlsvd_sum_fid(frequencies, damping_factors,
                                                  amplitudes, phases,
                                                  len(observed), step_size)
                # We're only concerned with the real portion of the data
                sig_cx[n][2:mrs_data.pts_orig] = observed - estimated
                fit[n][2:mrs_data.pts_orig] = estimated
                #                print('SPEC ['+str(n)+']: '+str(nc0)+' COMPONENTS, '+str(abs(fit[n][3])))
                print(str(abs(fit[n][3])))
                h2o_amp[n] = fit[n][3]
                break

        # The observed values are always noisier, so plotting them first allows
        # the cleaner estimation to be displayed on top.

    return (h2o_amp, fit)
예제 #4
0
    imagdata = read_1DArrayDouble(client)
    print(imagdata)
    print("nsv_sought")
    nsv_sought = read_int(client)
    print(nsv_sought)
    print("dwell_time")
    dwell_time = read_float(client)
    print(dwell_time)
    print("m")
    m = read_int(client)
    print(m)
order = read_string(client)
if order == 'run':
    data = realdata + 1j * imagdata
    npts = len(data)
    result = hlsvdpro.hlsvd(data, nsv_sought, dwell_time)
    nsv_found, singvals, freq, damp, ampl, phas = result
    print(nsv_found)
    write_int(client, nsv_found)
    write_1DArrayDouble(client, singvals)
    write_1DArrayDouble(client, freq)
    write_1DArrayDouble(client, damp)
    write_1DArrayDouble(client, ampl)
    write_1DArrayDouble(client, phas)

    # print("np.allclose(freq, indat['freq0']) = ", np.allclose(freq, freq0))

    # fid = hlsvdpro.create_hlsvd_fids(result, npts, dwell_time, sum_results=True, convert=False)
    #
    # chop = ((((np.arange(len(fid)) + 1) % 2) * 2) - 1)
    # dat = data * chop