SNEWS2 / snewpdag

SNEWS2 alert calculations
BSD 3-Clause "New" or "Revised" License
1 stars 13 forks source link

Uniform generator for time series and histograms #76

Closed tsengj10 closed 2 years ago

tsengj10 commented 2 years ago

Generator code for TimeSeries and TimeHist objects, starting with just a uniform event rate over a given span.

One can create a TimeSeries or TimeHist using the NewTimeSeries or NewTimeHist generator. Uniform then adds to the object. One can then string together further generators to add to the objects.

We'll need to add some more utilities, like setting new start times and adding objects together, to make this fully functional. This would be an alternative to creating a bunch of objects in the data['gen'], with a Combine at the end, which was getting a bit clumsy.

tsengj10 commented 2 years ago

Need to pull this on top of master for it to work, because renderers/init.py refers to PickleOutput now

tsengj10 commented 2 years ago

This PR mostly stands on its on (and I think shouldn't cause trouble for others), so going to merge soon.

mcolomermolla commented 2 years ago

I see that for the pickle implementation (still looking at it), you have come back to old ".py" config files instead of csv: snewpdag/data/test-pickle-in.py

Shouldn't it be also a csv?

tsengj10 commented 2 years ago

Sometimes I find the old .py form easier for simple graphs. But happy to make csv versions in a new PR!

mcolomermolla commented 2 years ago

Some comments:

tsengj10 commented 2 years ago

Thanks @mcolomermolla for the comments. A few replies:

mcolomermolla commented 2 years ago
tsengj10 commented 2 years ago

Good point about the duration - I'll add it to values.TimeSeries. And possibly call it "duration" rather than "time_span".

Also will try to add the non-zero default nbins value - though I now recall why I didn't, which is that I had allowed the nbins parameter to override (i.e., shorten) the length of the data array in determining how many bins the histogram was to have. Having a non-zero default value makes it impossible to specify "I want my histogram to have 100 bins, so truncate my array which happens to have 110 bins". On the other hand, there are other ways to specify that outside of the arguments, but in any case it'll change the semantics of the nbins vs data.

Finally, I remembered that we automatically lose precision in the timestamp, so we may need to keep (s,ns) for anything which could be a full timestamp. The reason is that the usual Unix-epoch timestamp uses nearly its full 32 bits - if I remember correctly, it turns over in the 2030's, possibly a bigger "Y2K" problem than the one in 1/1/2000. A 64-bit float has 53 significant binary digits, so we're down to about 21 bits left for the fraction. This only gets us down to microsecond granularity.

The detectors probably won't get down to ns timing granularity, but they do go below microseconds. The main SNO+ trigger window, for instance, is 400ns, so if we cut the timestamp off at the microsecond level, it's possible to have two events with the same timestamp. That could be a problem if we have to do some elementary data reduction within snewpdag.

Anyway, I'll see if I can reduce the number of ways one must use (s,ns), or indeed nanoseconds. For instance, by adding methods which take floats instead of long ints.

That will be another PR, because I tangled up the git history a little and need to merge to straighten it out...