-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/block offsets #550
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me but someone with RNO-G data expertise should also have a look and check/test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I think it can be merged, since it is standalone... not sure why the doc checks fail.
- 'fit' (default): fit the block offsets with a minimizer | ||
- 'approximate' : use the first guess from the out-of-band component, | ||
without any fitting (slightly faster) | ||
- 'stored': use the block offsets already stored in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you simulate the block offsets would you not simulated it on a sim_station
? Hence, the station would not have this parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'stored' option is probably superfluous, but I thought maybe one might want to undo the block offsets that have already been removed by e.g. the external calibration, or allow for some other fit to compute the block offsets.
In terms of simulation, right now we don't simulate the block offsets anyway, and because e.g. the timings are different I'm not sure how straightforward it would be to simulate them for the sim_station
(rather than for the station
, which is what I've been doing so far). Even if we end up doing this for the sim_station
, I'd be inclined to leave it to the user to retrieve the simulated parameter from the sim_station
to keep a cleaner separation between the two.
filtered_trace = fft.freq2time(filtered_trace_fft, sampling_rate) | ||
|
||
# obtain guesses for block offsets | ||
a_guess = np.array([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not relevant but using np.split
seems to be a bit faster
In [17]: %timeit np.mean(np.split(filtered_trace, n_blocks), axis=1)
19 µs ± 849 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
In [18]: %timeit a_guess = np.array([np.mean(filtered_trace[i*block_size:(i+1)*block_size]) for i in range(n_blocks)])
32.4 µs ± 1.17 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you ever check what the difference is when you use the unfiltered trace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, implemented (though I agree I don't think this was the bottleneck). Using the unfiltered trace is a little bit faster but gives a ~4 times larger RMS difference between true and fitted block offset
Damn, I did not know that I had to submit my comments/review. Sorry Sjoerd that those come so late (they were written a week ago) |
I fixed (hopefully) Felix's comments, and additionally added the fitter to the mattak datareader. A quick comparison of how fast the different options are:
Giving
Both 'approximate' and 'median' (= the previous implementation in the reader) are probably good enough for most purposes. |
What happens if you relax the |
return wfs - baseline_traces | ||
|
||
blockoffsetfitter = channelBlockOffsets() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That that here in between functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made it a private attribute of the readRNOGData
class, having readRNOGDataMattak.blockoffsetfitter
showing up in IDE autocompletion is probably unnecessary clutter.
Deprecating the old code is fine for me. However, I am still wondering a bit why it is not significant faster than the bandpass-filtered 'approximate' mode. After all this includes running an fft which should be quite time consuming compared to the other mathematical operations ? |
PS: An improvement with a factor of 100 in performance is never a waist of time :) |
@fschlueter Sorry, created a merge conflict for myself by removing all trailing whitespaces in #557, I've now turned that feature off again in my IDE. Nothing else should have changed. |
I am using a VS code plugin which should just remove ws in lines which I have modified anyway (its not working as promised but if you find one which works let me know) |
I just merged it. Did not feel like waiting longer .. |
Hmm, reading the history here, @fschlueter may just have avoided (but just barely :) ) the three strikes rule of only merging after 24 hours after final approval. It has been taking long enough, I concur. |
😇 |
(Finally) - added a module that can add or remove 'block offsets' as seen in the voltage traces recorded by RNO-G. The fit is done by assuming a repeating rect shape, and fitting this in the Fourier domain, outside the band where the antennas/amplifiers are expected to be sensitive to real signals.
I also added an additional
channelParameter
that stores the added/removed block offsets; maybe this can be used for the RNOG data reader in the future to ensure that the correction remains reversible. We can also consider adding (some version of) this module in the RNO-G data reader, while we're still waiting for the integration of the equivalent code on the DAQ side, although it's probably worth making sure first that the performance impact of the fitting and/or Fourier transforms is not too high.