Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions observation/phase_down.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python
#
# Reset the delay adjustments and CBF F-engine gains to zero.

import time

import numpy as np
import katpoint
from katcorelib.observe import (standard_script_options, verify_and_connect,
collect_targets, start_session, user_logger,
SessionSDP)

class NoTargetsUpError(Exception):
"""No targets are above the horizon at the start of the observation."""

# Set up standard script options
usage = "%prog"
description = 'Reset all the delays and phases to default.'
parser = standard_script_options(usage, description)
# Add experiment-specific options

# Set default value for any option (both standard and experiment-specific options)
parser.set_defaults(observer='comm_test', nd_params='off', project_id='COMMTEST',
description='Phase-up observation that sets the F-engine weights')
# Parse the command line
opts, args = parser.parse_args()

# Set of targets with flux models
J1934 = 'PKS 1934-63 | J1939-6342, radec, 19:39:25.03, -63:42:45.7, (200.0 12000.0 -11.11 7.777 -1.231)'
J0408 = 'PKS 0408-65 | J0408-6545, radec, 4:08:20.38, -65:45:09.1, (800.0 8400.0 -3.708 3.807 -0.7202)'
J1331 = '3C286 | J1331+3030, radec, 13:31:08.29, +30:30:33.0,(800.0 43200.0 0.956 0.584 -0.1644)'

observation_sources = katpoint.Catalogue(antenna=kat.sources.antenna)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kat object hasn't been assigned yet. Looks like this block needs to move down, after line 41.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As below, I would suggest to follow calibrate_delays.py as a template. We have removed these explicit sources in the code and replaced them with the three_calib.csv file in the instruction set. The whole catalogue construction also moves down to after verify_and_connect as @ajoubertza suggests. I also pick only a single source as opposed to looping through a list containing one source.

observation_sources.add(J1934)
observation_sources.add(J0408)
observation_sources.add(J1331)

if len(observation_sources.filter(el_limit_deg=opts.horizon)) == 0:
raise NoTargetsUpError("No targets are currently visible - please re-run the script later")

with verify_and_connect(opts) as kat:
with start_session(kat, **vars(opts)) as session:
session.standard_setup(**vars(opts))
session.cbf.correlator.req.capture_start()
channels = 32768 if session.product.endswith('32k') else 4096
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this check is used in other scripts, but it isn't very robust. E.g. for a user product like c856M32k4s or bec856M32kram. There is a CBF sensor that gives the number of channels, so suggest that is used instead. Think you can use it like this: channels = session.cbf.fengine.sensor.n_chans

@ludwigschwardt, please confirm that is the correct way to use the SessionCBFStream object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. My best suggestions would be to look at calibrate_delays.py as that is the most up-to-date cal/cbf-interacting script. There is a function that you can copy (and which should move into CaptureSession now that there is more than one user :-)):

# Default F-engine gain as a function of number of channels
DEFAULT_GAIN = {4096: 200, 32768: 4000}

def set_fengine_gain(session, gain):
    """Set F-engine gain to *gain* if positive, or automatic default if 0."""
    if session.kat.dry_run:
        gain = -1
    # Obtain default gain based on channel count if none specified
    if gain == 0:
        num_channels = session.cbf.fengine.sensor.n_chans.get_value()
        gain = DEFAULT_GAIN.get(num_channels, -1)
    if gain > 0:
        user_logger.info("Setting F-engine gains to %d" % (gain,))
        for inp in session.cbf.fengine.inputs:
            session.cbf.fengine.req.gain(inp, gain)

if channels == 4096:
default_gain = 200
elif channels == 32768:
default_gain = 4000
user_logger.info("Resetting F-engine gains to %g", default_gain)
for inp in session.cbf.fengine.inputs:
session.cbf.fengine.req.gain(inp, default_gain)
user_logger.info("Resetting delay adjustments to zero")
session.cbf.req.adjust_all_delays()

track_duration = 24
for target in [observation_sources.sort('el').targets[-1]]:
user_logger.info("Initiating %g-second track on target '%s' to validate reset",
track_duration, target.name)
session.track(target, duration=track_duration, announce=False)