Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to logging #623

Open
wants to merge 17 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion netpyne/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .tools import getInclude, plotData, saveData, loadData
from .utils import exception, _showFigure, _saveFigData, getCellsInclude, getCellsIncludeTags, _roundFigures, _smooth1d, syncMeasure, invertDictMapping, checkAvailablePlots

from netpyne.logger import logger
# Import connectivity-related functions
from .network import plotConn, _plotConnCalculateFromSim, _plotConnCalculateFromFile, plot2Dnet, plotShape, calculateDisynaptic, plot2Dfiring

Expand All @@ -33,7 +34,7 @@
try:
from .interactive import iplotDipole, iplotDipoleSpectrogram, iplotDipolePSD, iplotRaster, iplotSpikeHist, iplotRatePSD, iplotTraces, iplotLFP, iplotConn, iplotRxDConcentration, iplot2Dnet, iplotSpikeStats
except:
print('Warning: could not import interactive plotting functions; make sure the "bokeh" package is installed.')
logger.warning('Could not import interactive plotting functions; make sure the "bokeh" package is installed.')

# Import CSD-related functions
from .csd import getCSD, plotCSD
29 changes: 14 additions & 15 deletions netpyne/analysis/csd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"""

from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals
from __future__ import absolute_import
Expand Down Expand Up @@ -31,7 +30,7 @@
from scipy.signal import cheb2ord, cheby2, convolve, get_window, iirfilter, remez, decimate
from .filter import lowpass,bandpass
from .utils import exception, _saveFigData

from netpyne.logger import logger

def getbandpass(lfps, sampr, minf=0.05, maxf=300):
"""
Expand Down Expand Up @@ -320,7 +319,7 @@ def getCSD(LFP_input_data=None, LFP_input_file=None, sampr=None, dt=None, spacin
sim.allSimData['CSD']['CSD_data'] = CSD_data
sim.allSimData['CSD']['CSD_data_noBandpass'] = CSD_data_noBandpass
except:
print('NOTE: No sim.allSimData construct available to store CSD data.')
logger.warning('No sim.allSimData construct available to store CSD data.')

# return CSD_data or all data
if getAllData is True:
Expand Down Expand Up @@ -400,8 +399,8 @@ def plotCSD(CSD_data=None, LFP_input_data=None, overlay=None, timeRange=None, sa

"""

print('Plotting CSD... ')
logger.info('Plotting CSD...')

# DEFAULT -- CONDITION 1 : GET CSD DATA FROM SIM
if CSD_data is None:

Expand Down Expand Up @@ -439,24 +438,24 @@ def plotCSD(CSD_data=None, LFP_input_data=None, overlay=None, timeRange=None, sa
# CONDITION 2 : ARBITRARY CSD DATA
elif CSD_data is not None:
if timeRange is None:
print('MUST PROVIDE TIME RANGE in ms')
logger.warning('Must provide time range in in ms')
else:
print('timeRange = ' + str(timeRange))
logger.info('timeRange = ' + str(timeRange))

if dt is None:
print('MUST PROVIDE dt in ms')
logger.warning('Must provide dt in ms')
else:
print('dt = ' + str(dt)) # batch0['simConfig']['recordStep']
logger.info('dt = ' + str(dt)) # batch0['simConfig']['recordStep']

if spacing_um is None:
print('MUST PROVIDE SPACING BETWEEN ELECTRODES in MICRONS')
logger.warning('Must provide spacing between electrodes in microns')
else:
print('spacing_um = ' + str(spacing_um))
logger.info('spacing_um = ' + str(spacing_um))

if ymax is None:
print('MUST PROVIDE YMAX (MAX DEPTH) in MICRONS')
logger.warning('Must provide ymax (max depth) in microns')
else:
print('ymax = ' + str(ymax))
logger.info('ymax = ' + str(ymax))

tt = np.arange(timeRange[0], timeRange[1], dt)
LFP_data = np.array(LFP_input_data)[int(timeRange[0]/dt):int(timeRange[1]/dt),:]
Expand Down Expand Up @@ -538,7 +537,7 @@ def plotCSD(CSD_data=None, LFP_input_data=None, overlay=None, timeRange=None, sa
subaxs[chan].plot(X, LFP_data[:,chan], color='gray', linewidth=0.3)

else:
print('No data being overlaid')
logger.info('No data being overlaid')
axs[0].set_title('Current Source Density (CSD)', fontsize=fontSize)


Expand All @@ -550,7 +549,7 @@ def plotCSD(CSD_data=None, LFP_input_data=None, overlay=None, timeRange=None, sa

if layer_lines:
if layer_bounds is None:
print('No layer boundaries given')
logger.info('No layer boundaries given')
else:
layerKeys = []
for i in layer_bounds.keys():
Expand Down
1 change: 0 additions & 1 deletion netpyne/analysis/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

"""

from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals
from __future__ import absolute_import
Expand Down
11 changes: 5 additions & 6 deletions netpyne/analysis/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"""

from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals
from __future__ import absolute_import
Expand All @@ -22,7 +21,7 @@
import matplotlib.pyplot as plt
import numpy as np
from .utils import exception, _saveFigData, _showFigure, getCellsInclude

from netpyne.logger import logger

# -------------------------------------------------------------------------------------------------------------------
## Calculate normalized transfer entropy
Expand Down Expand Up @@ -102,13 +101,13 @@ def nTE(cells1=[], cells2=[], spks1=None, spks2=None, timeRange=None, binSize=20

if 'nte' not in dir(h):
try:
print(' Warning: support/nte.mod not compiled; attempting to compile from %s via "nrnivmodl support"'%(root))
logger.warning('support/nte.mod not compiled; attempting to compile from %s via "nrnivmodl support"'%(root))
os.system('cd ' + root + '; nrnivmodl support')
from neuron import load_mechanisms
load_mechanisms(root)
print(' Compilation of support folder mod files successful')
logger.info('Compilation of support folder mod files successful')
except:
print(' Error compiling support folder mod files')
logger.warning('Error compiling support folder mod files')
return

h.load_file(root+'/support/nte.hoc') # nTE code (also requires support/net.mod)
Expand Down Expand Up @@ -376,7 +375,7 @@ def plotGranger(cells1=None, cells2=None, spks1=None, spks2=None, label1=None, l
try:
from statsmodels.tsa.stattools import grangercausalitytests as gt
except:
print('To test Granger results please install the statsmodel package: "pip install statsmodel"')
logger.warning('To test Granger results please install the statsmodel package: "pip install statsmodel"')
exit()

tests = gt(np.array([histoCount1, histoCount2]).T, maxlag=10)
Expand Down
46 changes: 22 additions & 24 deletions netpyne/analysis/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

Expand Down Expand Up @@ -32,6 +31,7 @@
from bokeh.palettes import Viridis256
from bokeh.models import HoverTool

from netpyne.logger import logger

def applyTheme(kwargs):
theme = None
Expand Down Expand Up @@ -171,7 +171,7 @@ def iplotRaster(include=['allCells'], timeRange=None, maxSpikes=1e8, orderBy='gi
from bokeh.colors import RGB
from bokeh.models.annotations import Title

print('Plotting interactive raster ...')
logger.info('Plotting interactive raster...')

theme = applyTheme(kwargs)

Expand Down Expand Up @@ -218,7 +218,7 @@ def iplotRaster(include=['allCells'], timeRange=None, maxSpikes=1e8, orderBy='gi
sel, spkts, spkgids = getSpktSpkid(cellGids=[] if include == ['allCells'] else cellGids, timeRange=timeRange)
except:
import sys
print((sys.exc_info()))
logger.warning(sys.exc_info())
spkgids, spkts = [], []
sel = pd.DataFrame(columns=['spkt', 'spkid'])
sel['spkgidColor'] = sel['spkid'].map(gidColors)
Expand Down Expand Up @@ -252,14 +252,13 @@ def iplotRaster(include=['allCells'], timeRange=None, maxSpikes=1e8, orderBy='gi
numNetStims += 1
else:
pass
#print netStimLabel+' produced no spikes'
if len(cellGids)>0 and numNetStims:
ylabelText = ylabelText + ' and NetStims (at the end)'
elif numNetStims:
ylabelText = ylabelText + 'NetStims'

if numCellSpks+numNetStims == 0:
print('No spikes available to plot raster')
logger.warning('No spikes available to plot raster')
return None

# Time Range
Expand All @@ -272,7 +271,7 @@ def iplotRaster(include=['allCells'], timeRange=None, maxSpikes=1e8, orderBy='gi

# Limit to max spikes
if (len(sel)>maxSpikes):
print((' Showing only the first %i out of %i spikes' % (maxSpikes, len(sel)))) # Limit num of spikes
logger.info(' Showing only the first %i out of %i spikes' % (maxSpikes, len(sel))) # Limit num of spikes
if numNetStims: # sort first if have netStims
sel = sel.sort_values(by='spkt')
sel = sel.iloc[:maxSpikes]
Expand Down Expand Up @@ -321,7 +320,6 @@ def iplotRaster(include=['allCells'], timeRange=None, maxSpikes=1e8, orderBy='gi
if syncLines:
for spkt in sel['spkt'].tolist():
fig.line((spkt, spkt), (0, len(cells)+numNetStims), color='red', line_width=2)
print(syncMeasure())
t.text = 'cells=%i syns/cell=%0.1f rate=%0.1f Hz sync=%0.2f' % (numCells,connsPerCell,firingRate,syncMeasure())
else:
t.text = 'cells=%i syns/cell=%0.1f rate=%0.1f Hz' % (numCells,connsPerCell,firingRate)
Expand Down Expand Up @@ -967,7 +965,7 @@ def iplotSpikeHist(include = ['allCells', 'eachPop'], legendLabels = [], timeRan
from bokeh.models import Legend
from bokeh.colors import RGB

print('Plotting interactive spike histogram...')
logger.info('Plotting interactive spike histogram...')

theme = applyTheme(kwargs)

Expand Down Expand Up @@ -1085,7 +1083,7 @@ def iplotSpikeHist(include = ['allCells', 'eachPop'], legendLabels = [], timeRan
fig.legend.click_policy='hide'
fig.legend.location='top_right'

print(figs)
logger.info(figs)
plot_layout = gridplot(figs, ncols=1, merge_tools=False, sizing_mode='stretch_both')
html = file_html(plot_layout, CDN, title="Spike Histogram", theme=theme)

Expand Down Expand Up @@ -1191,7 +1189,7 @@ def iplotRatePSD(include=['allCells', 'eachPop'], timeRange=None, binSize=5, max
from bokeh.colors import RGB
from bokeh.models import Legend

print('Plotting interactive firing rate power spectral density (PSD) ...')
logger.info('Plotting interactive firing rate power spectral density (PSD) ...')

theme = applyTheme(kwargs)

Expand Down Expand Up @@ -1407,7 +1405,7 @@ def iplotTraces(include=None, timeRange=None, overlay=False, oneFigPer='cell', r
from bokeh.models import Legend
from bokeh.colors import RGB

print('Plotting interactive recorded cell traces per', oneFigPer)
logger.info('Plotting interactive recorded cell traces per ' + oneFigPer)

theme = applyTheme(kwargs)

Expand Down Expand Up @@ -1736,7 +1734,7 @@ def iplotLFP(electrodes=['avg', 'all'], plots=['timeSeries', 'PSD', 'spectrogram
from bokeh.layouts import layout, column, row
from bokeh.colors import RGB

print('Plotting interactive LFP ...')
logger.info('Plotting interactive LFP ...')

html = None
theme = applyTheme(kwargs)
Expand Down Expand Up @@ -2137,7 +2135,7 @@ def iplotConn(includePre=['all'], includePost=['all'], feature='strength', order
from bokeh.layouts import layout
from bokeh.colors import RGB

print('Plotting interactive connectivity matrix...')
logger.info('Plotting interactive connectivity matrix...')

theme = applyTheme(kwargs)

Expand All @@ -2148,7 +2146,7 @@ def iplotConn(includePre=['all'], includePost=['all'], feature='strength', order


if connMatrix is None:
print(" Error calculating connMatrix in iplotConn()")
logger.info(" Error calculating connMatrix in iplotConn()")
return None

# TODO: set plot font size in Bokeh
Expand Down Expand Up @@ -2253,11 +2251,11 @@ def iplotConn(includePre=['all'], includePost=['all'], feature='strength', order
fig.yaxis.axis_label = feature

elif groupBy == 'cell':
print(' Error: plotConn graphType="bar" with groupBy="cell" not yet implemented')
logger.warning(' Error: plotConn graphType="bar" with groupBy="cell" not yet implemented')
return None

elif graphType == 'pie':
print(' Error: plotConn graphType="pie" not yet implemented')
logger.warning(' Error: plotConn graphType="pie" not yet implemented')
return None

plot_layout = layout([fig], sizing_mode='stretch_both')
Expand Down Expand Up @@ -2375,7 +2373,7 @@ def iplot2Dnet(include=['allCells'], view='xy', showConns=True, popColors=None,
from bokeh.colors import RGB
from bokeh.models.annotations import Title

print('Plotting interactive 2D representation of network cell locations and connections...')
logger.info('Plotting interactive 2D representation of network cell locations and connections...')

theme = applyTheme(kwargs)

Expand All @@ -2393,7 +2391,7 @@ def iplot2Dnet(include=['allCells'], view='xy', showConns=True, popColors=None,
ycoord = 'z'

if tagsFile:
print('Loading tags file...')
logger.info('Loading tags file...')
import json
with open(tagsFile, 'r') as fileObj: tagsTmp = json.load(fileObj)['tags']
tagsFormat = tagsTmp.pop('format', [])
Expand All @@ -2407,8 +2405,8 @@ def iplot2Dnet(include=['allCells'], view='xy', showConns=True, popColors=None,
yIndex = tagsFormat.index('y') if 'y' in tagsFormat else missing.append('y')
zIndex = tagsFormat.index('z') if 'z' in tagsFormat else missing.append('z')
if len(missing) > 0:
print("Missing:")
print(missing)
logger.info("Missing:")
logger.info(missing)
return None, None, None

# find pre and post cells
Expand All @@ -2429,7 +2427,7 @@ def iplot2Dnet(include=['allCells'], view='xy', showConns=True, popColors=None,
elif ycoord == 'z':
posY = [tags[gid][zIndex] for gid in cellGids] # get all y positions
else:
print('Error loading tags from file')
logger.warning('Error loading tags from file')
return None

else:
Expand Down Expand Up @@ -2580,7 +2578,7 @@ def iplotRxDConcentration(speciesLabel, regionLabel, plane='xy', saveFig=None, s
from bokeh.transform import linear_cmap
from bokeh.models import ColorBar

print('Plotting interactive RxD concentration ...')
logger.info('Plotting interactive RxD concentration ...')

theme = applyTheme(kwargs)

Expand Down Expand Up @@ -2790,7 +2788,7 @@ def iplotSpikeStats(include=['eachPop', 'allCells'], statDataIn={}, timeRange=No
from bokeh.palettes import Spectral6
from bokeh.models.mappers import CategoricalColorMapper

print('Plotting interactive spike statistics ...')
logger.info('Plotting interactive spike statistics ...')

TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"

Expand Down Expand Up @@ -2887,7 +2885,7 @@ def iplotSpikeStats(include=['eachPop', 'allCells'], statDataIn={}, timeRange=No
try:
import pyspike
except:
print("Error: plotSpikeStats() requires the PySpike python package \
logger.warning("Error: plotSpikeStats() requires the PySpike python package \
to calculate synchrony (try: pip install pyspike)")
return 0

Expand Down
Loading