Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
zm711 committed Oct 3, 2023
1 parent 7b81ef3 commit 45eaefe
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/spikeanalysis/spike_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ def plot_latencies(self):
plt.figure(dpi=self.dpi)
plt.show()


def plot_isi(self):
"""
Function for plotting ISI distributions
Expand All @@ -726,10 +725,15 @@ def plot_isi(self):
plt.figure(dpi=self.dpi)
plt.show()


def plot_response_trace(self, type: Literal['zscore', 'raw'] = 'zscore', by_neuron: bool = False, by_trial:bool = False, ebar: bool = False, color='black'):

assert type in ['zscore', 'raw'], 'type of data must be zscore or raw'
def plot_response_trace(
self,
type: Literal["zscore", "raw"] = "zscore",
by_neuron: bool = False,
by_trial: bool = False,
ebar: bool = False,
color="black",
):
assert type in ["zscore", "raw"], "type of data must be zscore or raw"

if type == "zscore":
data = self.data.z_scores
Expand All @@ -743,41 +747,39 @@ def plot_response_trace(self, type: Literal['zscore', 'raw'] = 'zscore', by_neur
if by_trial and by_neuron:
for neuron in range(np.shape(response)[0]):
for trial in range(np.shape(response)[1]):
self._plot_one_trace(current_bins, response[neuron, trial, :], ebars=None, color=color, stim=stimulus)
self._plot_one_trace(
current_bins, response[neuron, trial, :], ebars=None, color=color, stim=stimulus
)
elif by_neuron:
for neuron in range(np.shape(response)[0]):
avg_response = np.mean(response[neuron], axis=0)
ebars = np.std(response[neuron], axis=0)
if ebar:
self._plot_one_trace(current_bins, avg_response, ebars=ebars, color=color,stim=stimulus)
self._plot_one_trace(current_bins, avg_response, ebars=ebars, color=color, stim=stimulus)
else:
self._plot_one_trace(current_bins, avg_response, ebars=None, color=color,stim=stimulus)
self._plot_one_trace(current_bins, avg_response, ebars=None, color=color, stim=stimulus)
elif by_trial:
for trial in range(np.shape(response)[1]):
avg_response= np.mean(response[:, trial, :], axis=0)
avg_response = np.mean(response[:, trial, :], axis=0)
ebars = np.std(response[:, trial, :], axis=0)
if ebar:
self._plot_one_trace(current_bins, avg_response, ebars=ebars, color=color,stim=stimulus)
self._plot_one_trace(current_bins, avg_response, ebars=ebars, color=color, stim=stimulus)
else:
self._plot_one_trace(current_bins, avg_response, ebars=None, color=color, stim=stimulus)
else:
avg_response = np.mean(np.mean(response, axis=1), axis=0)
if ebar:
self._plot_one_trace(current_bins, avg_response, ebars=ebars, color=color, stim=stimulus)
else:
self._plot_one_trace(current_bins, avg_response, ebars=None, color=color,stim=stimulus)




def _plot_one_trace(self, bins, trace, ebars=None, color='black', stim=''):
self._plot_one_trace(current_bins, avg_response, ebars=None, color=color, stim=stimulus)

def _plot_one_trace(self, bins, trace, ebars=None, color="black", stim=""):
fig, ax = plt.subplots(figsize=self.figsize)
ax.plot(bins, trace, color=color)
if ebars is not None:
ax.plot(bins, trace+ebars, color=color)
ax.plot(bins, trace-ebars, color=color)
ax.fill_between(bins, trace-ebars, trace+ebars, color=color, alpha=0.02)
ax.plot(bins, trace + ebars, color=color)
ax.plot(bins, trace - ebars, color=color)
ax.fill_between(bins, trace - ebars, trace + ebars, color=color, alpha=0.02)

ax.set_xlabel("Time (s)")
ax.set_ylabel(self.y_axis)
Expand All @@ -787,7 +789,6 @@ def _plot_one_trace(self, bins, trace, ebars=None, color='black', stim=''):
plt.figure(dpi=self.dpi)
plt.show()


def _get_event_lengths(self) -> dict:
"""
Utility function to get the event lengths and convert from samples to seconds on a trial
Expand Down

0 comments on commit 45eaefe

Please sign in to comment.