def process(self, display=True): #if text is empty set bits to zero if self.char == "": result = [0, 0, 0, 0, 0, 0, 0, 0] data = metaarray.MetaArray(result, info=[{'name': 'Time', 'values': np.linspace(0, 7, len(result))}, {}]) else: #Convert character to binary bin_value = bin(ord(str(self.char))) bin_list = list(bin_value[2:]) # remove '0b' from start and convert to array bin_array = [int(i) for i in bin_list] #Convert string list to int list #print(bin_array) data = metaarray.MetaArray(bin_array, info=[{'name': 'Time', 'values': np.linspace(0, 7, len(bin_array))}, {}]) return {'Out': data}
def processData(self, data): times = data.xvals('Time') dt = times[1] - times[0] data1 = data.asarray() ft = np.fft.fft(data1) ## determine frequencies in fft data df = 1.0 / (len(data1) * dt) freqs = np.linspace(0.0, (len(ft) - 1) * df, len(ft)) ## flatten spikes at f0 and harmonics f0 = self.ctrls['f0'].value() for i in xrange(1, self.ctrls['harmonics'].value() + 2): f = f0 * i # target frequency ## determine index range to check for this frequency ind1 = int(np.floor(f / df)) ind2 = int(np.ceil(f / df)) + (self.ctrls['samples'].value() - 1) if ind1 > len(ft) / 2.: break mag = (abs(ft[ind1 - 1]) + abs(ft[ind2 + 1])) * 0.5 for j in range(ind1, ind2 + 1): phase = np.angle( ft[j] ) ## Must preserve the phase of each point, otherwise any transients in the trace might lead to large artifacts. re = mag * np.cos(phase) im = mag * np.sin(phase) ft[j] = re + im * 1j ft[len(ft) - j] = re - im * 1j data2 = np.fft.ifft(ft).real ma = metaarray.MetaArray(data2, info=data.infoCopy()) return ma
def process(self, In, display=True): # Calculate FFT from input and calculate absolute values from complex values output = np.absolute(np.fft.fft(In.asarray())) # Generate MetaArray out_data = metaarray.MetaArray(output, info=[{'name': 'Time', 'values': np.linspace(0, len(output), len(output))}, {}]) return {'Out': out_data}
def getData(self, pos=1): # non threaded dirs = self.subDirs(self.protocol) index = self._readIndex() self.clampInfo['dirs'] = dirs self.clampInfo['missingData'] = [] self.traces = [] self.cmd = [] self.cmd_wave = [] self.time_base = [] self.values = [] self.trace_StartTimes = np.zeros(0) self.sample_rate = [] sequence_values = None for i, d in enumerate(dirs): fn = os.path.join(d, self.dataname) if not os.path.isfile(fn): continue tr = metaarray.MetaArray(file=fn) self.traces.append(tr.view(np.ndarray)[pos]) self.time_base.append(tr.xvals('Time')) info = tr[0].infoCopy() sr = info[1]['DAQ']['primary']['rate'] self.sample_rate.append(sr) self.traces = np.array(self.traces) self.time_base = np.array(self.time_base[0]) self.repetitions = index['.']['sequenceParams'][('protocol', 'repetitions')][0] + 1
def processData(self, data): if hasattr(data, 'implements') and data.implements('MetaArray'): info = data.infoCopy() if 'values' in info[0]: info[0]['values'] = info[0]['values'][:-1] return metaarray.MetaArray(data[1:] - data[:-1], info=info) else: return data[1:] - data[:-1]
def process(self, In, display=True): data = In.asarray() mean = np.mean(data) output = np.subtract(data, mean) # Generate meta array for output out_data = metaarray.MetaArray(output, info=[{'name': 'Time', 'values': np.linspace(0, len(output), len(output))}, {}]) return {'Out': out_data}
def update(self): #TODO fix this ugly if to something more generic. if self.signal_type == 'sin': # update signal value (sine) self.shared_data.signal_value_array[ self.pointer] = self.amplitude * np.sin( self.pointer * 2 * np.pi * self.frequency * 0.01) # Push the new data set to flow chart data = metaarray.MetaArray( self.shared_data.signal_value_array, info=[{ 'name': 'Time', 'values': np.linspace(0, 1000.0, len(self.shared_data.signal_value_array)) }, {}]) #self.flow_chart.setInput(sigOut=data) else: #This is the second generator # update signal value (sine) self.shared_data.signal_value_array2[ self.pointer] = self.amplitude * np.sin( self.pointer * 2 * np.pi * self.frequency * 0.01) # Push the new data set to flow chart data = metaarray.MetaArray( self.shared_data.signal_value_array2, info=[{ 'name': 'Time', 'values': np.linspace(0, 1000.0, len(self.shared_data.signal_value_array2)) }, {}]) #self.flow_chart.setInput(sigOut2=data) # move pointer self.pointer += 1 # Hop to start if we have reached the end if self.pointer >= self.shared_data.signal_value_array_size: self.pointer = 0
def process(self, In, display=True): indata = In.asarray() fd = self.ctrls['fd kHz/V'].value() output = [] summ = 0.0 for i in range (0,global_data.BUFFER_SIZE): summ += indata[i] output.append( np.cos((2*1000*np.pi*i + 2*fd*np.pi*summ) / global_data.BUFFER_SIZE) ) # Generate meta array for output out_data = metaarray.MetaArray(output, info=[{'name': 'Time', 'values': np.linspace(0, len(output), len(output))}, {}]) return {'Out': out_data}
def process(self, display=True): #if text is empty set bits to zero if self.char == "": result = [0, 0, 0, 0, 0, 0, 0, 0] data = metaarray.MetaArray(result, info=[{'name': 'Time', 'values': np.linspace(0, 7, len(result))}, {}]) else: #Convert character to binary bin_value = bin(ord(str(self.char))) bin_list = list(bin_value[2:]) # remove '0b' from start and convert to array bin_array = [int(i) for i in bin_list] #Convert string list to int list if len (bin_array) == 6: #adi edit to account for characters with 6 bit binary code bin_array.insert(0, 0)#adi edit bin_array.insert(7, 0) #adi edit this eighth bit is actually kept for parity wholeoutput = [] # adi edit ins START for j in range(0, (global_data.BUFFER_SIZE-global_data.BUFFER_SIZE%8)/8): #(global_data.BUFFER_SIZE-global_data.BUFFER_SIZE%8)/8: for k in range(0,8): wholeoutput.append(bin_array[k]) data = metaarray.MetaArray(wholeoutput, info=[{'name': 'Time', 'values': np.linspace(0, len(wholeoutput), len(wholeoutput))}, {}]) # adi edit ins END return {'Out': data}
def process(self, In, display=True): # Read GUI parameter values mode = self.ctrls['wave mode'].currentText() data = In.asarray() if mode == "half": output = np.clip(data, 0, 100000) else: output = np.absolute(data) # Generate meta array for output out_data = metaarray.MetaArray(output, info=[{'name': 'Time', 'values': np.linspace(0, len(output), len(output))}, {}]) return {'Out': out_data}
def init_filters(self): ## Create flowchart, define input/output terminals fc = Flowchart(terminals={ 'dataIn': { 'io': 'in' }, 'dataOut': { 'io': 'out' } }) ## Add flowchart control panel to the main window self.filter_d.layout.addWidget(fc.widget(), 0, 0, 2, 1) ## Add two plot widgets pw1 = pg.PlotWidget() pw2 = pg.PlotWidget() self.filter_d.layout.addWidget(pw1, 0, 1) self.filter_d.layout.addWidget(pw2, 1, 1) ## generate signal data to pass through the flowchart data = np.random.normal(size=1000) data[200:300] += 1 data += np.sin(np.linspace(0, 100, 1000)) data = metaarray.MetaArray(data, info=[{ 'name': 'Time', 'values': np.linspace(0, 1.0, len(data)) }, {}]) ## Feed data into the input terminal of the flowchart fc.setInput(dataIn=data) ## populate the flowchart with a basic set of processing nodes. ## (usually we let the user do this) plotList = {'Top Plot': pw1, 'Bottom Plot': pw2} pw1Node = fc.createNode('PlotWidget', pos=(0, -150)) pw1Node.setPlotList(plotList) pw1Node.setPlot(pw1) pw2Node = fc.createNode('PlotWidget', pos=(150, -150)) pw2Node.setPlot(pw2) pw2Node.setPlotList(plotList) fNode = fc.createNode('GaussianFilter', pos=(0, 0)) fNode.ctrls['sigma'].setValue(5) fc.connectTerminals(fc['dataIn'], fNode['In']) fc.connectTerminals(fc['dataIn'], pw1Node['In']) fc.connectTerminals(fNode['Out'], pw2Node['In']) fc.connectTerminals(fNode['Out'], fc['dataOut'])
def process(self, In, display=True): #Read parameter values code = self.ctrls['code'].currentText() symbolduration = global_data.BUFFER_SIZE / int(self.ctrls['rate, kBaud'].value()) decode = self.ctrls['decode mode'].isChecked() indata = In.asarray() data = [] #How many symbols fit into the array or buffer and take as many from indata to data for i in range (0,(global_data.BUFFER_SIZE-global_data.BUFFER_SIZE%symbolduration)/symbolduration): data.append(indata[i]) output = [] # duplicate each bit symbolduration times if not decode: if code == 'NRZ': for i in range(0, len(data)): for j in range(0,symbolduration): output.append(data[i]) elif code == 'Bipolar NRZ': for i in range(0, len(data)): for j in range(0,symbolduration): if data.item(i) == 1: signal_value = 0.5 else: signal_value = -0.5 output.append(signal_value) # Decode with symbolduration, take mid value (if symbolduration=10, read values, 5+15+25etc.) else: if code == 'NRZ': for i in range(0, len(data)/symbolduration): index = i * symbolduration + symbolduration / 2 output.append(data.item(index)) elif code == 'Bipolar NRZ': for i in range(0, len(data)/symbolduration): index = i * symbolduration + symbolduration / 2 value = data.item(index) if value > 0: output.append(1) else: output.append(0) #Generate MetaArray out_data = metaarray.MetaArray(output, info=[{'name': 'Time', 'values': np.linspace(0, len(output), len(output))}, {}]) return {'Out': out_data}
def process(self, In, display=True): #Read parameter values factor = self.ctrls['factor'].value() factor_source = self.ctrls['factor source'].currentText() # Read value from controller knob if factor_source != "None": knob_index = int(factor_source[len(factor_source)-1]) # Read the last character factor = global_data.potentiometer_values[knob_index] / 25.0 # Scale from [0,100] to [0,4] self.ctrls['factor'].setValue(factor) # Amplify / attenuate output = factor * In.asarray() #Generate MetaArray out_data = metaarray.MetaArray(output, info=[{'name': 'Time', 'values': np.linspace(0, len(output), len(output))}, {}]) return {'Out': out_data}
def process(self, In, display=True): # Read parameter values f_high_cutoff = self.ctrls['fh-3dB'].value() f_low_cutoff = self.ctrls['fl-3dB'].value() type = self.ctrls['type'].currentText() # Compute complex spectrum by fft for input signal of the filter fft_data = np.fft.fft(In.asarray()) # Generate complex filter function, initially all are set to zero filter_func_complex = np.zeros(global_data.BUFFER_SIZE, dtype=np.complex_) #Needed variables are defined in each loop to make formulas shorter and computing faster if type == "LPF": for i in range(0, global_data.BUFFER_SIZE/2-1): i_fh = i/f_high_cutoff filter_func_complex[i] = 1.0 / (1.0 + np.power(i_fh, 2)) + ((-i_fh)/(1.0 + np.power(i_fh, 2))) * 1j for i in range(global_data.BUFFER_SIZE/2, global_data.BUFFER_SIZE-1): #Note that in this section frequency index (i-global_data.BUFFER_SIZE) is negative that changes complex filter function to conjugate of positive portion above. #This transferres frequencies close to global_data.BUFFER_SIZE to negative frequencies and the same filtering function can e used ig_fh = (i-global_data.BUFFER_SIZE) / f_high_cutoff filter_func_complex[i] = 1.0 / (1.0 + np.power(ig_fh, 2)) - ig_fh/(1.0 + np.power(ig_fh, 2)) * 1j elif type == "HPF": for i in range(0, global_data.BUFFER_SIZE/2-1): i_fl = i/f_low_cutoff filter_func_complex[i] = (np.power(i_fl, 2)/(1.0 + np.power(i_fl, 2))) + ((i_fl)/(1.0 + np.power(i_fl, 2))) * 1j for i in range(global_data.BUFFER_SIZE/2, global_data.BUFFER_SIZE-1): ig_fl = (i-global_data.BUFFER_SIZE)/f_low_cutoff filter_func_complex[i] = (np.power(ig_fl, 2))/(1.0 + np.power(ig_fl, 2)) + (ig_fl/(1.0 + np.power(ig_fl, 2))) * 1j elif type == "BPF": for i in range(0, global_data.BUFFER_SIZE/2-1): i_fl = i/f_low_cutoff i_fh = i/f_high_cutoff filter_func_complex[i] = ((np.power(i_fl, 2))+(i_fh)*(i_fl))/((1.0 + np.power(i_fh, 2))*(1.0 + np.power(i_fl, 2))) + ((i_fl)-(i_fh)* np.power(i_fl, 2))/((1.0 + np.power(i_fh, 2))*(1.0 + np.power(i_fl, 2))) * 1j for i in range(global_data.BUFFER_SIZE/2, global_data.BUFFER_SIZE-1): ig_fl = (i-global_data.BUFFER_SIZE)/f_low_cutoff ig_fh = (i-global_data.BUFFER_SIZE) / f_high_cutoff filter_func_complex[i] = ((np.power(ig_fl, 2))+ig_fh * ig_fl)/((1 + np.power(ig_fh, 2))*(1.0 + np.power(ig_fl, 2))) + (ig_fl - ig_fh* np.power(ig_fl, 2))/((1.0 + np.power(ig_fh, 2))*(1.0 + np.power(ig_fl, 2))) * 1j #print "---" # Filter data with filter function (in frequncy domain) filtered_data = filter_func_complex * fft_data # Compute inverse fft to reconstruct time domain signal for filter output output = np.real(np.fft.ifft(filtered_data)) # Only real part to remove zero valued imaginary part # Generate MetaArray out_data = metaarray.MetaArray(output, info=[{'name': 'Time', 'values': np.linspace(0, len(output), len(output))}, {}]) return {'Out': out_data}
def process(self, In, display=True): # Read GUI parameter values parity = self.ctrls['Parity'].currentText() #data = In.view(np.ndarray) data = In.asarray() #adi edit - comments: #Desired changes in the 'Parity Bit Node': #Earlier version assumes that the input is 7-bit or 6-bit #(basically less than 8-bit) and appends an eighth bit #New version has "8-bit repeat sequence" input of which eighth bit (zero) has no meaning. #first seven bits of the sequence have to be retained, parity bit added, sequence repeated output = [] # copy received data to output array for i in range(0,7): output.append(data.item(i)) #copying seven bits from charToBinary node # append parity bit if parity == "odd": #if sum(data) % 2 == 0: earlier version if sum(output) % 2 == 0: output.append(1) else: output.append(0) else: if sum(output) % 2 == 0: output.append(0) else: output.append(1) # Generate meta array for output wholeoutput = [] for j in range(0,(global_data.BUFFER_SIZE-global_data.BUFFER_SIZE%8)/8): for k in range(0,8): wholeoutput.append(output[k]) out_data = metaarray.MetaArray(wholeoutput, info=[{'name': 'Time', 'values': np.linspace(0, len(wholeoutput), len(wholeoutput))}, {}]) return {'Out': out_data}
def read_nrrd_atlas(nrrd_file): """ Download atlas files from: http://help.brain-map.org/display/mouseconnectivity/API#API-DownloadAtlas """ try: import nrrd except ImportError: raise Exception( "Could not import module 'nrrd' (please install pynrrd)") data, header = nrrd.read(nrrd_file) # convert to ubyte to compress a bit # (no inplace multiply; nrrd returns read-only array) data = data * (255. / data.max()) data = data.astype('ubyte') # data must have axes (anterior, dorsal, right) # rearrange axes to fit -- CCF data comes in (posterior, inferior, right) order. data = data[::-1, ::-1, :] # voxel size in um vxsize = 1e-6 * float(header['space directions'][0][0]) info = [{ 'name': 'anterior', 'values': np.arange(data.shape[0]) * vxsize, 'units': 'm' }, { 'name': 'dorsal', 'values': np.arange(data.shape[1]) * vxsize, 'units': 'm' }, { 'name': 'right', 'values': np.arange(data.shape[2]) * vxsize, 'units': 'm' }, { 'vxsize': vxsize }] ma = metaarray.MetaArray(data, info=info) return ma
def readNRRDAtlas(nrrdFile=None): """ Download atlas files from: http://help.brain-map.org/display/mouseconnectivity/API#API-DownloadAtlas """ import nrrd if nrrdFile is None: displayMessage('Please Select NRRD Atlas File') nrrdFile = QtGui.QFileDialog.getOpenFileName(None, "Select NRRD atlas file") with pg.BusyCursor(): data, header = nrrd.read(nrrdFile) # convert to ubyte to compress a bit np.multiply(data, 255. / data.max(), out=data, casting='unsafe') data = data.astype('ubyte') # data must have axes (anterior, dorsal, right) # rearrange axes to fit -- CCF data comes in (posterior, inferior, right) order. data = data[::-1, ::-1, :] # voxel size in um vxsize = 1e-6 * float(header['space directions'][0][0]) info = [{ 'name': 'anterior', 'values': np.arange(data.shape[0]) * vxsize, 'units': 'm' }, { 'name': 'dorsal', 'values': np.arange(data.shape[1]) * vxsize, 'units': 'm' }, { 'name': 'right', 'values': np.arange(data.shape[2]) * vxsize, 'units': 'm' }, { 'vxsize': vxsize }] ma = metaarray.MetaArray(data, info=info) return ma
def read_nrrd_atlas(nrrd_file): """ Download atlas files from: http://help.brain-map.org/display/mouseconnectivity/API#API-DownloadAtlas """ import nrrd data, header = nrrd.read(nrrd_file) # convert to ubyte to compress a bit np.multiply(data, 255. / data.max(), out=data, casting='unsafe') data = data.astype('ubyte') # data must have axes (anterior, dorsal, right) # rearrange axes to fit -- CCF data comes in (posterior, inferior, right) order. data = data[::-1, ::-1, :] # voxel size in um vxsize = 1e-6 * float(header['space directions'][0][0]) info = [{ 'name': 'anterior', 'values': np.arange(data.shape[0]) * vxsize, 'units': 'm' }, { 'name': 'dorsal', 'values': np.arange(data.shape[1]) * vxsize, 'units': 'm' }, { 'name': 'right', 'values': np.arange(data.shape[2]) * vxsize, 'units': 'm' }, { 'vxsize': vxsize }] ma = metaarray.MetaArray(data, info=info) return ma
if __name__ == '__main__': app = pg.mkQApp() v = AtlasViewer() v.setWindowTitle('CCF Viewer') v.show() path = os.path.dirname(os.path.realpath(__file__)) atlasFile = os.path.join(path, "ccf.ma") labelFile = os.path.join(path, "ccf_label.ma") if os.path.isfile(atlasFile): atlas = metaarray.MetaArray(file=atlasFile, readAllData=True) else: try: atlas = readNRRDAtlas() writeFile(atlas, atlasFile) except: print "Unexpected error when creating ccf.ma file with " + atlasFile if os.path.isfile(atlasFile): try: print "Removing ccf.ma" os.remove(atlasFile) except: print "Error removing ccf.ma:" sys.excepthook(*sys.exc_info()) raise
win.setCentralWidget(t) win.resize(800, 600) win.show() ll = [[1, 2, 3, 4, 5]] * 20 ld = [{'x': 1, 'y': 2, 'z': 3}] * 20 dl = {'x': list(range(20)), 'y': list(range(20)), 'z': list(range(20))} a = np.ones((20, 5)) ra = np.ones((20, ), dtype=[('x', int), ('y', int), ('z', int)]) t.setData(ll) ma = metaarray.MetaArray(np.ones((20, 3)), info=[{ 'values': np.linspace(1, 5, 20) }, { 'cols': [ { 'name': 'x' }, { 'name': 'y' }, { 'name': 'z' }, ] }]) t.setData(ma)
def process(self, display=True): #Create meta array from updated data out_data = metaarray.MetaArray(self.data, info=[{'name': 'Time', 'values': np.linspace(0, len(self.data), len(self.data))}, {}]) #Set outputs return {'Out': out_data}
def readNRRDLabels(nrrdFile=None, ontologyFile=None): """ Download label files from: http://help.brain-map.org/display/mouseconnectivity/API#API-DownloadAtlas Download ontology files from: http://api.brain-map.org/api/v2/structure_graph_download/1.json see: http://help.brain-map.org/display/api/Downloading+an+Ontology%27s+Structure+Graph http://help.brain-map.org/display/api/Atlas+Drawings+and+Ontologies#AtlasDrawingsandOntologies-StructuresAndOntologies This method compresses the annotation data down to a 16-bit array by remapping the larger annotations to smaller, unused values. """ global onto, ontology, data, mapping, inds, vxsize, info, ma import nrrd if nrrdFile is None: displayMessage('Select NRRD annotation file') nrrdFile = QtGui.QFileDialog.getOpenFileName( None, "Select NRRD annotation file") if ontologyFile is None: displayMessage('Select ontology file (json)') ontoFile = QtGui.QFileDialog.getOpenFileName( None, "Select ontology file (json)") with pg.ProgressDialog("Loading annotation file...", 0, 5, wait=0) as dlg: print "Loading annotation file..." app.processEvents() # Read ontology and convert to flat table onto = json.load(open(ontoFile, 'rb')) onto = parseOntology(onto['msg'][0]) l1 = max([len(row[2]) for row in onto]) l2 = max([len(row[3]) for row in onto]) ontology = np.array(onto, dtype=[('id', 'int32'), ('parent', 'int32'), ('name', 'S%d' % l1), ('acronym', 'S%d' % l2), ('color', 'S6')]) if dlg.wasCanceled(): return dlg += 1 # read annotation data data, header = nrrd.read(nrrdFile) if dlg.wasCanceled(): return dlg += 1 # data must have axes (anterior, dorsal, right) # rearrange axes to fit -- CCF data comes in (posterior, inferior, right) order. data = data[::-1, ::-1, :] if dlg.wasCanceled(): return dlg += 1 # compress down to uint16 print "Compressing.." u = np.unique(data) # decide on a 32-to-64-bit label mapping mask = u <= 2**16 - 1 next_id = 2**16 - 1 mapping = OrderedDict() inds = set() for i in u[mask]: mapping[i] = i inds.add(i) with pg.ProgressDialog("Remapping annotations to 16-bit...", 0, (~mask).sum(), wait=0) as dlg: app.processEvents() for i in u[~mask]: while next_id in inds: next_id -= 1 mapping[i] = next_id inds.add(next_id) data[data == i] = next_id ontology['id'][ontology['id'] == i] = next_id ontology['parent'][ontology['parent'] == i] = next_id if dlg.wasCanceled(): return dlg += 1 data = data.astype('uint16') mapping = np.array(list(mapping.items())) # voxel size in um vxsize = 1e-6 * float(header['space directions'][0][0]) info = [{ 'name': 'anterior', 'values': np.arange(data.shape[0]) * vxsize, 'units': 'm' }, { 'name': 'dorsal', 'values': np.arange(data.shape[1]) * vxsize, 'units': 'm' }, { 'name': 'right', 'values': np.arange(data.shape[2]) * vxsize, 'units': 'm' }, { 'vxsize': vxsize, 'ai_ontology_map': mapping, 'ontology': ontology }] ma = metaarray.MetaArray(data, info=info) return ma
def load_label_cache(self): """Load a MetaArray-format atlas label file. """ filename = self._label_cache_file self.label = metaarray.MetaArray(file=filename, readAllData=True) self.ontology = self.label._info[-1]['ontology']
def load_image_cache(self): """Load a MetaArray-format atlas image file. """ filename = self._image_cache_file self.image = metaarray.MetaArray(file=filename, readAllData=True)
## Add flowchart control panel to the main window layout.addWidget(fc.widget(), 0, 0, 2, 1) ## Add two plot widgets pw1 = pg.PlotWidget() pw2 = pg.PlotWidget() layout.addWidget(pw1, 0, 1) layout.addWidget(pw2, 1, 1) win.show() ## generate signal data to pass through the flowchart data = np.random.normal(size=1000) data[200:300] += 1 data += np.sin(np.linspace(0, 100, 1000)) data = metaarray.MetaArray(data, info=[{'name': 'Time', 'values': np.linspace(0, 1.0, len(data))}, {}]) ## Feed data into the input terminal of the flowchart fc.setInput(dataIn=data) ## populate the flowchart with a basic set of processing nodes. ## (usually we let the user do this) plotList = {'Top Plot': pw1, 'Bottom Plot': pw2} pw1Node = fc.createNode('PlotWidget', pos=(0, -150)) pw1Node.setPlotList(plotList) pw1Node.setPlot(pw1) pw2Node = fc.createNode('PlotWidget', pos=(150, -150)) pw2Node.setPlot(pw2) pw2Node.setPlotList(plotList)
import pyqtgraph as pg import pyqtgraph.metaarray as metaarray from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph.opengl as pgl import scipy.ndimage as ndi import numpy as np pg.mkQApp() view = pgl.GLViewWidget() atlas = metaarray.MetaArray(file='ccf.ma', readAllData=True) img = np.ascontiguousarray(atlas.asarray()[::8,::8,::8]) # render volume #vol = np.empty(img.shape + (4,), dtype='ubyte') #vol[:] = img[..., None] #vol = np.ascontiguousarray(vol.transpose(1, 2, 0, 3)) #vi = pgl.GLVolumeItem(vol) #self.glView.addItem(vi) #vi.translate(-vol.shape[0]/2., -vol.shape[1]/2., -vol.shape[2]/2.) verts, faces = pg.isosurface(ndi.gaussian_filter(img.astype('float32'), (2, 2, 2)), 5.0) md = pgl.MeshData(vertexes=verts, faces=faces) mesh = pgl.GLMeshItem(meshdata=md, smooth=True, color=[0.5, 0.5, 0.5, 0.2], shader='balloon') mesh.setGLOptions('additive') mesh.translate(-img.shape[0]/2., -img.shape[1]/2., -img.shape[2]/2.) view.addItem(mesh)