This is the companion to block functions introduced earlier. I will keep it simple. The stats functions for rasters with and without nodata values still apply to this type of treatment. The only difference is how the sub-arrays are generated. I won't get into the details of how they are done here, but the stride function uses some pretty tricky handling of the input array structure to parse out the moving windows.
Remember, block functions move one window size across and down, per movement cycle. Sliding functions move one cell across and down and sample the cell based on the window size...hence, there are many more windows to sample in sliding function than in block functions. I will just show the code snippets and you can play on your own. I have posted sample timing results for comparative purposes for both implementations.
Code section and comments |
---|
Stride and block functions provide the means to sample the input array according to the type of data, the size and layout. You must read the documentation and experiment in order to fully understand. It really messes with your head and makes the Rubic's cube look simple. The decorator and timer functions I have talked about before. Refer to my previous blogs for more information. |
imports
slide (stride) and block functions
timing decorator, decorated stat function and time test
main section
|
Description: This code does...timing examples for sliding and block mean Timing results sliding mean block mean array size total time total time (seconds) 1000x1000 3.85e-02 4.65...e-03 2000x2000 1.51e-01 1.75...e-02 3000x3000 3.41e-01 3.86...e-02 4000x4000 6.37e-01 7.20...e-02 5000x5000 9.46e-01 1.04...e-01 The slowest is obviously the sliding function since it does 9 samples for ever 1 that block does since I used a 3x3 window...I think...it is the easy stuff that confuses. Enjoy and study the code and its origins should you be interested. I should note that the whole area of sliding implementation has been quite the area of investigation. The implementation that I presented here is one that I chose to use because I liked it. It may not be the fastest or the bestest... but I don't care...if it takes less than a sip of coffee, it is good enough for me. |
That's all for now....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.