Use "markers" to define beg. and end of a period, then do calcs on data within that period

Hello @grant1,
I’m a little confused about how you’re determining the periods.
I would assume that every value below 150 is either the start or stop of a new period.
Im surprised to see that one valley in the period of 04-2022 is missed or that the next period after that ends with the value at ~240.

I am working on this script:

import "math"
import outer "join"
data = from(bucket: "noaa")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "h2o_feet")
  |> filter(fn: (r) => r["_field"] == "water_level")
  |> filter(fn: (r) => r["location"] == "coyote_creek")
  |> limit(n: 400)
//   |> yield(name: "raw")

derr = data 
// unit for the time in between timestamps
|> derivative(unit: 6m)
|> keep(columns: ["_time", "_value"])
// |> yield(name: "derr")

derr_shift = derr
|> timeShift(duration: 6m)
|> keep(columns: ["_time", "_value"])
// |> yield(name: "derr_shift")

inflection_time = join(tables: {derr: derr, derr_shift: derr_shift}, on: ["_time"])
// change to just one side of the or expression if you want to find a true period in a sin wave
|> filter(fn: (r) => r._value_derr >= 0.0 and r._value_derr_shift <= 0.0 or r._value_derr <= 0.0 and r._value_derr_shift >= 0.0 )
// to account for when the derivative does == 0 and define inflection point from either side of crossing from pos to neg or neg to pos
// also helps us make sure that local max and min are looking right/adequate time between them
|> elapsed(unit: 6m)
|> filter(fn: (r) => r.elapsed > 1)
// |> yield(name: "inflection points")
// add a counter for the inflection points so we can fill previous after subsequent join to track which values are a part of which period
|> map(fn: (r) => ({r with _value: 1.0}))
|> cumulativeSum()
|> keep(columns: ["_time", "_value"])

outer.time(left: data, right: inflection_time, as: (l, r) => ({l with label: r._value}))
|> fill(usePrevious: true)
|> yield(name: "_result")

Which uses

But unfortunately I get an error which is part of this PR

I’m told I can use

|> debug.pass()
To bypass the errors but it's not working. 

I'll update you as I know.