Skip to content

Commit

Permalink
Merge pull request #801 from suny-downstate-medical-center/development
Browse files Browse the repository at this point in the history
Merge latest development to nml branch
  • Loading branch information
pgleeson authored Dec 14, 2023
2 parents 06eb47f + 9d53354 commit 43d1731
Show file tree
Hide file tree
Showing 138 changed files with 19,147 additions and 2,695 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

- Fixed loading netParams in some scenarios (bug caused by srting functions pre-processing)

- Fix of `plotRaster` pops coloring if ordered not by gid

# Version 1.0.5

**New features**
Expand Down
2 changes: 2 additions & 0 deletions netpyne/analysis/spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ def prepareSpikeData(
'orderBy': orderBy,
'axisArgs': axisArgs,
'legendLabels': legendLabels,
'cellGids': df['pop'].index.tolist(),
'cellPops': df['pop'].tolist(),
}

if colorbyPhase:
Expand Down
54 changes: 34 additions & 20 deletions netpyne/plotting/plotRaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def plotRaster(
if type(rasterData) == str:
rasterData = loadData(rasterData)

popsOfCellsByGid = zip([], [])

# If input is a dictionary, pull the data out of it
if type(rasterData) == dict:

Expand All @@ -245,6 +247,10 @@ def plotRaster(
axisArgs = rasterData.get('axisArgs')
legendLabels = rasterData.get('legendLabels')

popsOfCellsByGid = zip( # ordered the same
rasterData.get('cellGids', []),
rasterData.get('cellPops', []))

# If input is a list or tuple, the first item is spike times, the second is spike indices
elif type(rasterData) == list or type(rasterData) == tuple:
spkTimes = rasterData[0]
Expand Down Expand Up @@ -288,32 +294,13 @@ def plotRaster(
+ ') must be the same size'
)

# Create a dictionary with the color for each pop
if not colorList:
from .plotter import colorList
popColorsTemp = {popLabel: colorList[ipop % len(colorList)] for ipop, popLabel in enumerate(popLabels)}
if popColors:
popColorsTemp.update(popColors)
popColors = popColorsTemp

# Create a list to link cell indices to their populations
indPop = []
for popLabel, popNumCell in zip(popLabels, popNumCells):
indPop.extend(int(popNumCell) * [popLabel])

# Create a dictionary to link cells to their population color
cellInds = list(set(spkInds))
indColors = {cellInd: popColors[indPop[int(cellInd)]] for cellInd in cellInds}

# Create a list of spkColors to be fed into the scatter plot
spkColors = [indColors[spkInd] for spkGid, spkInd in zip(spkGids, spkInds)]

# Set the time range appropriately
if 'timeRange' in kwargs:
timeRange = kwargs['timeRange']
elif 'timeRange' in rasterData:
timeRange = rasterData['timeRange']
else:
import numpy as np
timeRange = [0, np.ceil(max(spkTimes))]

# Set features for raster plot colored by phase
Expand All @@ -325,6 +312,33 @@ def plotRaster(
if 'pop_background' in colorbyPhase:
if colorbyPhase['pop_background'] == True:
kwargs['background'] = {'popLabels': popLabels, 'popNumCells': popNumCells, 'timeRange': timeRange}
else:
# Create a dictionary with the color for each pop
if not colorList:
from .plotter import colorList
popColorsTemp = {popLabel: colorList[ipop % len(colorList)] for ipop, popLabel in enumerate(popLabels)}
if popColors:
popColorsTemp.update(popColors)
popColors = popColorsTemp

if orderBy == 'gid':
# Create a list to link cell indices to their populations
indPop = []
for popLabel, popNumCell in zip(popLabels, popNumCells):
indPop.extend(int(popNumCell) * [popLabel])

def color(_, ind):
return popColors[indPop[int(ind)]]
else:
popByGid = {gid: pop for (gid, pop) in popsOfCellsByGid}
def color(gid, _):
pop = popByGid.get(gid)
if not pop:
return [.0, .0, .0] # default to black
return popColors.get(pop)

# Create a list of spkColors to be fed into the scatter plot
spkColors = [color(gid, ind) for gid, ind in zip(spkGids, spkInds)]

# Create a dictionary with the inputs for a scatter plot
scatterData = {}
Expand Down
2 changes: 1 addition & 1 deletion netpyne/specs/netParams.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,5 +846,5 @@ def setNestedParam(self, paramLabel, paramVal):
def setCfgMapping(self, cfg):
if hasattr(self, 'mapping'):
for k, v in self.mapping.items():
if getattr(cfg, k, None):
if hasattr(cfg, k):
self.setNestedParam(v, getattr(cfg, k))
15 changes: 7 additions & 8 deletions netpyne/tutorials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ We don't want to affect your system in any way, so we will operate from a virtua

You can open a terminal and enter the following at the prompt:

mkdir netpyne_tuts && cd netpyne_tuts && export PATH=/bin:/usr/bin && python3 -m venv env && source env/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install --upgrade ipython && python3 -m pip install --upgrade ipykernel && python3 -m pip install --upgrade jupyter && ipython kernel install --user --name=env && python3 -m pip install --upgrade neuron && git clone https://github.com/Neurosim-lab/netpyne.git && python3 -m pip install -e netpyne && cp -r netpyne/netpyne/tutorials . && cd tutorials && jupyter notebook
mkdir netpyne_tuts && cd netpyne_tuts && export PATH=/bin:/usr/bin && python3 -m venv env && source env/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install --upgrade ipython && python3 -m pip install --upgrade ipykernel && python3 -m pip install --upgrade jupyter && ipython kernel install --user --name=env && python3 -m pip install --upgrade neuron && git clone --depth 1 https://github.com/suny-downstate-medical-center/netpyne.git && python3 -m pip install -e netpyne && cp -r netpyne/netpyne/tutorials . && cd tutorials && jupyter notebook

## Installation option two

You can execute **netpyne_tut0.py** by opening a terminal and entering:
You can execute **install_tuts.py** by downloading it, opening a terminal and entering:

python3 netpyne_tut0.py
python3 install_tuts.py

## Installation option three

You can execute **netpyne_tut0.sh** by opening a terminal and entering:
You can execute **install_tuts.sh** by downloading it, opening a terminal and entering:

chmod u+x netpyne_tut0.sh
./netpyne_tut0.sh
sh install_tuts.sh

## Installation summary

Expand All @@ -31,15 +30,15 @@ Either of these options will do the same thing. They will:
- Activate (enter) the virtual environment
- Upgrade pip and install necessary packages
- Create a Jupyter kernel out of **env**
- Clone the NetPyNE GitHub repository
- Clone the NetPyNE GitHub repository (using shallow cloning)
- Install NetPyNE using pip
- Copy the NetPyNE **tutorials** directory into **netpyne_tuts**
- Change into the **tutorials** directory
- Start Jupyter Notebook

## Future use

This installation step only needs to be performed once. To re-enter the virtual environment in the future, change to the **netpyne_tuts** directory and execute the following:
This installation step only needs to be performed once. To re-enter the virtual environment in the future, change to the **netpyne_tuts** directory and execute the following:

source env/bin/activate
jupyter notebook
Loading

0 comments on commit 43d1731

Please sign in to comment.