JorritMontijn / zetapy

Python code implementing the ZETA-test
GNU General Public License v3.0
20 stars 7 forks source link

Plotting in getZeta throws an error #6

Closed MarinaSlashcheva closed 8 months ago

MarinaSlashcheva commented 10 months ago

Hey! I am trying to plot the results of ZETA test with the following code:

        np.random.seed(1)

        eventTimes_off = eventTimes+0.1 #Take 100 ms for now
        arrEventTimes = np.transpose(np.array([eventTimes, eventTimes_off]))
        dblZetaP, vecLatencies = getZeta(spike_vec, 
                                        arrEventTimes, 
                                        intLatencyPeaks = 4,
                                        dblUseMaxDur =0.05,
                                        intPlot=1)

But get the following error


ValueError                                Traceback (most recent call last)
c:\Users\admin\OneDrive - KI.SE\Skrivbordet\General\Projects\CommonCodes\NPx_basic_analysis\optotagging.py in 
      2 eventTimes_off = eventTimes+0.1 #Take 100 ms for now
      3 arrEventTimes = np.transpose(np.array([eventTimes, eventTimes_off]))
----> 4 dblZetaP, vecLatencies = getZeta(spike_vec, 
      5                                 arrEventTimes,
      6                                 intLatencyPeaks = 4,

c:\Users\admin\anaconda3\envs\NWBenv\lib\site-packages\zetapy\main.py in getZeta(arrSpikeTimes, arrEventTimes, dblUseMaxDur, intResampNum, intPlot, intLatencyPeaks, tplRestrictRange, boolReturnRate, boolReturnZETA, boolVerbose)
    248                                               arrEventStarts, pre_time=0, post_time=dblUseMaxDur,
    249                                               bin_size=dblUseMaxDur/25, smoothing=0)
--> 250         ax2.errorbar(peth['tscale'], peth['means'][0, :], yerr=peth['sems'])
    251         ax2.set(xlabel='Time from event (s)', ylabel='spks/s',
    252                 title='Mean spiking over trials')

c:\Users\admin\anaconda3\envs\NWBenv\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
   1445     def inner(ax, *args, data=None, **kwargs):
   1446         if data is None:
-> 1447             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1448 
   1449         bound = new_sig.bind(ax, *args, **kwargs)

c:\Users\admin\anaconda3\envs\NWBenv\lib\site-packages\matplotlib\axes\_axes.py in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
   3451 
   3452         if yerr is not None:
-> 3453             lower, upper = extract_err('y', yerr, y, lolims, uplims)
   3454             barcols.append(self.vlines(
   3455                 *apply_mask([x, lower, upper], everymask), **eb_lines_style))

c:\Users\admin\anaconda3\envs\NWBenv\lib\site-packages\matplotlib\axes\_axes.py in extract_err(name, err, data, lolims, uplims)
   3401                 a = b = err  # Symmetric error: 1D iterable.
   3402             if np.ndim(a) > 1 or np.ndim(b) > 1:
-> 3403                 raise ValueError(
   3404                     f"{name}err must be a scalar or a 1D or (2, n) array-like")
   3405             # Using list comprehensions rather than arrays to preserve units.

ValueError: yerr must be a scalar or a 1D or (2, n) array-like

Do you have any idea what could be causing it? Thanks in advance :)

JorritMontijn commented 10 months ago

Oddly enough I got a different error, but hopefully it had the same root cause (getOnset was returning multiple onset values). In any case, I've fixed it now in the dev branch: https://github.com/JorritMontijn/zetapy/tree/dev (assuming my error wasn't something else that was wrong). Let me know if the dev-branch version doesn't fix the error. Otherwise I can only recommend using the matlab version for now ( https://github.com/JorritMontijn/zetatest ). The zetatest repo has some extra statistical tweaks to improve statistical power when the events are heterogeneously distributed, it runs faster than python and it has no bugs (AFAIK).

That said, I'm about to start porting the latest changes from https://github.com/JorritMontijn/zetatest into the python version, so I recommend not updating the dev branch beyond the first commit;)

Guido is still maintaining the master branch and the pip version, so hopefully he can take a look at the problem to update those versions?

JorritMontijn commented 8 months ago

I've just uploaded the new version, so if you switch to zetatest instead of getZeta, there should be no more plotting bugs (fingers crossed)