I have used your code to try and count the number of days per year that a fire weather index is above or below a set threshold. For the most part, the code worked well, but I have noticed that there are some errors in the total counts. For example, (total days meeting or exceeding threshold) + (total days below threshold) does not equal the total number of days in a year. And similarly, when looking at the graphed data, I count x number of distinct periods (above or below threshold), but the results of the code indicate there are (x-1) distinct periods.

I have essentially used your exact code, so I’m wondering if you may have any insight into this problem or have encountered similar problems in your own program.

Thanks!

]]>The short python snippet below counts transitions from one result to the next. The second sequence is far more extreme than the first in this regard, as a head is always followed by a tail and a tail is most often followed by a head.

import numpy as np

r1 = “HTTTTHHTHHHHTTHHHHTT” r2 = “HTHTHTHTHTHTTHTHTTTH”

def transition_freqs(rr): rr = np.where(np.array(list(rr)) == “H”, 1, 0) freqs = np.zeros((2, 2), dtype=float) for last, cur in zip(rr[:-1], rr[1:]): freqs[last, cur] += 1 return freqs / freqs.sum(0)[None, :]

print(transition_freqs(r1).round(2)) print(transition_freqs(r2).round(2))

[[0.56 0.3 ] [0.44 0.7 ]] [[0.27 1. ] [0.73 0. ]]

So my bet is on the second sequence to be the one made up.

]]>thanks

]]>`precipitation`

to your script and it will return to you the histogram of the duration of dry spells – isn’t that what you want?
]]>`threshold`

acts as an indicator, everything below counts as dry, everything above as wet. You could set `threshold`

to zero. However, I would encourage you to use some value slightly larger than zero, because a precipitation of 0.1mm does not contribute to any flow.
How does your data look like – could you be more specific?

]]>