GWeindel / hmp

Repository for the hmp python package
BSD 3-Clause "New" or "Revised" License
32 stars 8 forks source link

Running plot_latencies() as in Tutorial 4 yield error with new implementation of the function #95

Closed GWeindel closed 1 year ago

GWeindel commented 1 year ago

On tutorial 4 the cell

    labels= ['speed', 'Accuracy'], errs='ci', time_step=1000/init.sfreq,
    colors=["indianred","darkgreen"], figsize=(10,5));

Yields:

UnboundLocalError                         Traceback (most recent call last)
Cell In[28], line 6
      4     condition_times.append(cond[0].compute_times(cond[0], cond[1].dropna('event'), add_rt=True))
      5 condition_times = np.array(condition_times,dtype=object)
----> 6 hmp.visu.plot_latencies(condition_times, kind='point',legend=True,
      7     labels= ['speed', 'Accuracy'], errs='ci', time_step=1000/init.sfreq,
      8     colors=["indianred","darkgreen"], figsize=(10,5));

File ~/owncloud/projects/RUGUU/hsmm-mvpy/src/hsmm_mvpy/visu.py:696, in plot_latencies(times, init, time_step, labels, colors, figsize, errs, kind, legend, max_time, as_time)
    692 plt.errorbar(np.arange(n_stages)+1, avg_duration, 
    693         yerr=errorbars, color=cur_colors[j], fmt='o-', capsize=10, label=labels[j])
    695 plt.xlim(1-.5, n_stages+.5)
--> 696 axs.set_ylim(0, np.nanmax(avg_durations)*1.05)
    698 if time_step == 1:
    699     plt.ylabel('Stage durations (samples)')

UnboundLocalError: cannot access local variable 'avg_durations' where it is not associated with a value

@Jelmer this traces back to your latest modifications, is this an error in the function or in its call?

GWeindel commented 1 year ago

Fixed by #96