From f7a6fc8c469603305cec12e5e0f136c85c72e11d Mon Sep 17 00:00:00 2001 From: Brent Huisman <brenthuisman@users.noreply.github.com> Date: Mon, 16 Aug 2021 17:57:28 +0200 Subject: [PATCH] Update Python examples to work with latest Pandas+Seaborn (#1625) Latest Pandas versions required unique indices, breaking the plotting in the python examples. --- python/example/network_ring.py | 2 +- python/example/network_ring_mpi.py | 2 +- python/example/network_ring_mpi_plot.py | 4 ++-- python/example/single_cell_detailed.py | 6 +++--- python/example/single_cell_detailed_recipe.py | 5 +++-- python/example/single_cell_model.py | 6 ++---- python/example/single_cell_nml.py | 2 +- python/example/single_cell_recipe.py | 2 +- python/example/single_cell_swc.py | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/python/example/network_ring.py b/python/example/network_ring.py index c1c6a07b..46c6ada3 100755 --- a/python/example/network_ring.py +++ b/python/example/network_ring.py @@ -137,5 +137,5 @@ for gid in range(ncells): samples, meta = sim.samples(handles[gid])[0] df_list.append(pandas.DataFrame({'t/ms': samples[:, 0], 'U/mV': samples[:, 1], 'Cell': f"cell {gid}"})) -df = pandas.concat(df_list) +df = pandas.concat(df_list,ignore_index=True) seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Cell",ci=None).savefig('network_ring_result.svg') diff --git a/python/example/network_ring_mpi.py b/python/example/network_ring_mpi.py index 51bde9d4..52e88aec 100644 --- a/python/example/network_ring_mpi.py +++ b/python/example/network_ring_mpi.py @@ -143,5 +143,5 @@ for gid in range(ncells): df_list.append(pandas.DataFrame({'t/ms': samples[:, 0], 'U/mV': samples[:, 1], 'Cell': f"cell {gid}"})) if len(df_list): - df = pandas.concat(df_list) + df = pandas.concat(df_list,ignore_index=True) df.to_csv(f"result_mpi_{context.rank}.csv", float_format='%g') diff --git a/python/example/network_ring_mpi_plot.py b/python/example/network_ring_mpi_plot.py index c5ec346c..5f54baef 100644 --- a/python/example/network_ring_mpi_plot.py +++ b/python/example/network_ring_mpi_plot.py @@ -10,5 +10,5 @@ df_list = [] for result in results: df_list.append(pandas.read_csv(result)) -df = pandas.concat(df_list) -seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Cell",ci=None).savefig('mpi_result.svg') \ No newline at end of file +df = pandas.concat(df_list,ignore_index=True) +seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Cell",ci=None).savefig('mpi_result.svg') diff --git a/python/example/single_cell_detailed.py b/python/example/single_cell_detailed.py index b19627f9..0ff3af50 100755 --- a/python/example/single_cell_detailed.py +++ b/python/example/single_cell_detailed.py @@ -118,8 +118,8 @@ for s in model.spikes: # (10) Plot the voltages -df = pandas.DataFrame() +df_list = [] for t in model.traces: - df=df.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), 'Variable': t.variable})) - + df_list.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), 'Variable': t.variable})) +df = pandas.concat(df_list,ignore_index=True) seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_detailed_result.svg') diff --git a/python/example/single_cell_detailed_recipe.py b/python/example/single_cell_detailed_recipe.py index 281da877..d9275e8d 100644 --- a/python/example/single_cell_detailed_recipe.py +++ b/python/example/single_cell_detailed_recipe.py @@ -182,7 +182,8 @@ for d, m in sim.samples(handle): data.append(d) meta.append(m) -df = pandas.DataFrame() +df_list = [] for i in range(len(data)): - df = df.append(pandas.DataFrame({'t/ms': data[i][:, 0], 'U/mV': data[i][:, 1], 'Location': str(meta[i]), 'Variable':'voltage'})) + df_list.append(pandas.DataFrame({'t/ms': data[i][:, 0], 'U/mV': data[i][:, 1], 'Location': str(meta[i]), 'Variable':'voltage'})) +df = pandas.concat(df_list,ignore_index=True) seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_recipe_result.svg') diff --git a/python/example/single_cell_model.py b/python/example/single_cell_model.py index e8e461c4..a21445d3 100755 --- a/python/example/single_cell_model.py +++ b/python/example/single_cell_model.py @@ -4,8 +4,6 @@ import arbor import pandas, seaborn # You may have to pip install these. -print(arbor.__config__) - # (1) Create a morphology with a single (cylindrical) segment of length=diameter=6 μm tree = arbor.segment_tree() tree.append(arbor.mnpos, arbor.mpoint(-3, 0, 0, 3), arbor.mpoint(3, 0, 0, 3), tag=1) @@ -41,11 +39,11 @@ if len(m.spikes)>0: else: print('no spikes') -# (8) Plot the recorded voltages over time. +# (9) Plot the recorded voltages over time. print("Plotting results ...") seaborn.set_theme() # Apply some styling to the plot df = pandas.DataFrame({'t/ms': m.traces[0].time, 'U/mV': m.traces[0].value}) seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",ci=None).savefig('single_cell_model_result.svg') -# (9) Optionally, you can store your results for later processing. +# (10) Optionally, you can store your results for later processing. df.to_csv('single_cell_model_result.csv', float_format='%g') diff --git a/python/example/single_cell_nml.py b/python/example/single_cell_nml.py index 7c5920bc..d582b36b 100755 --- a/python/example/single_cell_nml.py +++ b/python/example/single_cell_nml.py @@ -103,6 +103,6 @@ df_list = [] for t in m.traces: df_list.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), "Variable": t.variable})) -df = pandas.concat(df_list) +df = pandas.concat(df_list,ignore_index=True) seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_nml.svg') diff --git a/python/example/single_cell_recipe.py b/python/example/single_cell_recipe.py index 01af5d46..193e258a 100644 --- a/python/example/single_cell_recipe.py +++ b/python/example/single_cell_recipe.py @@ -87,7 +87,7 @@ else: print('no spikes') print("Plotting results ...") -seaborn.set_theme() # Apply some styling to the plot + df = pandas.DataFrame({'t/ms': data[:, 0], 'U/mV': data[:, 1]}) seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV", ci=None).savefig('single_cell_recipe_result.svg') diff --git a/python/example/single_cell_swc.py b/python/example/single_cell_swc.py index 525d90e8..2090f16d 100755 --- a/python/example/single_cell_swc.py +++ b/python/example/single_cell_swc.py @@ -95,6 +95,6 @@ df_list = [] for t in m.traces: df_list.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), "Variable": t.variable})) -df = pandas.concat(df_list) +df = pandas.concat(df_list,ignore_index=True) seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_swc.svg') -- GitLab