Skip to content
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

Don't wait too long for gains to materialise #253

Merged
merged 7 commits into from
Oct 24, 2017

Conversation

ludwigschwardt
Copy link
Contributor

This PR is a bit of a mish-mash, mandated by available telescope time...

The main aim is to reduce the amount of time spent waiting for cal products to materialise in telstate. Ever since katsdptelstate PR #39 telstate allows timestamps to be checked in its wait_key method, which allows the script to wait until a fresh cal product arrives. The script therefore waits for the last expected cal product with a worst-case timeout, but should return as soon as possible. Standardise the telstate interactions between the various scripts (bf_phaseup / calibrate_delays / basic_health / reference_pointing). This addresses JIRA ticket SR-965.

The secondary aim is to flatten the bandpass amplitudes during phaseup. This builds on the new --flatten-bandpass option introduced by #252. That change showed that it was necessary to interpolate bandpass gains across NaNs representing flagged channels, instead of merely setting NaNs to 1.0 which introduces step changes in amplitude and phase. Use the simplistic linear interpolation provided by np.interp as it is reasonably robust. This addresses JIRA ticket SR-956.

A last minor change is the removal of the basic_health.py script still lurking in the utility directory. It has moved to observation a while ago.

This allows the script to continue as soon as the cal pipeline products
materialise in telstate, instead of sleeping for the worst case time.
Consolidate all product retrievals in a single routine (DRY).

Use the same delaycal routine for both phaseup and calibrate_delays,
and resign ourselves to the fact that katsdpcal will forever have delay
solutions with the wrong sign (which at least makes interpretation of
historic solutions sane).

This addresses JIRA ticket SR-965.
The script has moved back to observation as it actually captures data
and puts data products into the archive, and that version is now more
up to date.
The solution extractors in reference_pointing are slightly different
to the phaseup family as it is based on explicit start and end times.
There is probably some benefit to merge the two approaches in future,
but for now simply wait for the last piece of the puzzle.
Stub this out to pass through dry-running (rather add wait to
TimeSession next time around...).
When the cal pipeline encounters completely flagged channels (typically
the static RFI mask) it returns bandpass gains that are NaNs in those
channels. No-one likes NaNs though, especially not the correlator.
The existing scheme replaced them with gains of 1.0 + 0.0j, which is
quite arbitrary. This caused step changes in the bandpass amplitude
and phase, which had been ignored until Mattieu recently introduced the
--flatten-bandpass option.

The new solution uses rudimentary linear interpolation across the
flagged regions via np.interp (which works on complex values too and
interpolates real + imag separately as far as I can tell). In addition,
if all channels are flagged for some reason, ignore the bandpass gains
for that input.

This addresses JIRA ticket SR-956.
@ludwigschwardt ludwigschwardt merged commit 1c05173 into master Oct 24, 2017
@ludwigschwardt ludwigschwardt deleted the SR-965/make-waiting-on-telstate-more-efficient branch October 24, 2017 08:57
ludwigschwardt added a commit that referenced this pull request Feb 18, 2019
Some history first...

The original phase-up script had a fixed magnitude for the F-engine
gains (aka gain corrections) that was constant for all inputs and
frequency channels (let's say 70 for the purpose of this commit
message). It really only adjusted the phases per input and per channel
to phase up the beamformer:

  (1)  corrections = 70 * abs(gains) / gains

The first version of --flatten-bandpass (#252, #253, Oct 2017) had

  (2)  corrections = 70 / gains

which flattened the bandpass magnitude but unfortunately also introduced
an arbitrary scaling, since the gains have the arbitrary units of
sqrt(Jy / count). This caused clipping and/or quantisation loss on some
F-engine outputs.

The next version of --flatten-bandpass (#331 redone as #335, Nov 2018)
addressed this by normalising by the mean gain over the band per input:

  (3)  corrections = 70 * average_over_frequency(gains) / gains

While this removed all the bumps in the bandpass of each input, it left
the average correction magnitude stuck at 70 for all inputs, thereby not
equalising the average gain per input. This leads to some H / V mismatch
as well as potential correlator / beamformer inefficiency.

The proposed change addresses this equalisation issue. The gain
correction calculation is collected in its own function to clean up
the main script flow and allow simpler testing. The average gain is now
calculated over all inputs and all frequency channels, using a more
robust succession of medians that ignore flagged gains, as

  (4)  corrections = 70 * global_average(gains) / gains

The average (relative) gain per input is also reported as a diagnostic,
and the script refuses to continue if all the corrections will be zero
(which implies zero signal out of the beamformer).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants