コード例 #1
0
 def update(thresh):
     from quickspikes.tools import filter_times
     line.set_ydata((thresh, thresh))
     det = qs.detector(thresh, 40)
     spike_t = filter_times(det.send(osc), 10, osc.size - 20)
     if spike_t:
         spike_t = np.asarray(spike_t)
         spike_w = np.asarray(qs.peaks(osc, spike_t, 10, 20))
         plot_some_spikes(ax2, spike_w, color='k', alpha=0.2)
         points.set_xdata(time[spike_t])
         points.set_ydata(osc[spike_t])
     ax1.figure.canvas.draw()
コード例 #2
0
def prepare4Analysis(filename, y):
    npyFile = filename + ".npy"
    np.save(npyFile, y)
    thres = -3 * y[3749999]
    loadedData = np.load(npyFile)
    det = qs.detector(thres, 1000)  # quickspikes function
    times = det.send(loadedData)  # quickspikes function
    # spikes = qs.peaks(np.load('A4.npy'), times, 30, 30) #quickspikes function
    # print(spikes)
    for i in range(len(times)):
        if i == (len(times) - 1):
            break
        isi.append(times[i + 1] - times[i])
    #print("Spike Time Indices:", times)
    if len(times) != 0:
        for t in range(len(times)):
            spikeValues.append(y[times[t]])
    #print("Spike Voltage Values:", spikeValues)
    # data filter
    for time in isi:
        if time < 5:
            isi.remove(time)

    isiAnalysis(filename, isi)
コード例 #3
0
for i in range(len(rawData)):
    if i == 0 or i == 1 or i == 3:
        continue
    data.append(rawData[i])

for i in range(len(data)-1):
    data[i] = data[i].split("\t")
    if i == 0:
        continue
    x.append(float(data[i][0]))
    y.append(float(data[i][1]))

np.save('A4.npy', y)
thres = -3*y[3749999]
loadedData = np.load('A4.npy')
det = qs.detector(thres, 1000) #quickspikes function
times = det.send(loadedData) #quickspikes function
#spikes = qs.peaks(np.load('A4.npy'), times, 30, 30) #quickspikes function
#print(spikes)
for i in range(len(times)):
    if i == (len(times)-1):
        break
    isi.append(times[i+1] - times[i])
#print("Spike Time Indices:", times)
if len(times) != 0:
    for t in range(len(times)):
        spikeValues.append(y[times[t]])
#print("Spike Voltage Values:", spikeValues)
#data filter
for time in isi:
    if time < 5:
コード例 #4
0
    def _loadProbe(self, plunge=1, outlier=False, outThr=150):
        """
        Load the signal from the Probe and ensure
        we are using exclusively the insertion part of the
        plunge. If it has not been already loaded the profile
        it loads also the profile. We also create the appropriate
        attribute with floating potential with 10 kHz high pass
        filtering due to a pick-up from FPS coils

        Parameters
        ----------
        plunge :
            Integer indicating the plunge number
        outlier :
            Boolean for indicating if outlier should be
            eliminated
        outThr :
            Threshold for eliminating the outlier

        Returns
        -------
        Save as attributes for the class the Ion saturation current
        and the floating potential (as xarray.DataSet) plus the
        values of rho and drSep as function of time
        """

        self.plunge = plunge
        # now load the data and save them in the appropriate xarray
        self._getNames(plunge=plunge)
        # get the time basis
        time = self._tree.getNode(r'\FP' +
                                  self.vfNames[0]).getDimensionAt().data()
        dt = (time.max() - time.min()) / (time.size - 1)
        Fs = np.round(1. / dt)
        # now we load the floating potential and save them in an xarray
        vF = []
        vFF = []
        for name in self.vfNames:
            vF.append(self._tree.getNode(r'\FP' + name).data())
            vFF.append(
                self.bw_filter(self._tree.getNode(r'\FP' + name).data(),
                               10e3,
                               Fs,
                               'highpass',
                               order=5))
            # convert in a numpy array
        vF = np.asarray(vF)
        vFF = np.asarray(vFF)
        # we need to build an appropriate time basis since it has not a
        # constant time step
        time = np.linspace(time.min(), time.max(), time.size, dtype='float64')
        vF = xray.DataArray(vF,
                            coords=[self.vfNames, time],
                            dims=['Probe', 'time'])
        vFF = xray.DataArray(vFF,
                             coords=[self.vfNames, time],
                             dims=['Probe', 'time'])
        # repeat for the ion saturation current
        if self.isNames.size == 1:
            iS = self._tree.getNode(r'\FP' + self.isNames[0]).data()
            iS = xray.DataArray(iS, coords=[time], dims=['time'])
        else:
            iS = []
            for name in self.isNames:
                iS.append(self._tree.getNode(r'\FP' + name).data())
            # convert in a numpy array
            iS = np.asarray(iS)
            # save an xarray dataset
            iS = xray.DataArray(iS,
                                coords=[self.isNames, time],
                                dims=['Probe', 'time'])
        # this is upstream remapped I load the node not the data
        RRsep = self._filament.getNode(r'\FP_%1i' % plunge + 'PL_RRSEPT')
        # this is in Rhopoloidal
        Rhop = self._filament.getNode(r'\FP_%1i' % plunge + 'PL_RHOT')
        R = self._tree.getNode(r'\FPCALPOS_%1i' % self.plunge)
        # limit to first insertion of the probe
        Rtime = Rhop.getDimensionAt().data()[:np.nanargmin(RRsep.data())]
        Rhop = Rhop.data()[:np.nanargmin(RRsep.data())]
        RRsep = RRsep.data()[:np.nanargmin(RRsep.data())]
        # limit to the timing where we insert the
        ii = np.where((iS.time >= Rtime.min()) & (iS.time <= Rtime.max()))[0]
        if 1 == self.isNames.size:
            self.iS = iS[ii]
        else:
            self.iS = iS[:, ii]
        self.vF = vF[:, ii]
        self.vFF = vFF[:, ii]
        # now check if the number of size between position and signal
        # are the same otherwise univariate interpolate the position
        if Rtime.size != self.iS.time.size:
            S = interp1d(Rtime[~np.isnan(Rhop)],
                         Rhop[~np.isnan(Rhop)],
                         kind='linear',
                         fill_value='extrapolate')
            self.Rhop = S(self.iS.time.values)
            S = interp1d(Rtime[~np.isnan(RRsep)],
                         RRsep[~np.isnan(RRsep)],
                         kind='linear',
                         fill_value='extrapolate')
            self.RRsep = S(self.iS.time.values)
            self.Rtime = self.iS.time.values
        else:
            self.Rhop = Rhop
            self.RRsep = RRsep
            self.Rtime = Rtime
        S = interp1d(R.getDimensionAt().data(),
                     R.data() / 1e2,
                     kind='linear',
                     fill_value='extrapolate')
        self.R = S(self.iS.time.values)
        # in case we set outlier we eliminate outlier with NaN
        if outlier:
            det = qs.detector(outThr, 40)
            for _probe in range(self.vF.shape[0]):
                times = det.send(
                    np.abs(self.vF[_probe, :]).values.astype('float64'))
                if len(times) != 0:
                    for t in times:
                        if t + 40 < self.vF.shape[1]:
                            self.vF[_probe, t - 40:t + 40] = np.nan
                        else:
                            self.vF[_probe, t - 40:-1] = np.nan
                            # perform a median filter to get rid of possible
                        #        self.R = R.rolling(time=20).mean()[:R.argmin().item()]
        self.Epol = (vF.sel(Probe='VFT_' + str(int(self.plunge))) -
                     vF.sel(Probe='VFM_' + str(int(self.plunge)))) / 4e-3
        self.Erad = (vF.sel(Probe='VFM_' + str(int(self.plunge))) -
                     vF.sel(Probe='VFR1_' + str(int(self.plunge)))) / 1.57e-3
コード例 #5
0
ファイル: Bands.py プロジェクト: miquelroq/CHECKapp
 def __init__(self, data, sample_rate=1000):
     self.data = data
     self.sample_rate = sample_rate
     self.det = qs.detector(2000, 30)