-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resample: ValueError: x and y arrays must be equal in length along interpolation axis. #361
Comments
Actually, looks like the issue is |
This traces back to In this dataset, with The question is if that strong ceiling rounding is fair here. I could imagine why only 438000 samples are provided. Maybe regular |
I think changing it to |
Agreed. But if its off by one? Should this check adjust it? I can just see either number of samples being valid (although round seems like a saner default to me if we had to choose). |
Yes, the idea would be to trim or pad one or the other (or at the very least, raise a more comprehensible exception). Probably the |
I believe I ran into this (and referenced it incoherently in the lower end of #355) |
@effigies try changing the rounding from |
This was fixed by #365 |
Looks like it's because for me this issue is arising at Since this happens in conjunction with |
I was looking at the resampling code earlier to day and spotted some potential problems. I'm not sure if this issue is coming from the same place (probably not), but FWIW, this line is probably broken: # This...
x_new = np.linspace(0, n - 1, num=num)
# Should be something like...
x_new = np.linspace(0, n , num=num, endpoint=False) That would however probably require tweaking some things elsewhere in the code (e.g., in If we really want to do this right, we may also want to consider selecting resampling methods intelligently based on data and target sampling rate (e.g., in cases where we're downsampling by a relatively small factor, we should maybe use |
I think for me it was simply a rounding error, so I changed my code to match, but its not clear which is "correct" to me. Probably worth looking at, and abstract that logic away to be the same function to consistency (if/when resampling is overhauled) |
@tyarkoni This resampling issue just happend to come up for me. In a run with 1033 binary "speech" events, resampling to 10hz result in an average value of around 0.3. But below 5hz (and especially at TR), lots of these values seem to get lost/averaged out. In the end, at sampling_rate = TR, only a single non-zero value remained.... I'll look into it in more detail tomorrow |
How long are the events, and how widely are they spaced? This doesn't necessarily sound problematic—possibly just an indication that the sampling rate is too low (even at 10 Hz). Also, are you talking about the convolved values, or just the raw values run through just the |
It only happens on raw binary values. with very short durations (0.01-0.5s). Usually they are in chunks. I don't think I'd noticed before because I always convolve this regressor. I suppose the code for Edit: The issue is actually that if an events duration * sampling_rate is less than 0.5, it will get rounded down to 0 and omitted: pybids/bids/variables/variables.py Line 330 in b4bb3cd
|
Yeah, that makes sense. The resampling/densification code needs a complete overhaul. I have a plan for it, but need to find the time. Bunch of things to review in the next week or so, but probably after that. |
No rush, convolution "fixes" this for me for now. |
Proof of concept of the seemingly faulty interpolation of Given the following
applying
However, with
|
@adelavega - have you tested this without using the antialiasing filter? i suspect that is what is causing this to return what you have. just from looking at the dense variable(which looks to be high frequency) the output looks reasonably correct. |
Thanks, although I don't think that's the issue. Looks like However, when requesting Looks we should doing a |
which for this particular vector could still likely return zeros. upsampling does not change frequency characteristics, downsampling does (via aliasing), hence there is an asymmetry in processes. |
Trying with a slightly different inputs, the outputs of
|
I think you make a valid point @satra, thanks, but I think there's a more basic problem here with how we handle automatic densification in |
To ensure a faithful representation of sparse variables with dense variables, I think the sampling rate needs to be If we're going to allow a sampling rate with |
Tal and I just discussed this and I think the take home is that However, the problem is that It would be worthwhile to think about smarter ways to apply resampling which may inspect the variable itself to ensure the right thing is done, such as what you suggested, @effigies , so I may open an issue on that, although it does not seem critical. |
When trying to resample a dense variable (physio) with a sampling rate of
0.49999984750004656
the length of the
x
given tointerp1d
is one longer thanvalues
. My guess is that this has to do with a rounding error with the funky sampling_rate.The text was updated successfully, but these errors were encountered: