Esempio n. 1
0
    def createNewProject(self, file_name, pen_data):
            PenDataSegmentCategory.clearSegmentCache()

            self._project_settings = None

            self._name = file_name

            # Normalize pen sample times so first sample starts at 0.0 sec.
            self._original_timebase_offset=pen_data[0]['time']
            pen_data['time']-=self._original_timebase_offset
            pen_data['time']=pen_data['time']/1000.0

            # to flip data vertically by changing y pos values...
            # Maybe better to see if pyqtgraph has a built in option
            # to flip a plot vertically.
            #
            # pmax = pen_data['y'].max()
            # pmin = pen_data['y'].min()
            # pen_data['y'] = pmax-pen_data['y']+pmin

            self._pendata = pen_data
            self.nonzero_pressure_mask=self._pendata['pressure']>0
            # nonzero_regions_ix will be a tuple of (starts, stops, lengths) arrays
            self.nonzero_region_ix=contiguous_regions(self.nonzero_pressure_mask)
            self._segmentset=PenDataSegmentCategory(name=self.name,project=self)
            self._pendata['segment_id']=self._segmentset.id

            if self._selectedtimeregion is None:
                MarkWriteProject._selectedtimeregion = SelectedTimePeriodItem(project=self)
            else:
                MarkWriteProject._selectedtimeregion.project = self

            MarkWriteProject._selectedtimeregion.setBounds(bounds=(self.pendata['time'][0], self.pendata['time'][-1]))
            MarkWriteProject._selectedtimeregion.setRegion([self.pendata['time'][0], self.pendata['time'][0] + 1.0])
Esempio n. 2
0
    def createNewProject(self, file_name, pen_data, condvars=None, stime_var=None, etime_var=None, file_type=None):
            PenDataSegmentCategory.clearSegmentCache()

            self._project_settings = None

            self._name = file_name
            self._filetype = file_type

            self._expcondvars = condvars
            self._stimevar = stime_var
            self._etimevar = etime_var

            # go through each trial, select only the samples within
            # the trial period, add the trials sample array to list of trial
            # sample data.
            samples_by_trial = []
            trial_times = None
            if self._expcondvars is not None and self._stimevar is not None and self._etimevar is not None:
                trial_times = []
                for t in self._expcondvars:
                    try:
                        trialstart = float(t[self._stimevar])
                        trialend = float(t[self._etimevar])
                        trial_times.append((trialstart,trialend))
                        trial_samples = pen_data[(pen_data['time'] >= trialstart) & (pen_data['time'] <= trialend)]
                        samples_by_trial.append(trial_samples)
                        #print "trial samples:",trial_samples.shape
                    except:
                        print("Error getting trial time period:")
                        import traceback
                        traceback.print_exc()

            if samples_by_trial:
                # make pen_data == concat'ed samples_by_trial
                pen_data = np.concatenate(samples_by_trial)

                # turn trial start, stop time list into np array
                trial_times = np.asarray(trial_times)

            # Normalize pen sample times so first sample starts at 0.0 sec.
            self._original_timebase_offset=pen_data[0]['time']
            pen_data['time']-=self._original_timebase_offset
            if trial_times is not None:
                trial_times-=self._original_timebase_offset
                self._trialtimes = trial_times

            # Change time stamps to sec.msec format, if needed
            if file_type != 'hdf5':
                # data from iohub hdf5 file is already in sec.msec format
                pen_data['time']=pen_data['time']/1000.0

            self._pendata = pen_data

            self.nonzero_pressure_mask=self._pendata['pressure']>0
            # nonzero_regions_ix will be a tuple of (starts, stops, lengths) arrays
            self.nonzero_region_ix=contiguous_regions(self.nonzero_pressure_mask)
            self._segmentset=PenDataSegmentCategory(name=self.name,project=self)
            self._pendata['segment_id']=self._segmentset.id

            if self._selectedtimeregion is None:
                MarkWriteProject._selectedtimeregion = SelectedTimePeriodItem(project=self)
            else:
                MarkWriteProject._selectedtimeregion.project = self