Darren Wiens yes, definitely, but it sometimes depends on perspective...lets try rolling/padding by 1 position/year.
In this example the first year and the last year are the same.
>>> a = np.array([1,0,0,1,1,1,1,0,1,1,1,1],dtype=bool) # with first and last month the same
>>> b = np.roll(a,-1)
>>> chg = (b ^ a)
>>> pos = np.arange(len(chg))[chg]
>>> diff = np.diff(pos)
>>> max_seq = np.max(diff)
>>> max_seq
4
>>> a.astype(int)
array([1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1])
>>> b.astype(int)
array([0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1])
>>> chg.astype(int)
array([1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0])
>>> pos
array([0, 2, 6, 7])
>>> diff
array([2, 4, 1])
>>>
So the question becomes how far do you roll (12 years as in your case)?
But what if the, first year and the last year are different?
>>> a = np.array([1,0,0,1,1,1,1,0,1,1,1,0],dtype=bool) # with last month different than first
>>> b = np.roll(a,-1)
>>> chg = (b ^ a)
>>> pos = np.arange(len(chg))[chg]
>>> diff = np.diff(pos)
>>> max_seq = np.max(diff)
>>> # results........
>>> a.astype(int)
array([1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0])
>>> b.astype(int)
array([0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1])
>>> chg.astype(int)
array([1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1])
>>> pos
array([ 0, 2, 6, 7, 10, 11])
>>> diff
array([2, 4, 1, 3, 1])
>>> max_seq
4
The same results are yielded, largely by coincidence since the first and last year are different
It is interesting that you can roll forward or backward as long as you keep track of your positions.
You can also use padding with different pad widths and types AND direction. In this example the edges were padded with their neighbor.
>>> a = np.array([1,0,0,1,1,1,1,0,1,1,1,1],dtype=bool) # with first and last month the same
>>> b = np.pad(a,1,mode="edge")
>>> b.astype(int)
array([1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1])
>>> chg = (b[:-1] ^ b[1:])
>>> pos = np.arange(len(chg))[chg]
>>> diff = np.diff(pos)
>>> max_seq = np.max(diff)
>>> max_seq
4
It just becomes more interesting when you are trying to shift, difference and pad sequences of 2D+ arrays with or without padding or replication. As I indicated, I will try to summarize in an upcoming blog because raster size can play a role. Also, if you are only interested in limited positions within the raster, reducing the input raster to a sparse array will reduce memory needs and speed up processing time.