def createCellsFixedNum(self): ''' Create population cells based on fixed number of cells''' cellModelClass = f.Cell cells = [] seed(f.sim.id32('%d'%(f.cfg['seeds']['loc']+self.tags['numCells']+f.net.lastGid))) randLocs = rand(self.tags['numCells'], 3) # create random x,y,z locations for icoord, coord in enumerate(['x', 'y', 'z']): if coord+'Range' in self.tags: # if user provided absolute range, convert to normalized self.tags[coord+'normRange'] = [float(point) / f.net.params['size'+coord.upper()] for point in self.tags[coord+'Range']] if coord+'normRange' in self.tags: # if normalized range, rescale random locations minv = self.tags[coord+'normRange'][0] maxv = self.tags[coord+'normRange'][1] randLocs[:,icoord] = randLocs[:,icoord] * (maxv-minv) + minv for i in xrange(int(f.rank), f.net.params['scale'] * self.tags['numCells'], f.nhosts): gid = f.net.lastGid+i self.cellGids.append(gid) # add gid list of cells belonging to this population - not needed? cellTags = {k: v for (k, v) in self.tags.iteritems() if k in f.net.params['popTagsCopiedToCells']} # copy all pop tags to cell tags, except those that are pop-specific cellTags['xnorm'] = randLocs[i,0] # set x location (um) cellTags['ynorm'] = randLocs[i,1] # set y location (um) cellTags['znorm'] = randLocs[i,2] # set z location (um) cellTags['x'] = f.net.params['sizeX'] * randLocs[i,0] # set x location (um) cellTags['y'] = f.net.params['sizeY'] * randLocs[i,1] # set y location (um) cellTags['z'] = f.net.params['sizeZ'] * randLocs[i,2] # set z location (um) if 'propList' not in cellTags: cellTags['propList'] = [] # initalize list of property sets if doesn't exist cells.append(cellModelClass(gid, cellTags)) # instantiate Cell object if f.cfg['verbose']: print('Cell %d/%d (gid=%d) of pop %s, on node %d, '%(i, f.net.params['scale'] * self.tags['numCells']-1, gid, self.tags['popLabel'], f.rank)) f.net.lastGid = f.net.lastGid + self.tags['numCells'] return cells
def createCellsFixedNum (self): ''' Create population cells based on fixed number of cells''' cells = [] seed(sim.id32('%d'%(sim.cfg.seeds['loc']+self.tags['numCells']+sim.net.lastGid))) randLocs = rand(self.tags['numCells'], 3) # create random x,y,z locations if sim.net.params.shape == 'cylinder': # Use the x,z random vales rho = randLocs[:,0] # use x rand value as the radius rho in the interval [0, 1) phi = 2 * pi * randLocs[:,2] # use z rand value as the angle phi in the interval [0, 2*pi) x = (1 + sqrt(rho) * cos(phi))/2.0 z = (1 + sqrt(rho) * sin(phi))/2.0 randLocs[:,0] = x randLocs[:,2] = z elif sim.net.params.shape == 'ellipsoid': # Use the x,y,z random vales rho = np.power(randLocs[:,0], 1.0/3.0) # use x rand value as the radius rho in the interval [0, 1); cuberoot phi = 2 * pi * randLocs[:,1] # use y rand value as the angle phi in the interval [0, 2*pi) costheta = (2 * randLocs[:,2]) - 1 # use z rand value as cos(theta) in the interval [-1, 1); ensures uniform dist theta = arccos(costheta) # obtain theta from cos(theta) x = (1 + rho * cos(phi) * sin(theta))/2.0 y = (1 + rho * sin(phi) * sin(theta))/2.0 z = (1 + rho * cos(theta))/2.0 randLocs[:,0] = x randLocs[:,1] = y randLocs[:,2] = z for icoord, coord in enumerate(['x', 'y', 'z']): if coord+'Range' in self.tags: # if user provided absolute range, convert to normalized self.tags[coord+'normRange'] = [float(point) / getattr(sim.net.params, 'size'+coord.upper()) for point in self.tags[coord+'Range']] # constrain to range set by user if coord+'normRange' in self.tags: # if normalized range, rescale random locations minv = self.tags[coord+'normRange'][0] maxv = self.tags[coord+'normRange'][1] randLocs[:,icoord] = randLocs[:,icoord] * (maxv-minv) + minv for i in self._distributeCells(int(sim.net.params.scale * self.tags['numCells']))[sim.rank]: gid = sim.net.lastGid+i self.cellGids.append(gid) # add gid list of cells belonging to this population - not needed? cellTags = {k: v for (k, v) in self.tags.iteritems() if k in sim.net.params.popTagsCopiedToCells} # copy all pop tags to cell tags, except those that are pop-specific cellTags['popLabel'] = self.tags['popLabel'] cellTags['xnorm'] = randLocs[i,0] # set x location (um) cellTags['ynorm'] = randLocs[i,1] # set y location (um) cellTags['znorm'] = randLocs[i,2] # set z location (um) cellTags['x'] = sim.net.params.sizeX * randLocs[i,0] # set x location (um) cellTags['y'] = sim.net.params.sizeY * randLocs[i,1] # set y location (um) cellTags['z'] = sim.net.params.sizeZ * randLocs[i,2] # set z location (um) cells.append(self.cellModelClass(gid, cellTags)) # instantiate Cell object if sim.cfg.verbose: print('Cell %d/%d (gid=%d) of pop %s, on node %d, '%(i, sim.net.params.scale * self.tags['numCells']-1, gid, self.tags['popLabel'], sim.rank)) sim.net.lastGid = sim.net.lastGid + self.tags['numCells'] return cells
def createCellsFixedNum(self): ''' Create population cells based on fixed number of cells''' cellModelClass = sim.Cell cells = [] seed( sim.id32('%d' % (sim.cfg.seeds['loc'] + self.tags['numCells'] + sim.net.lastGid))) randLocs = rand(self.tags['numCells'], 3) # create random x,y,z locations for icoord, coord in enumerate(['x', 'y', 'z']): if coord + 'Range' in self.tags: # if user provided absolute range, convert to normalized self.tags[coord + 'normRange'] = [ float(point) / getattr(sim.net.params, 'size' + coord.upper()) for point in self.tags[coord + 'Range'] ] if coord + 'normRange' in self.tags: # if normalized range, rescale random locations minv = self.tags[coord + 'normRange'][0] maxv = self.tags[coord + 'normRange'][1] randLocs[:, icoord] = randLocs[:, icoord] * (maxv - minv) + minv for i in xrange(int(sim.rank), sim.net.params.scale * self.tags['numCells'], sim.nhosts): gid = sim.net.lastGid + i self.cellGids.append( gid ) # add gid list of cells belonging to this population - not needed? cellTags = { k: v for (k, v) in self.tags.iteritems() if k in sim.net.params.popTagsCopiedToCells } # copy all pop tags to cell tags, except those that are pop-specific cellTags['popLabel'] = self.tags['popLabel'] cellTags['xnorm'] = randLocs[i, 0] # set x location (um) cellTags['ynorm'] = randLocs[i, 1] # set y location (um) cellTags['znorm'] = randLocs[i, 2] # set z location (um) cellTags['x'] = sim.net.params.sizeX * randLocs[ i, 0] # set x location (um) cellTags['y'] = sim.net.params.sizeY * randLocs[ i, 1] # set y location (um) cellTags['z'] = sim.net.params.sizeZ * randLocs[ i, 2] # set z location (um) cells.append(cellModelClass(gid, cellTags)) # instantiate Cell object if sim.cfg.verbose: print('Cell %d/%d (gid=%d) of pop %s, on node %d, ' % (i, sim.net.params.scale * self.tags['numCells'] - 1, gid, self.tags['popLabel'], sim.rank)) sim.net.lastGid = sim.net.lastGid + self.tags['numCells'] return cells
def createCellsGrid (self): ''' Create population cells based on fixed number of cells''' cells = [] seed(sim.id32('%d'%(sim.cfg.seeds['loc']+self.tags['gridSpacing']+sim.net.lastGid))) rangeLocs = [[0, getattr(sim.net.params, 'size'+coord)] for coord in ['X','Y','Z']] for icoord, coord in enumerate(['x', 'y', 'z']): # constrain to range set by user if coord+'normRange' in self.tags: # if normalized range, convert to normalized self.tags[coord+'Range'] = [float(point) * getattr(sim.net.params, 'size'+coord.upper()) for point in self.tags[coord+'Range']] if coord+'Range' in self.tags: # if user provided absolute range, calculate range self.tags[coord+'normRange'] = [float(point) / getattr(sim.net.params, 'size'+coord.upper()) for point in self.tags[coord+'Range']] rangeLocs[icoord] = [self.tags[coord+'Range'][0], self.tags[coord+'Range'][1]] gridSpacing = self.tags['gridSpacing'] gridLocs = [] for x in np.arange(rangeLocs[0][0], rangeLocs[0][1]+1, gridSpacing): for y in np.arange(rangeLocs[1][0], rangeLocs[1][1]+1, gridSpacing): for z in np.arange(rangeLocs[2][0], rangeLocs[2][1]+1, gridSpacing): gridLocs.append((x, y, z)) numCells = len(gridLocs) for i in self._distributeCells(numCells)[sim.rank]: gid = sim.net.lastGid+i self.cellGids.append(gid) # add gid list of cells belonging to this population - not needed? cellTags = {k: v for (k, v) in self.tags.iteritems() if k in sim.net.params.popTagsCopiedToCells} # copy all pop tags to cell tags, except those that are pop-specific cellTags['popLabel'] = self.tags['popLabel'] cellTags['xnorm'] = gridLocs[i][0] / sim.net.params.sizeX # set x location (um) cellTags['ynorm'] = gridLocs[i][1] / sim.net.params.sizeY # set y location (um) cellTags['znorm'] = gridLocs[i][2] / sim.net.params.sizeZ # set z location (um) cellTags['x'] = gridLocs[i][0] # set x location (um) cellTags['y'] = gridLocs[i][1] # set y location (um) cellTags['z'] = gridLocs[i][2] # set z location (um) cells.append(self.cellModelClass(gid, cellTags)) # instantiate Cell object if sim.cfg.verbose: print('Cell %d/%d (gid=%d) of pop %s, on node %d, '%(i, numCells, gid, self.tags['popLabel'], sim.rank)) sim.net.lastGid = sim.net.lastGid + numCells return cells
def createCellsDensity (self): ''' Create population cells based on density''' cells = [] shape = sim.net.params.shape sizeX = sim.net.params.sizeX sizeY = sim.net.params.sizeY sizeZ = sim.net.params.sizeZ # calculate volume if shape == 'cuboid': volume = sizeY/1e3 * sizeX/1e3 * sizeZ/1e3 elif shape == 'cylinder': volume = sizeY/1e3 * sizeX/1e3/2 * sizeZ/1e3/2 * pi elif shape == 'ellipsoid': volume = sizeY/1e3/2.0 * sizeX/1e3/2.0 * sizeZ/1e3/2.0 * pi * 4.0 / 3.0 for coord in ['x', 'y', 'z']: if coord+'Range' in self.tags: # if user provided absolute range, convert to normalized self.tags[coord+'normRange'] = [point / sim.net.params['size'+coord.upper()] for point in self.tags[coord+'Range']] if coord+'normRange' in self.tags: # if normalized range, rescale volume minv = self.tags[coord+'normRange'][0] maxv = self.tags[coord+'normRange'][1] volume = volume * (maxv-minv) funcLocs = None # start with no locations as a function of density function if isinstance(self.tags['density'], str): # check if density is given as a function if shape == 'cuboid': # only available for cuboids strFunc = self.tags['density'] # string containing function strVars = [var for var in ['xnorm', 'ynorm', 'znorm'] if var in strFunc] # get list of variables used if not len(strVars) == 1: print 'Error: density function (%s) for population %s does not include "xnorm", "ynorm" or "znorm"'%(strFunc,self.tags['popLabel']) return coordFunc = strVars[0] lambdaStr = 'lambda ' + coordFunc +': ' + strFunc # convert to lambda function densityFunc = eval(lambdaStr) minRange = self.tags[coordFunc+'Range'][0] maxRange = self.tags[coordFunc+'Range'][1] interval = 0.001 # interval of location values to evaluate func in order to find the max cell density maxDensity = max(map(densityFunc, (arange(minRange, maxRange, interval)))) # max cell density maxCells = volume * maxDensity # max number of cells based on max value of density func seed(sim.id32('%d' % sim.cfg.seeds['loc']+sim.net.lastGid)) # reset random number generator locsAll = minRange + ((maxRange-minRange)) * rand(int(maxCells), 1) # random location values locsProb = array(map(densityFunc, locsAll)) / maxDensity # calculate normalized density for each location value (used to prune) allrands = rand(len(locsProb)) # create an array of random numbers for checking each location pos makethiscell = locsProb>allrands # perform test to see whether or not this cell should be included (pruning based on density func) funcLocs = [locsAll[i] for i in range(len(locsAll)) if i in array(makethiscell.nonzero()[0],dtype='int')] # keep only subset of yfuncLocs based on density func self.tags['numCells'] = len(funcLocs) # final number of cells after pruning of location values based on density func if sim.cfg.verbose: print 'Volume=%.2f, maxDensity=%.2f, maxCells=%.0f, numCells=%.0f'%(volume, maxDensity, maxCells, self.tags['numCells']) else: print 'Error: Density functions are only implemented for cuboid shaped networks' exit(0) else: # NO ynorm-dep self.tags['numCells'] = int(self.tags['density'] * volume) # = density (cells/mm^3) * volume (mm^3) # calculate locations of cells seed(sim.id32('%d'%(sim.cfg.seeds['loc']+self.tags['numCells']+sim.net.lastGid))) randLocs = rand(self.tags['numCells'], 3) # create random x,y,z locations if sim.net.params.shape == 'cylinder': # Use the x,z random vales rho = randLocs[:,0] # use x rand value as the radius rho in the interval [0, 1) phi = 2 * pi * randLocs[:,2] # use z rand value as the angle phi in the interval [0, 2*pi) x = (1 + sqrt(rho) * cos(phi))/2.0 z = (1 + sqrt(rho) * sin(phi))/2.0 randLocs[:,0] = x randLocs[:,2] = z elif sim.net.params.shape == 'ellipsoid': # Use the x,y,z random vales rho = np.power(randLocs[:,0], 1.0/3.0) # use x rand value as the radius rho in the interval [0, 1); cuberoot phi = 2 * pi * randLocs[:,1] # use y rand value as the angle phi in the interval [0, 2*pi) costheta = (2 * randLocs[:,2]) - 1 # use z rand value as cos(theta) in the interval [-1, 1); ensures uniform dist theta = arccos(costheta) # obtain theta from cos(theta) x = (1 + rho * cos(phi) * sin(theta))/2.0 y = (1 + rho * sin(phi) * sin(theta))/2.0 z = (1 + rho * cos(theta))/2.0 randLocs[:,0] = x randLocs[:,1] = y randLocs[:,2] = z for icoord, coord in enumerate(['x', 'y', 'z']): if coord+'normRange' in self.tags: # if normalized range, rescale random locations minv = self.tags[coord+'normRange'][0] maxv = self.tags[coord+'normRange'][1] randLocs[:,icoord] = randLocs[:,icoord] * (maxv-minv) + minv if funcLocs and coordFunc == coord+'norm': # if locations for this coordinate calculated using density function randLocs[:,icoord] = funcLocs if sim.cfg.verbose and not funcLocs: print 'Volume=%.4f, density=%.2f, numCells=%.0f'%(volume, self.tags['density'], self.tags['numCells']) for i in self._distributeCells(self.tags['numCells'])[sim.rank]: gid = sim.net.lastGid+i self.cellGids.append(gid) # add gid list of cells belonging to this population - not needed? cellTags = {k: v for (k, v) in self.tags.iteritems() if k in sim.net.params.popTagsCopiedToCells} # copy all pop tags to cell tags, except those that are pop-specific cellTags['popLabel'] = self.tags['popLabel'] cellTags['xnorm'] = randLocs[i,0] # calculate x location (um) cellTags['ynorm'] = randLocs[i,1] # calculate y location (um) cellTags['znorm'] = randLocs[i,2] # calculate z location (um) cellTags['x'] = sizeX * randLocs[i,0] # calculate x location (um) cellTags['y'] = sizeY * randLocs[i,1] # calculate y location (um) cellTags['z'] = sizeZ * randLocs[i,2] # calculate z location (um) cells.append(self.cellModelClass(gid, cellTags)) # instantiate Cell object if sim.cfg.verbose: print('Cell %d/%d (gid=%d) of pop %s, pos=(%2.f, %2.f, %2.f), on node %d, '%(i, self.tags['numCells']-1, gid, self.tags['popLabel'],cellTags['x'], cellTags['y'], cellTags['z'], sim.rank)) sim.net.lastGid = sim.net.lastGid + self.tags['numCells'] return cells
def createCellsDensity(self): ''' Create population cells based on density''' cellModelClass = sim.Cell cells = [] volume = sim.net.params.sizeY / 1e3 * sim.net.params.sizeX / 1e3 * sim.net.params.sizeZ / 1e3 # calculate full volume for coord in ['x', 'y', 'z']: if coord + 'Range' in self.tags: # if user provided absolute range, convert to normalized self.tags[coord + 'normRange'] = [ point / sim.net.params['size' + coord.upper()] for point in self.tags[coord + 'Range'] ] if coord + 'normRange' in self.tags: # if normalized range, rescale volume minv = self.tags[coord + 'normRange'][0] maxv = self.tags[coord + 'normRange'][1] volume = volume * (maxv - minv) funcLocs = None # start with no locations as a function of density function if isinstance(self.tags['density'], str): # check if density is given as a function strFunc = self.tags['density'] # string containing function strVars = [ var for var in ['xnorm', 'ynorm', 'znorm'] if var in strFunc ] # get list of variables used if not len(strVars) == 1: print 'Error: density function (%s) for population %s does not include "xnorm", "ynorm" or "znorm"' % ( strFunc, self.tags['popLabel']) return coordFunc = strVars[0] lambdaStr = 'lambda ' + coordFunc + ': ' + strFunc # convert to lambda function densityFunc = eval(lambdaStr) minRange = self.tags[coordFunc + 'Range'][0] maxRange = self.tags[coordFunc + 'Range'][1] interval = 0.001 # interval of location values to evaluate func in order to find the max cell density maxDensity = max( map(densityFunc, (arange(minRange, maxRange, interval)))) # max cell density maxCells = volume * maxDensity # max number of cells based on max value of density func seed(sim.id32('%d' % sim.cfg.seeds['loc'] + sim.net.lastGid)) # reset random number generator locsAll = minRange + ((maxRange - minRange)) * rand( int(maxCells), 1) # random location values locsProb = array( map(densityFunc, locsAll) ) / maxDensity # calculate normalized density for each location value (used to prune) allrands = rand( len(locsProb) ) # create an array of random numbers for checking each location pos makethiscell = locsProb > allrands # perform test to see whether or not this cell should be included (pruning based on density func) funcLocs = [ locsAll[i] for i in range(len(locsAll)) if i in array(makethiscell.nonzero()[0], dtype='int') ] # keep only subset of yfuncLocs based on density func self.tags['numCells'] = len( funcLocs ) # final number of cells after pruning of location values based on density func if sim.cfg.verbose: print 'Volume=%.2f, maxDensity=%.2f, maxCells=%.0f, numCells=%.0f' % ( volume, maxDensity, maxCells, self.tags['numCells']) else: # NO ynorm-dep self.tags['numCells'] = int( self.tags['density'] * volume) # = density (cells/mm^3) * volume (mm^3) # calculate locations of cells seed( sim.id32('%d' % (sim.cfg.seeds['loc'] + self.tags['numCells'] + sim.net.lastGid))) randLocs = rand(self.tags['numCells'], 3) # create random x,y,z locations for icoord, coord in enumerate(['x', 'y', 'z']): if coord + 'normRange' in self.tags: # if normalized range, rescale random locations minv = self.tags[coord + 'normRange'][0] maxv = self.tags[coord + 'normRange'][1] randLocs[:, icoord] = randLocs[:, icoord] * (maxv - minv) + minv if funcLocs and coordFunc == coord + 'norm': # if locations for this coordinate calcualated using density function randLocs[:, icoord] = funcLocs if sim.cfg.verbose and not funcLocs: print 'Volume=%.4f, density=%.2f, numCells=%.0f' % ( volume, self.tags['density'], self.tags['numCells']) for i in xrange(int(sim.rank), self.tags['numCells'], sim.nhosts): gid = sim.net.lastGid + i self.cellGids.append( gid ) # add gid list of cells belonging to this population - not needed? cellTags = { k: v for (k, v) in self.tags.iteritems() if k in sim.net.params.popTagsCopiedToCells } # copy all pop tags to cell tags, except those that are pop-specific cellTags['popLabel'] = self.tags['popLabel'] cellTags['xnorm'] = randLocs[i, 0] # calculate x location (um) cellTags['ynorm'] = randLocs[i, 1] # calculate y location (um) cellTags['znorm'] = randLocs[i, 2] # calculate z location (um) cellTags['x'] = sim.net.params.sizeX * randLocs[ i, 0] # calculate x location (um) cellTags['y'] = sim.net.params.sizeY * randLocs[ i, 1] # calculate y location (um) cellTags['z'] = sim.net.params.sizeZ * randLocs[ i, 2] # calculate z location (um) cells.append(cellModelClass(gid, cellTags)) # instantiate Cell object if sim.cfg.verbose: print( 'Cell %d/%d (gid=%d) of pop %s, pos=(%2.f, %2.f, %2.f), on node %d, ' % (i, self.tags['numCells'] - 1, gid, self.tags['popLabel'], cellTags['x'], cellTags['y'], cellTags['z'], sim.rank)) sim.net.lastGid = sim.net.lastGid + self.tags['numCells'] return cells
def createCellsDensity(self): ''' Create population cells based on density''' cellModelClass = f.Cell cells = [] volume = f.net.params['sizeY']/1e3 * f.net.params['sizeX']/1e3 * f.net.params['sizeZ']/1e3 # calculate full volume for coord in ['x', 'y', 'z']: if coord+'Range' in self.tags: # if user provided absolute range, convert to normalized self.tags[coord+'normRange'] = [point / f.net.params['size'+coord.upper()] for point in self.tags[coord+'Range']] if coord+'normRange' in self.tags: # if normalized range, rescale volume minv = self.tags[coord+'normRange'][0] maxv = self.tags[coord+'normRange'][1] volume = volume * (maxv-minv) funcLocs = None # start with no locations as a function of density function if isinstance(self.tags['density'], str): # check if density is given as a function strFunc = self.tags['density'] # string containing function strVars = [var for var in ['xnorm', 'ynorm', 'znorm'] if var in strFunc] # get list of variables used if not len(strVars) == 1: print 'Error: density function (%s) for population %s does not include "xnorm", "ynorm" or "znorm"'%(strFunc,self.tags['popLabel']) return coordFunc = strVars[0] lambdaStr = 'lambda ' + coordFunc +': ' + strFunc # convert to lambda function densityFunc = eval(lambdaStr) minRange = self.tags[coordFunc+'Range'][0] maxRange = self.tags[coordFunc+'Range'][1] interval = 0.001 # interval of location values to evaluate func in order to find the max cell density maxDensity = max(map(densityFunc, (arange(minRange, maxRange, interval)))) # max cell density maxCells = volume * maxDensity # max number of cells based on max value of density func seed(f.sim.id32('%d' % f.cfg['seeds']['loc'])) # reset random number generator locsAll = minRange + ((maxRange-minRange)) * rand(int(maxCells), 1) # random location values locsProb = array(map(densityFunc, locsAll)) / maxDensity # calculate normalized density for each location value (used to prune) allrands = rand(len(locsProb)) # create an array of random numbers for checking each location pos makethiscell = locsProb>allrands # perform test to see whether or not this cell should be included (pruning based on density func) funcLocs = [locsAll[i] for i in range(len(locsAll)) if i in array(makethiscell.nonzero()[0],dtype='int')] # keep only subset of yfuncLocs based on density func self.tags['numCells'] = len(funcLocs) # final number of cells after pruning of location values based on density func if f.cfg['verbose']: print 'Volume=%.2f, maxDensity=%.2f, maxCells=%.0f, numCells=%.0f'%(volume, maxDensity, maxCells, self.tags['numCells']) else: # NO ynorm-dep self.tags['numCells'] = int(self.tags['density'] * volume) # = density (cells/mm^3) * volume (mm^3) # calculate locations of cells seed(f.sim.id32('%d'%(f.cfg['seeds']['loc']+self.tags['numCells']))) randLocs = rand(self.tags['numCells'], 3) # create random x,y,z locations for icoord, coord in enumerate(['x', 'y', 'z']): if coord+'normRange' in self.tags: # if normalized range, rescale random locations minv = self.tags[coord+'normRange'][0] maxv = self.tags[coord+'normRange'][1] randLocs[:,icoord] = randLocs[:,icoord] * (maxv-minv) + minv if funcLocs and coordFunc == coord+'norm': # if locations for this coordinate calcualated using density function randLocs[:,icoord] = funcLocs if f.cfg['verbose'] and not funcLocs: print 'Volume=%.4f, density=%.2f, numCells=%.0f'%(volume, self.tags['density'], self.tags['numCells']) for i in xrange(int(f.rank), self.tags['numCells'], f.nhosts): gid = f.net.lastGid+i self.cellGids.append(gid) # add gid list of cells belonging to this population - not needed? cellTags = {k: v for (k, v) in self.tags.iteritems() if k in f.net.params['popTagsCopiedToCells']} # copy all pop tags to cell tags, except those that are pop-specific cellTags['xnorm'] = randLocs[i,0] # calculate x location (um) cellTags['ynorm'] = randLocs[i,1] # calculate x location (um) cellTags['znorm'] = randLocs[i,2] # calculate z location (um) cellTags['x'] = f.net.params['sizeX'] * randLocs[i,0] # calculate x location (um) cellTags['y'] = f.net.params['sizeY'] * randLocs[i,1] # calculate x location (um) cellTags['z'] = f.net.params['sizeZ'] * randLocs[i,2] # calculate z location (um) if 'propList' not in cellTags: cellTags['propList'] = [] # initalize list of property sets if doesn't exist cells.append(cellModelClass(gid, cellTags)) # instantiate Cell object if f.cfg['verbose']: print('Cell %d/%d (gid=%d) of pop %s, pos=(%2.f, %2.f, %2.f), on node %d, '%(i, self.tags['numCells']-1, gid, self.tags['popLabel'],cellTags['x'], cellTags['ynorm'], cellTags['z'], f.rank)) f.net.lastGid = f.net.lastGid + self.tags['numCells'] return cells
import matplotlib.pylab as pl import LFPy import numpy as np import os import sys import neuron from plotting import plotstuff, simple_plot_2D, plot_cell_compartments, plot_sec from tools import push_simulation_to_folder, analyze_neuron, find_sec_from_comp sim_folder = "hay_model/" LFPy.cell.neuron.load_mechanisms(sim_folder + "/mod") pl.seed(999) cellParameters = { "morphology": sim_folder + "lfpy_version/morphologies/cell1.hoc", #'rm' : 30000, # membrane resistance #'cm' : 1.0, # membrane capacitance "Ra": 80, # axial resistance "v_init": -80, # initial crossmembrane potential #'e_pas' : -90, # reversal potential passive mechs #'passive' : True, # switch on passive mechs #'nsegs_method' : 'lambda_f',# method for setting number of segments, #'lambda_f' : 100, # segments are isopotential at this frequency "timeres_NEURON": 2 ** -4, # dt of LFP and NEURON simulation. "timeres_python": 2 ** -4, "tstartms": -50, # start time, recorders start at t=0 "tstopms": 120, # stop time of simulation "custom_code": [sim_folder + "lfpy_version/custom_codes.hoc", sim_folder + "lfpy_version/biophys3.hoc"], # will if given list of files run this file } # Synaptic parameters taken from Hendrickson et al 2011
import matplotlib.pylab as pl import numpy as np import os import sys #seed for random generation pl.seed(0) def find_sec_from_comp(cell, comp): name_list = [] for sec in cell.allseclist: name_list.append(str(sec.name())) for name in name_list: comps = cell.get_idx_section(name) if comp in comps: print comp, name return name def push_simulation_to_folder(save_to_folder, data_from_folder): print "Copying all simulation results from %s " %data_from_folder\ +"and simulation file to folder %s." % save_to_folder try: os.mkdir(save_to_folder) except(OSError): print "Result folder already exists. Overwriting..." os.system('cp %s/* %s' %(data_from_folder, save_to_folder)) def find_amplitude_at_comp(signal_with_spike, debug=False): n_compartments = len(signal_with_spike[:,0])
samps = {7} # Number of valid samps per sequence stride = {8} # hop size iSNR = {9:.3} # inverse signal to noise ratio. basically, volume # of noise added to input desired_sr = {10} # signals are resampled to this rate mu = {11} # quantization level C = {12} # number of chunks drop_prob = {13} # Dropout probability for pre-output layer VAL = {14} # Whether to have validation or not """.format( seed, num_filts, K, D, dil_reg, reg_out, batch_size, samps, stride, iSNR, desired_sr, mu, C, drop_prob, VAL ) print(TXT) P.seed(seed) # Getting the data x1, sr = read("new/ajay1.wav") y1, sr = read("new/anh_synced_ajay1.wav") y1 = y1[:len(x1)] x1 = resample_poly(x1, desired_sr, sr) vx1 = P.sqrt((x1**2).mean()) x1 = x1 / vx1 * .05 y1 = resample_poly(y1, desired_sr, sr) vy1 = P.sqrt((y1**2).mean()) y1 = y1 / vy1 * .05 sr = desired_sr x2, sr = read("new/ajay2.wav") y2, sr = read("new/anh_synced_ajay2.wav")