Skip to content

hampel_filter filtsize doesn't work as expected/intended. #111

@multigummie

Description

@multigummie

Two issues:

  1. The documentation for the hampel_filter function states:
    filtsize : int
        the filter size expressed the number of datapoints
        taken surrounding the analysed datapoint. a filtsize
        of 6 means three datapoints on each side are taken.
        total filtersize is thus filtsize + 1 (datapoint evaluated)

however, as currently implemented the slices will not be filtesize + 1, it will be exactly filtsize. e.g. for filtsize = 6, the following line:

dataslice = output[i - onesided_filt : i + onesided_filt]

on the first iteration of the loop (i = onesided_filt -> i = 3) will evaluate to dataslice = output[0:6]. Python is exclusive on the end of the slice, so you will only get 6 data points in the slice. I believe the code should read:

dataslice = output[i - onesided_filt:i + onesided_filt + 1]
  1. behavior for odd numbered filtsize is not well defined. Python's // operator will round down for odd numbers (e.g. 7//2 will result in 3). This means a filtsize = 7 is actually functionally the same as filtsize = 6. If I understand correctly an odd-numbered filtsize isn't really intended to be possible, so I'd suggest adding a guard clause at the top of the function to prevent this, as well as updating the docs.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions