Skip to content
Merged
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
Binary file modified docs/figures/example02/fig01_data_overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/figures/example02/fig02_lag_and_model_comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/figures/example03/fig05_stimulus_effect_surfaces.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 12 additions & 18 deletions examples/paper/example01_mepsc_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _maybe_export(fig, export_dir: Path | None, name: str, dpi: int = 250):
if export_dir is not None:
export_dir.mkdir(parents=True, exist_ok=True)
png_path = export_dir / f"{name}.png"
fig.savefig(png_path, dpi=dpi, bbox_inches="tight")
fig.savefig(png_path, dpi=dpi, facecolor="w", edgecolor="none")
saved.append(png_path)
print(f" Saved {png_path}")
return saved
Expand Down Expand Up @@ -149,8 +149,8 @@ def run_example01(*, export_figures: bool = False, export_dir: Path | None = Non
spikeCollConst.plot(handle=ax)
ax.set_title("Neural Raster with constant Mg$^{2+}$ Concentration",
fontweight="bold", fontsize=12)
ax.set_xlabel("time [s]", fontsize=12, fontweight="bold")
ax.set_ylabel("mEPSCs", fontsize=12, fontweight="bold")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_ylabel("mEPSCs", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_yticks([0, 1])

# (2,2,2): Inverse Gaussian transform (ACF)
Expand All @@ -165,13 +165,10 @@ def run_example01(*, export_figures: bool = False, export_dir: Path | None = Non
ax.plot(np.asarray(lam.time, dtype=float),
np.asarray(lam.data[:, 0], dtype=float),
"b", linewidth=2)
ax.set_xlabel("time [s]", fontsize=12, fontweight="bold")
ax.set_ylabel(lam.ylabel if hasattr(lam, "ylabel") else "spikes/sec",
fontsize=12, fontweight="bold")
ax.legend(["$\\lambda_{const}$"], loc="upper right")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_ylabel(r"$\lambda(t)$ [Hz]", fontname="Arial", fontsize=12, fontweight="bold")
ax.legend(["$\\lambda_{const}$"], loc="upper right", fontsize=14)

fig1.suptitle("Example 01 — Figure 1: Constant Mg$^{2+}$ Summary",
fontsize=14, fontweight="bold")
fig1.tight_layout()
figure_files.extend(_maybe_export(fig1, export_dir, "fig01_constant_mg_summary"))

Expand All @@ -194,18 +191,17 @@ def run_example01(*, export_figures: bool = False, export_dir: Path | None = Non
ax = axes2[0]
nstConst.plot(handle=ax)
ax.set_yticks([0, 1])
ax.set_ylabel("mEPSCs", fontsize=12, fontweight="bold")
ax.set_ylabel("mEPSCs", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_title("Neural Raster with constant Mg$^{2+}$ Concentration",
fontweight="bold", fontsize=12)

ax = axes2[1]
nstWashout.plot(handle=ax)
ax.set_yticks([0, 1])
ax.set_ylabel("mEPSCs", fontsize=12, fontweight="bold")
ax.set_ylabel("mEPSCs", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_title("Neural Raster with decreasing Mg$^{2+}$ Concentration",
fontweight="bold", fontsize=12)

fig2.suptitle("Example 01 — Figure 2: Constant vs Decreasing Mg$^{2+}$", fontsize=14, fontweight="bold")
fig2.tight_layout()
figure_files.extend(_maybe_export(fig2, export_dir, "fig02_washout_raster_overview"))

Expand Down Expand Up @@ -281,13 +277,11 @@ def run_example01(*, export_figures: bool = False, export_dir: Path | None = Non
if lam.data.shape[1] > 1:
ax.plot(t, np.asarray(lam.data[:, 1], dtype=float), "g", linewidth=2)
ax.set_ylim(0, 5)
ax.set_xlabel("time [s]", fontsize=12, fontweight="bold")
ax.set_ylabel(lam.ylabel if hasattr(lam, "ylabel") else "spikes/sec",
fontsize=12, fontweight="bold")
ax.legend(["$\\lambda_{const}$", "$\\lambda_{const-epoch}$"], loc="upper right")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_ylabel(r"$\lambda(t)$ [Hz]", fontname="Arial", fontsize=12, fontweight="bold")
ax.legend(["$\\lambda_{const}$", "$\\lambda_{const-epoch}$"],
loc="upper right", fontsize=14)

fig3.suptitle("Example 01 — Figure 3: Piecewise Baseline Comparison",
fontsize=14, fontweight="bold")
fig3.tight_layout()
figure_files.extend(_maybe_export(fig3, export_dir, "fig03_piecewise_baseline_comparison"))

Expand Down
36 changes: 19 additions & 17 deletions examples/paper/example02_whisker_stimulus_thalamus.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _maybe_export(fig, export_dir: Path | None, name: str, dpi: int = 250):
if export_dir is not None:
export_dir.mkdir(parents=True, exist_ok=True)
png_path = export_dir / f"{name}.png"
fig.savefig(png_path, dpi=dpi, bbox_inches="tight")
fig.savefig(png_path, dpi=dpi, facecolor="w", edgecolor="none")
saved.append(png_path)
print(f" Saved {png_path}")
return saved
Expand Down Expand Up @@ -150,28 +150,32 @@ def run_example02(*, export_figures: bool = False, export_dir: Path | None = Non
nstView.setMaxTime(viewWindow)
nstView.plot(handle=ax)
ax.set_yticks([0, 1])
ax.set_title("Neural Raster", fontweight="bold", fontsize=12)
ax.set_xlabel("time [s]", fontsize=12, fontweight="bold")
ax.set_ylabel("Spikes", fontsize=12, fontweight="bold")
ax.set_title("Neural Raster", fontweight="bold", fontsize=16, fontname="Arial")
ax.set_xlabel("")
ax.set_xticklabels([])
ax.set_ylabel("spikes", fontname="Arial", fontsize=12, fontweight="bold")

# Subplot 2: Stimulus displacement (first 21 s)
# Subplot 2: Stimulus displacement (first 21 s, black line matching MATLAB)
ax = axes1[1]
stimView = stim.getSigInTimeWindow(0, viewWindow)
stimView.plot(handle=ax)
ax.set_ylabel("Displacement [mm]", fontsize=12, fontweight="bold")
ax.set_xlabel("time [s]", fontsize=12, fontweight="bold")

# Subplot 3: Stimulus velocity (derivative, first 21 s)
stimView.plot(handle=ax, plotPropsIn=[["k"]])
ax.get_legend().remove() if ax.get_legend() else None
ax.set_ylabel("Displacement [mm]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_xlabel("")
ax.set_xticklabels([])
ax.set_title("Stimulus - Whisker Displacement", fontweight="bold", fontsize=16, fontname="Arial")

# Subplot 3: Stimulus velocity (derivative, first 21 s, black line matching MATLAB)
ax = axes1[2]
stimDeriv = stim.derivative
stimDerivView = stimDeriv.getSigInTimeWindow(0, viewWindow)
stimDerivView.plot(handle=ax)
stimDerivView.plot(handle=ax, plotPropsIn=[["k"]])
ax.get_legend().remove() if ax.get_legend() else None
ax.set_ylim(-80, 80)
ax.set_ylabel("Velocity", fontsize=12, fontweight="bold")
ax.set_xlabel("time [s]", fontsize=12, fontweight="bold")
ax.set_ylabel("Displacement Velocity [mm/s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_title("Displacement Velocity", fontweight="bold", fontsize=16, fontname="Arial")

fig1.suptitle("Example 02 — Figure 1: Data Overview",
fontsize=14, fontweight="bold")
fig1.tight_layout()
figure_files.extend(_maybe_export(
fig1, export_dir, "fig01_data_overview"))
Expand Down Expand Up @@ -380,8 +384,6 @@ def run_example02(*, export_figures: bool = False, export_dir: Path | None = Non
ax_coeff = fig2.add_subplot(gs[4:7, 1])
modelCompare.plotCoeffs(handle=ax_coeff)

fig2.suptitle("Example 02 — Figure 2: Lag & History Selection",
fontsize=14, fontweight="bold")
figure_files.extend(_maybe_export(
fig2, export_dir, "fig02_lag_and_model_comparison"))

Expand Down
46 changes: 27 additions & 19 deletions examples/paper/example03_psth_and_ssglm.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,36 +199,38 @@ def run_part_a(data_dir, export_dir=None):
# Top-left: CIF
ax = axes1[0, 0]
ax.plot(time, lambdaData, "b", linewidth=2)
ax.set_title("Simulated CIF", fontweight="bold", fontsize=14)
ax.set_xlabel("time [s]")
ax.set_ylabel("spikes/sec")
ax.set_title("Simulated Conditional Intensity Function (CIF)",
fontweight="bold", fontsize=14, fontname="Arial")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_ylabel(r"$\lambda(t)$ [spikes/sec]", fontname="Arial", fontsize=12, fontweight="bold")
ax.legend([r"$\lambda_1$"], loc="upper right", fontsize=14)

# Bottom-left: simulated raster
ax = axes1[1, 0]
spikeCollSim.plot(handle=ax)
ax.set_yticks(range(0, numRealizations + 1, 5))
ax.set_title(f"{numRealizations} Simulated Sample Paths",
fontweight="bold", fontsize=14)
ax.set_xlabel("time [s]")
ax.set_ylabel("Trial [k]")
ax.set_title(f"{numRealizations} Simulated Point Process Sample Paths",
fontweight="bold", fontsize=14, fontname="Arial")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_ylabel("Trial [k]", fontname="Arial", fontsize=12, fontweight="bold")

# Top-right: real cell 6 raster
ax = axes1[0, 1]
spikeCollReal1.plot(handle=ax)
ax.set_yticks(range(0, numTrials + 1, 2))
ax.set_title("Response to Moving Visual Stimulus (Neuron 6)",
fontweight="bold", fontsize=14)
ax.set_xlabel("time [s]")
ax.set_ylabel("Trial [k]")
fontweight="bold", fontsize=14, fontname="Arial")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_ylabel("Trial [k]", fontname="Arial", fontsize=12, fontweight="bold")

# Bottom-right: real cell 1 raster
ax = axes1[1, 1]
spikeCollReal2.plot(handle=ax)
ax.set_yticks(range(0, numTrials + 1, 2))
ax.set_title("Response to Moving Visual Stimulus (Neuron 1)",
fontweight="bold", fontsize=14)
ax.set_xlabel("time [s]")
ax.set_ylabel("Trial [k]")
fontweight="bold", fontsize=14, fontname="Arial")
ax.set_xlabel("time [s]", fontname="Arial", fontsize=12, fontweight="bold")
ax.set_ylabel("Trial [k]", fontname="Arial", fontsize=12, fontweight="bold")

fig1.tight_layout()

Expand Down Expand Up @@ -496,7 +498,8 @@ def run_part_b(data_dir, export_dir=None):
# ------------------------------------------------------------------
# Figure 5: True/PSTH/SSGLM stimulus effect surfaces
# Match MATLAB: mesh(trial, time, data) with view([90 -90]) → top-down
# Using pcolormesh for clean 2D rendering matching MATLAB's top-down mesh
# MATLAB orientation: time [s] on x-axis, Trial [k] on y-axis
# (matches fig03 bottom-panel "True Conditional Intensity Function")
# ------------------------------------------------------------------
fig5, axes5 = plt.subplots(3, 1, figsize=(14, 9))
trial_axis = np.arange(1, numRealizations + 1)
Expand All @@ -509,12 +512,17 @@ def run_part_b(data_dir, export_dir=None):
]
for ax, (data, title_str) in zip(axes5, surfaces):
# data is (T, K) — time on rows, trials on columns
# MATLAB: imagesc shows trial on x, time on y
ax.pcolormesh(trial_axis, basis_time[:T_act], data, cmap="viridis",
# Transpose so trials are on y-axis and time on x-axis,
# matching MATLAB nSTATPaperExamples_15.png orientation.
ax.pcolormesh(basis_time[:T_act], trial_axis, data.T, cmap="viridis",
shading="auto")
ax.set_ylabel("time [s]")
ax.set_xlabel("time [s]")
ax.set_ylabel("Trial [k]")
ax.set_title(title_str, fontweight="bold", fontsize=14)
axes5[-1].set_xlabel("Trial [k]")
# Remove redundant per-subplot x-labels except the bottom one
for ax in axes5[:-1]:
ax.set_xlabel("")
ax.set_xticklabels([])

fig5.tight_layout()
print(" Figure 5: Stimulus effect surfaces (top-down mesh)")
Expand Down Expand Up @@ -613,7 +621,7 @@ def run_example03(*, export_figures: bool = False, export_dir: Path | None = Non
export_dir.mkdir(parents=True, exist_ok=True)
for name, fig in all_figs.items():
path = export_dir / f"{name}.png"
fig.savefig(str(path), dpi=150, bbox_inches="tight")
fig.savefig(str(path), dpi=250, facecolor="w", edgecolor="none")
print(f" Saved {path}")

plt.show()
Expand Down
26 changes: 16 additions & 10 deletions examples/paper/example04_place_cells_continuous_stimulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,19 @@ def run_example04(*, export_figures: bool = False, export_dir: Path | None = Non
fig1, axes1 = plt.subplots(2, 2, figsize=(12, 10))
for i, cidx in enumerate(exampleCells):
ax = axes1.flat[i]
ax.plot(x1, y1, "b-", linewidth=0.5, alpha=0.5)
h1, = ax.plot(x1, y1, "b", linewidth=0.5)
n = neurons1[min(cidx, nCells1 - 1)]
xn = np.asarray(n["xN"].item(), dtype=float).ravel()
yn = np.asarray(n["yN"].item(), dtype=float).ravel()
ax.plot(xn, yn, "r.", markersize=7)
ax.set_title(f"Cell {cidx + 1}", fontweight="bold", fontsize=12)
h2, = ax.plot(xn, yn, "r.", markersize=7)
ax.set_title(f"Cell#{cidx + 1}", fontweight="bold", fontsize=12, fontname="Arial")
ax.set_xlabel("X Position")
ax.set_ylabel("Y Position")
ax.set_xticks([-1, -0.5, 0, 0.5, 1])
ax.set_yticks([-1, -0.5, 0, 0.5, 1])
ax.set_aspect("equal")
fig1.suptitle("Animal 1 — Example Place Cells", fontweight="bold",
fontsize=14)
if i == 3:
ax.legend([h1, h2], ["Animal Path", "Location at time of spike"])
fig1.tight_layout()

# ==================================================================
Expand Down Expand Up @@ -359,10 +363,12 @@ def _plot_heatmaps(fit_results, nCells, title_prefix, design_gauss,
axesG[row, col].set_visible(False)
axesZ[row, col].set_visible(False)

figG.suptitle(f"{title_prefix} — Gaussian Place Fields",
fontweight="bold", fontsize=14)
figZ.suptitle(f"{title_prefix} — Zernike Place Fields",
fontweight="bold", fontsize=14)
# Match MATLAB sgtitle format: "Gaussian Place Fields - Animal#N"
animal_num = title_prefix.replace("Animal ", "")
figG.suptitle(f"Gaussian Place Fields - Animal#{animal_num}",
fontweight="bold", fontsize=12)
figZ.suptitle(f"Zernike Place Fields - Animal#{animal_num}",
fontweight="bold", fontsize=12)
figG.tight_layout()
figZ.tight_layout()
return figG, figZ
Expand Down Expand Up @@ -430,7 +436,7 @@ def _plot_heatmaps(fit_results, nCells, title_prefix, design_gauss,
export_dir.mkdir(parents=True, exist_ok=True)
for name, fig in all_figs.items():
path = export_dir / f"{name}.png"
fig.savefig(str(path), dpi=150, bbox_inches="tight")
fig.savefig(str(path), dpi=250, facecolor="w", edgecolor="none")
print(f" Saved {path}")

plt.show()
Expand Down
2 changes: 1 addition & 1 deletion examples/paper/example05_decoding_ppaf_pphf.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def run_example05(*, export_figures=False, export_dir=None, show=False):
]
for i, fig in enumerate(figures):
path = export_dir / f"{fig_names[i]}.png"
fig.savefig(path, dpi=150, bbox_inches="tight")
fig.savefig(path, dpi=250, facecolor="w", edgecolor="none")
print(f" Saved: {path}")

if show:
Expand Down
Loading
Loading