Added weighted median function and tests

`!all(mask)` will be faster here