Skip to content

Commit

Permalink
Merge pull request #431 from NeuroML/feat-timeseries-tweaks
Browse files Browse the repository at this point in the history
Time series plotting tweaks
  • Loading branch information
sanjayankur31 authored Oct 23, 2024
2 parents b7b8104 + 188e80e commit 581d1a4
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 29 deletions.
2 changes: 1 addition & 1 deletion man/man1/pynml-archive.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-ARCHIVE "1" "September 2024" "pynml-archive v1.3.13" "User Commands"
.TH PYNML-ARCHIVE "1" "October 2024" "pynml-archive v1.3.13" "User Commands"
.SH NAME
pynml-archive \- manual page for pynml-archive v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-channelanalysis.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-CHANNELANALYSIS "1" "September 2024" "pynml-channelanalysis v1.3.13" "User Commands"
.TH PYNML-CHANNELANALYSIS "1" "October 2024" "pynml-channelanalysis v1.3.13" "User Commands"
.SH NAME
pynml-channelanalysis \- manual page for pynml-channelanalysis v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-channelml2nml.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-CHANNELML2NML "1" "September 2024" "pynml-channelml2nml v1.3.13" "User Commands"
.TH PYNML-CHANNELML2NML "1" "October 2024" "pynml-channelml2nml v1.3.13" "User Commands"
.SH NAME
pynml-channelml2nml \- manual page for pynml-channelml2nml v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-modchananalysis.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-MODCHANANALYSIS "1" "September 2024" "pynml-modchananalysis v1.3.13" "User Commands"
.TH PYNML-MODCHANANALYSIS "1" "October 2024" "pynml-modchananalysis v1.3.13" "User Commands"
.SH NAME
pynml-modchananalysis \- manual page for pynml-modchananalysis v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-plotchan.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-PLOTCHAN "1" "September 2024" "pynml-plotchan v1.3.13" "User Commands"
.TH PYNML-PLOTCHAN "1" "October 2024" "pynml-plotchan v1.3.13" "User Commands"
.SH NAME
pynml-plotchan \- manual page for pynml-plotchan v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-plotmorph.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-PLOTMORPH "1" "September 2024" "pynml-plotmorph v1.3.13" "User Commands"
.TH PYNML-PLOTMORPH "1" "October 2024" "pynml-plotmorph v1.3.13" "User Commands"
.SH NAME
pynml-plotmorph \- manual page for pynml-plotmorph v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-plotspikes.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-PLOTSPIKES "1" "September 2024" "pynml-plotspikes v1.3.13" "User Commands"
.TH PYNML-PLOTSPIKES "1" "October 2024" "pynml-plotspikes v1.3.13" "User Commands"
.SH NAME
pynml-plotspikes \- manual page for pynml-plotspikes v1.3.13
.SH DESCRIPTION
Expand Down
17 changes: 13 additions & 4 deletions man/man1/pynml-plottimeseries.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-PLOTTIMESERIES "1" "September 2024" "pynml-plottimeseries v1.3.13" "User Commands"
.TH PYNML-PLOTTIMESERIES "1" "October 2024" "pynml-plottimeseries v1.3.13" "User Commands"
.SH NAME
pynml-plottimeseries \- manual page for pynml-plottimeseries v1.3.13
.SH DESCRIPTION
usage: pynml\-plottimeseries [\-h] [\-offset] [\-saveToFile <Image file name>]
.IP
usage: pynml\-plottimeseries [\-h] [\-columns [<column indices to plot> ...]]
.TP
[\-labels] [\-offset]
[\-saveToFile <Image file name>]
<a LEMS file or data files>
[<a LEMS file or data files> ...]
.PP
A script to plot time series data from data files or LEMS files
Expand All @@ -18,8 +21,14 @@ series from
\fB\-h\fR, \fB\-\-help\fR
show this help message and exit
.TP
\fB\-columns\fR [<column indices to plot> ...]
column indices to plot if data files are provided
.TP
\fB\-labels\fR
Label plots
.TP
\fB\-offset\fR
Toggle whether plots are overlaid or offset
Offset plots
.TP
\fB\-saveToFile\fR <Image file name>
Name of the image file to save plot to
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-povray.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-POVRAY "1" "September 2024" "pynml-povray v1.3.13" "User Commands"
.TH PYNML-POVRAY "1" "October 2024" "pynml-povray v1.3.13" "User Commands"
.SH NAME
pynml-povray \- manual page for pynml-povray v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-sonata.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-SONATA "1" "September 2024" "pynml-sonata v1.3.13" "User Commands"
.TH PYNML-SONATA "1" "October 2024" "pynml-sonata v1.3.13" "User Commands"
.SH NAME
pynml-sonata \- manual page for pynml-sonata v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-summary.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-SUMMARY "1" "September 2024" "pynml-summary v1.3.13" "User Commands"
.TH PYNML-SUMMARY "1" "October 2024" "pynml-summary v1.3.13" "User Commands"
.SH NAME
pynml-summary \- manual page for pynml-summary v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-swc2nml.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-SWC2NML "1" "September 2024" "pynml-swc2nml v1.3.13" "User Commands"
.TH PYNML-SWC2NML "1" "October 2024" "pynml-swc2nml v1.3.13" "User Commands"
.SH NAME
pynml-swc2nml \- manual page for pynml-swc2nml v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-tune.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-TUNE "1" "September 2024" "pynml-tune v1.3.13" "User Commands"
.TH PYNML-TUNE "1" "October 2024" "pynml-tune v1.3.13" "User Commands"
.SH NAME
pynml-tune \- manual page for pynml-tune v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml-xpp.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML-XPP "1" "September 2024" "pynml-xpp v1.3.13" "User Commands"
.TH PYNML-XPP "1" "October 2024" "pynml-xpp v1.3.13" "User Commands"
.SH NAME
pynml-xpp \- manual page for pynml-xpp v1.3.13
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/man1/pynml.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH PYNML "1" "September 2024" "pynml v1.3.13" "User Commands"
.TH PYNML "1" "October 2024" "pynml v1.3.13" "User Commands"
.SH NAME
pynml \- manual page for pynml v1.3.13
.SH DESCRIPTION
Expand Down
60 changes: 49 additions & 11 deletions pyneuroml/plot/PlotTimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
logger.setLevel(logging.WARNING)


TIME_SERIES_PLOTTER_DEFAULTS = {"offset": False}
TIME_SERIES_PLOTTER_DEFAULTS = {
"offset": False,
"labels": False,
}


def plot_time_series(
Expand Down Expand Up @@ -143,13 +146,15 @@ def plot_time_series(
else:
show_yticklabels = True

# if a scalebar is to be set, we need to wait for it to be added before
# showing the plot
ax = pynmlplt.generate_plot(
xvalues=xs,
yvalues=ys,
title=title,
labels=labelvals,
show_yticklabels=show_yticklabels,
show_plot_already=False,
show_plot_already=False if scalebar_location is not None else True,
**kwargs_generate_plot,
)

Expand All @@ -170,12 +175,16 @@ def plot_time_series(
print(f"Note: length of the scalebar is {scalebar_length} units")
ax.add_artist(scalebar_)

if show_plot_already is True:
plt.show()
if show_plot_already is True:
plt.show()


def plot_time_series_from_lems_file(
lems_file_name: str, base_dir: str = ".", title: str = "", **kwargs
lems_file_name: str,
base_dir: str = ".",
title: str = "",
labels: bool = True,
**kwargs,
) -> None:
"""Plot time series from a LEMS file.
Expand All @@ -193,6 +202,8 @@ def plot_time_series_from_lems_file(
:type lems_file_name: str
:param base_dir: directory where LEMS file resides
:type base_dir: str
:param labels: toggle whether plots should be labelled
:type labels: bool
:param kwargs: other arguments passed to `plot_time_series`
:returns: None
Expand All @@ -201,11 +212,14 @@ def plot_time_series_from_lems_file(
lems_file_name, get_events=False, get_traces=True
)

plot_time_series(traces, xaxis="Time (s)", **kwargs)
plot_time_series(traces, labels=labels, xaxis="Time (s)", **kwargs)


def plot_time_series_from_data_files(
data_file_names: typing.Union[str, typing.List[str]], **kwargs
data_file_names: typing.Union[str, typing.List[str]],
labels: bool = True,
columns: typing.Optional[typing.List[int]] = None,
**kwargs,
):
"""Plot time series from a data file.
Expand All @@ -215,6 +229,10 @@ def plot_time_series_from_data_files(
:param data_file_names: name/path to data file(s)
:type data_file_names: str or list of strings
:param labels: toggle whether plots should be labelled
:type labels: bool
:param columns: column indices to plot
:type columns: list of ints: [1, 2, 3]
:param kwargs: other key word arguments that are passed to the
`plot_time_series` function
Expand All @@ -230,10 +248,14 @@ def plot_time_series_from_data_files(
traces["t"] = data_array[:, 0]
num_cols = numpy.shape(data_array)[1]
for i in range(1, num_cols, 1):
traces[str(i)] = data_array[:, i]
if columns and len(columns) > 0:
if i not in columns:
logger.warning(f"Skipping column {i}")
continue
traces[f"{f}_{i}"] = data_array[:, i]
all_traces.append(traces)

plot_time_series(all_traces, labels=False, **kwargs)
plot_time_series(all_traces, labels=labels, **kwargs)


def _process_time_series_plotter_args():
Expand All @@ -248,15 +270,28 @@ def _process_time_series_plotter_args():
"input_files",
type=str,
metavar="<a LEMS file or data files>",
nargs="*",
nargs="+",
help="a LEMS file (LEMS_..) or data files to plot time series from",
)

parser.add_argument(
"-columns",
type=int,
metavar="<column indices to plot>",
nargs="*",
help="column indices to plot if data files are provided",
)
parser.add_argument(
"-labels",
action="store_true",
default=TIME_SERIES_PLOTTER_DEFAULTS["labels"],
help=("Label plots"),
)
parser.add_argument(
"-offset",
action="store_true",
default=TIME_SERIES_PLOTTER_DEFAULTS["offset"],
help=("Toggle whether plots are overlaid or offset"),
help=("Offset plots"),
)
parser.add_argument(
"-saveToFile",
Expand All @@ -280,13 +315,16 @@ def _time_series_plotter_main(args=None):
plot_time_series_from_lems_file(
a.input_files[0],
offset=a.offset,
labels=a.labels,
bottom_left_spines_only=True,
save_figure_to=a.save_to_file,
)
else:
plot_time_series_from_data_files(
a.input_files,
columns=a.columns,
offset=a.offset,
labels=a.labels,
bottom_left_spines_only=True,
save_figure_to=a.save_to_file,
)

0 comments on commit 581d1a4

Please sign in to comment.