I have a binary sequence such as
Where clusters of mostly 1's are followed by a larger number of zeros, like in the picture below (black stands for 1):
I would like to apply a technique (preferably in R or in Python) where I can automatically detect these clusters of 1's, and produce spans (denoted as red lines in the image). I know one could do this with a threshold, i.e. saying that two clusters must be seperated by at least n 0's to be clusters, but I wonder if there are other established methods which do not use predefined thresholds.