[GRASS-user] Median filtering time series in time only

nik at nikosalexandris.net nik at nikosalexandris.net
Wed Jan 27 07:24:57 PST 2021


Yes, I have tried `r.series.fiter` with winsize=3 and winsize=9 for a
year of MODIS products. 
It seems it works. But I want to ensure I am not filtering in space
too.- 

Vero, it feels nice to read you understand what I am trying to describe.

As usual there is an excuse/justification: workload suppresses/d placing
the adjective 'moving' or 'rolling' in the right place before median. 

So, It's a rolling median-filtering of 1-D signal (call it scalar,
vector) in time. 

If you dig in the code of the addon, it uses SciPy's
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.medfilt.html#scipy.signal.medfilt.

This function applies indeed to both 1-D and 2-D data. 

So, we are discussing about the `kernel_size` input parameter for
scipy.signal.medfilt [1].

    > A scalar or an N-length list giving the size of the median filter
window in each dimension. Elements of _kernel_size_ should be odd. If
_kernel_size_ is a scalar, then this scalar is used as the size in each
dimension. Default size is 3 for each dimension. 

By the way, there is a note that 
    > The more general function scipy.ndimage.median_filter [2] has a
more efficient implementation of a median filter and therefore runs much
faster. 

Nikos 
---

On 2021-01-27 16:59, Veronica Andreo wrote:

> El mié., 27 ene. 2021 11:33, <nik at nikosalexandris.net> escribió: 
> 
>> Thank you Vero. 
>> 
>> Consider the following time series [1, 2, 2, 6, 3, 3, 4, 4, 3, 2, 2, 1] <- evolution of a pixel in time. 
>> 
>> Say this is always the same pixel indexed at [0, 0] in each of 12 raster maps registered in a GRASS GIS STRDS. 
>> 
>> Median filtering pixel-wise in time, only, with a temporal window=3, would then be doing: 
>> 
>> 1st pixel would be replaced by the median of [0, 1, 2] 
>> 
>> 2nd pixel would be replaced by then median of [1, 2, 2] 
>> 
>> 3rd pixel would be replaced by the median of [2, 2, 6] 
>> 
>> 4th pixel would be replaved by the median of [2, 6, 3] 
>> 
>> etc.
> 
> Got it, it's more like a rolling median what you need.  
> 
> Have you tried r.series.filter? From the manual page, it seems that's exactly what it does if you set method=median and winsize=3 (given that winsize is in time) 
> 
> Otherwise, we can think harder on how to do that with t.rast.algebra and the neighborhood modifier only moving in time. But, you should explore how to expose the median function from r.mapcalc first, since it's not available in t.rast.algebra yet 
> 
>> Doing a spatial median over a 2D (sub)window of each raster map in a GRASS GIS STRDS is not wanted here.  I hope this is more clear now.
> 
> This is not what I suggested in the previous email either. Both r.series and t.rast.series will estimate the median per pixel in time (either for the whole series or the time period you want). Would it be possible then with so e sort of special for cycle? 
> 
> Best, 
> Vero 
> 
> Nikos 
> 
> ---
> 
> On 2021-01-27 16:04, Veronica Andreo wrote: 
> 
> What exactly do you mean by median-filtering in time only, Nikos? Get the median and then filtering out all pixels above/below that value? If that's the case, then maybe some of the examples here https://grasswiki.osgeo.org/wiki/Temporal_data_processing#Spatio-temporal_algebra_with_STRDS might be of help 
> 
> Basically, you first estimate the median of the series (or the period you are interested in) either with r.series or t.rast.series and then use t.rast.mapcalc or t.rast.algebra to get only pixels below/above that value represented pixelwise in the median map. It can also be a single value of course. 
> 
> Does that make sense? 
> 
> best, 
> Vero 
> 
> El mié., 27 ene. 2021 08:44, <nik at nikosalexandris.net> escribió: I am trying to median-filter time series in time and not in space.
> 
> Not sure `r.series.filter` is the right tool.
> I skimmed through the manual, the paper and the source code. Yet I am 
> asking for a confirmation.
> Its (odd integer) parameter `winsize=` implies a moving window (of size 
> winsize^2).
> Does this rather filter images, of a time series, in space?
> Or does the `winsize` here refer to the length of a moving temporal 
> window?
> 
> Then, there is `r.series.lwr`.
> Can I use the tool with `order=0` and `delta=1` (or `order=3` and 
> `delta=1`)
> and perform a moving average filtering in time?
> It's not median. Still I'd like to see a filtering in time-only effect.
> 
> And, now I recall `r.hants`.
> Is there a way to use it for filtering-out only lows and highs (`-l` and 
> `-h` respectively) pixel-wise in time, without interpolating nor 
> extrapolating?
> 
> Else, I guess there should be a way to build a 'custom' filter using 
> `t.rast.algebra` using its temporal neighborhood modifier.
> It's convenient if one the tools above does already median-filtering in 
> time-only.
> 
> Kind regards, Nikos
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
 

Links:
------
[1]
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.medfilt.html#scipy.signal.medfilt
[2]
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.median_filter.html#scipy.ndimage.median_filter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20210127/3a7f3c3d/attachment-0001.html>


More information about the grass-user mailing list