Detect U-shave or V-shape in data series

Question:

I have a data series. I need to find all data segments that look look like U-shape or V-shape. Using the data below as an example, if I define the U-shape or V-shape as starting and ending point with ratio>=0.7 and all points in between are with ratio<0.7 and at least one point in between with ratio<=0.2. With this requirements, I can say two segments in this sample data (12/18/2021 to 12/22/2021, and 12/24/2021 to 12/27/2021) are with U or V shape.

is there some easy way to do this in python or with any package other than writing loops to identify the starting point and nested loop to identify the ending point? Thanks.

date ratio
12/12/2021 0.676
12/13/2021 0.66
12/14/2021 0.682
12/15/2021 0.815
12/16/2021 0.784
12/17/2021 0.649
12/18/2021 0.859
12/19/2021 0.084
12/20/2021 0.156
12/21/2021 0.435
12/22/2021 0.741
12/23/2021 0.671
12/24/2021 0.761
12/25/2021 0.391
12/26/2021 0.126
12/27/2021 0.8
12/28/2021 0.761
12/29/2021 1.025
12/30/2021 0.776
12/31/2021 0.849
Asked By: sguo

||

Answers:

Start at all points ratio <= 0.2 and grow the neighborhood until the endpoints are both >=0.7.

So there are 2 V’s with the minimum at:

12/20/2021  0.156
12/26/2021  0.126

This is a 1-d variant (or conceptual cousin) of the watershed algorithm.

https://en.wikipedia.org/wiki/Watershed_(image_processing)

GAME OF LIFE

So you can implement this similar to a game of life or cellular automata. First mark all data points <= 0.2 as blue. Every round implement this rule for each data point. If any neighbor is blue and < 0.7 or if I’m already blue => I’m blue else I’m black. Iterate rounds until no data point changes color.

Second, find each continuous range of blue data points. That range is a "V-shape".

Answered By: SargeATM
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.