Jan-12-2020, 10:55 PM
I have a large 3 dimensional (time, longitude, latitude) input array of daily tmax values. I have masked the values which exceed a certain threshold. I need to find those entries where the mask is True for longer than a specific number of (3) consecutive time steps. The result should be a data array with 0s for the non-consecutive days and numbers corresponding to the length (duration of event) of consecutive elements.
Below is some pseudo-code to make myself clearer:
events = find_consecutive(input_array, duration=3)
input_array = [1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1]
events = [0, 0, 0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0]
I've had a look at scipy nd image but haven't been able to completely figure out how to use it.
Any help is appreciated :)
Below is some pseudo-code to make myself clearer:
events = find_consecutive(input_array, duration=3)
input_array = [1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1]
events = [0, 0, 0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0]
I've had a look at scipy nd image but haven't been able to completely figure out how to use it.
Any help is appreciated :)