Skip to content

Commit

Permalink
Adding some options for changing labels on axes
Browse files Browse the repository at this point in the history
Fix issue with use of relative path in reload_saved_data()
Update to v0.3.3
  • Loading branch information
pgleeson committed Nov 6, 2017
1 parent eb0c806 commit 93e216d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ examples/results/*.dat
/examples/NML2_SingleCompHHCell.png
/examples/quick.png
/examples/test_data/HHCellNetwork.net.nml_channeldens.svg
/quick.png
2 changes: 1 addition & 1 deletion pyneuroml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


__version__ = '0.3.2'
__version__ = '0.3.3'

JNEUROML_VERSION = '0.8.3'
56 changes: 41 additions & 15 deletions pyneuroml/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ def generate_current_vs_frequency_curve(nml2_file,
ylim_if = None,
xlim_iv = None,
ylim_iv = None,
label_xaxis = True,
label_yaxis = True,
show_volts_label = True,
grid = True,
font_size = 12,
if_iv_color = 'k',
linewidth = 1,
bottom_left_spines_only = False,
show_plot_already = True,
save_voltage_traces_to = None,
Expand Down Expand Up @@ -71,7 +76,7 @@ def generate_current_vs_frequency_curve(nml2_file,
stims.append(amp)
amp+=step_nA

stim_info = '(%snA->%snA; %s steps of %snA)'%(start_amp_nA, end_amp_nA, len(stims), step_nA)
stim_info = '(%snA->%snA; %s steps of %snA; %sms)'%(start_amp_nA, end_amp_nA, len(stims), step_nA, total_duration)

print_comment_v("Generating an IF curve for cell %s in %s using %s %s"%
(cell_id, nml2_file, simulator, stim_info))
Expand Down Expand Up @@ -202,13 +207,14 @@ def generate_current_vs_frequency_curve(nml2_file,
traces_ax = pynml.generate_plot(times_results,
volts_results,
"Membrane potential traces for: %s"%nml2_file,
xaxis = 'Time (ms)',
yaxis = 'Membrane potential (mV)',
xaxis = 'Time (ms)' if label_xaxis else ' ',
yaxis = 'Membrane potential (mV)' if label_yaxis else '',
xlim = [total_duration*-0.05,total_duration*1.05],
show_xticklabels = label_xaxis,
font_size = font_size,
bottom_left_spines_only = bottom_left_spines_only,
grid = False,
labels = volts_labels,
labels = volts_labels if show_volts_label else [],
show_plot_already=False,
save_figure_to = save_voltage_traces_to,
title_above_plot = title_above_plot,
Expand All @@ -221,17 +227,20 @@ def generate_current_vs_frequency_curve(nml2_file,
stims_pA = [ii*1000 for ii in stims]

freqs = [if_results[s] for s in stims]

if_ax = pynml.generate_plot([stims_pA],
[freqs],
"Firing frequency versus injected current for: %s"%nml2_file,
colors = ['k'],
colors = [if_iv_color],
linestyles=['-'],
markers=['o'],
xaxis = 'Input current (pA)',
yaxis = 'Firing frequency (Hz)',
linewidths = [linewidth],
xaxis = 'Input current (pA)' if label_xaxis else ' ',
yaxis = 'Firing frequency (Hz)' if label_yaxis else '',
xlim = xlim_if,
ylim = ylim_if,
show_xticklabels = label_xaxis,
show_yticklabels = label_yaxis,
font_size = font_size,
bottom_left_spines_only = bottom_left_spines_only,
grid = grid,
Expand All @@ -249,18 +258,35 @@ def generate_current_vs_frequency_curve(nml2_file,
stims = sorted(iv_results.keys())
stims_pA = [ii*1000 for ii in sorted(iv_results.keys())]
vs = [iv_results[s] for s in stims]

xs = []
ys = []
xs.append([])
ys.append([])

for si in range(len(stims)):
stim = stims[si]
if len(custom_amps_nA)==0 and si>1 and (stims[si]-stims[si-1])>step_nA*1.01:
xs.append([])
ys.append([])

xs[-1].append(stim*1000)
ys[-1].append(iv_results[stim])

iv_ax = pynml.generate_plot([stims_pA],
[vs],
iv_ax = pynml.generate_plot(xs,
ys,
"V at %sms versus I below threshold for: %s"%(end_stim,nml2_file),
colors = ['k'],
linestyles=['-'],
markers=['o'],
xaxis = 'Input current (pA)',
yaxis = 'Membrane potential (mV)',
colors = [if_iv_color for s in xs],
linestyles=['-' for s in xs],
markers=['o' for s in xs],
xaxis = 'Input current (pA)' if label_xaxis else '',
yaxis = 'Membrane potential (mV)' if label_yaxis else '',
xlim = xlim_iv,
ylim = ylim_iv,
show_xticklabels = label_xaxis,
show_yticklabels = label_yaxis,
font_size = font_size,
linewidths = [linewidth for s in xs],
bottom_left_spines_only = bottom_left_spines_only,
grid = grid,
show_plot_already=False,
Expand Down
20 changes: 18 additions & 2 deletions pyneuroml/pynml.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ def reload_saved_data(lems_file_name,
verbose = DEFAULTS['v'],
remove_dat_files_after_load = False):

print_comment("Reloading data specified in LEMS file: %s, base_dir: %s" \
% (lems_file_name,base_dir), verbose)
print_comment("Reloading data specified in LEMS file: %s, base_dir: %s, cwd: %s" \
% (lems_file_name,base_dir,os.getcwd()), True)

# Could use pylems to parse all this...
traces = {}
Expand All @@ -686,6 +686,7 @@ def reload_saved_data(lems_file_name,
import matplotlib.pyplot as plt

from lxml import etree
base_lems_file_path = os.path.dirname(os.path.realpath(lems_file_name))
tree = etree.parse(lems_file_name)

sim = tree.getroot().find('Simulation')
Expand All @@ -706,6 +707,9 @@ def reload_saved_data(lems_file_name,
for i,of in enumerate(event_output_files):
name = of.attrib['fileName']
file_name = os.path.join(base_dir,name)
if not os.path.isfile(file_name): # If not relative to the LEMS file...
file_name = os.path.join(base_lems_file_path,name)

#if not os.path.isfile(file_name): # If not relative to the LEMS file...
# file_name = os.path.join(os.getcwd(),name)
# ... try relative to cwd.
Expand Down Expand Up @@ -756,8 +760,13 @@ def reload_saved_data(lems_file_name,
traces['t'] = []
name = of.attrib['fileName']
file_name = os.path.join(base_dir,name)

if not os.path.isfile(file_name): # If not relative to the LEMS file...
file_name = os.path.join(base_lems_file_path,name)

if not os.path.isfile(file_name): # If not relative to the LEMS file...
file_name = os.path.join(os.getcwd(),name)

# ... try relative to cwd.
if not os.path.isfile(file_name): # If not relative to the LEMS file...
file_name = os.path.join(os.getcwd(),'NeuroML2','results',name)
Expand Down Expand Up @@ -1059,6 +1068,8 @@ def generate_plot(xvalues,
yaxis = None,
xlim = None,
ylim = None,
show_xticklabels = True,
show_yticklabels = True,
grid = False,
logx = False,
logy = False,
Expand Down Expand Up @@ -1102,6 +1113,11 @@ def generate_plot(xvalues,
ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')

if not show_xticklabels:
ax.set_xticklabels([])
if not show_yticklabels:
ax.set_yticklabels([])

for i in range(len(xvalues)):

Expand Down

0 comments on commit 93e216d

Please sign in to comment.