Example #1
0
def session_options(parser, x_short_opts=[], x_long_opts=[]):
    # Add options from katcorelib that is valid for all observations
    group = parser.add_argument_group(title="\
standard MeerKAT options",
                                      description="\
default observation script options")
    if live_system:
        parser_ = standard_script_options('', '')
        # fudge parser_ class from OptionParser to Group
        for opt in parser_.option_list:
            # Disregarding options we don't want in the group
            long_ = opt.__dict__['_long_opts'][0]
            if long_ in x_long_opts:
                continue
            args = opt.__dict__['_long_opts']
            if opt.__dict__['_short_opts']:
                short = opt.__dict__['_short_opts'][0]
                if short in x_short_opts:
                    continue
                args = opt.__dict__['_short_opts'] + args

            kwargs = {
                'dest':
                opt.__dict__['dest'],
                'type':
                type(opt.__dict__['default'])
                if type(opt.__dict__['default']) != tuple else None,
                'default':
                opt.__dict__['default']
                if type(opt.__dict__['default']) != tuple else None,
                'nargs':
                opt.__dict__['nargs'] if opt.__dict__['nargs'] != 1 else None,
                'metavar':
                opt.__dict__['metavar'] if not opt.__dict__['choices'] else '',
                'choices':
                opt.__dict__['choices'],
                'action':
                opt.__dict__['action']
                if opt.__dict__['action'] != 'store_true' else None,
                'const':
                opt.__dict__['const']
                if opt.__dict__['action'] == 'store_const' else None,
                'help':
                opt.__dict__['help'].replace("%default", "%(default)s")
                if long_ != '--quorum' else opt.__dict__['help'].replace(
                    "%", "%%"),
                'required':
                True if '**required**' in opt.__dict__['help'] else False,
            }

            group.add_argument(*args, **kwargs)
    else:
        group.add_argument('--horizon',
                           type=float,
                           default=20,
                           help='\
lowest elevation limit in degrees')
    return parser
        #    break
        set_att(kat, inputs, new_att)
        # Wait until power has stabilised before making the next measurement
        time.sleep(wait)
        # Obtain latest measurements on the last iteration
        if n == 4:
            att = get_att(kat, inputs)
            power = get_dbe_input_power(kat, inputs, dbe)
    return att, power


############################### Main script ###################################

# Set up standard script options
parser = standard_script_options(
    usage="%prog [opts]",
    description="This automatically adjusts RFE5 and RFE7 attenuator settings "
    "to achieve optimal power levels. Some options are **required**.")

# Add extra command-line opts and arguments
parser.add_option(
    '-t',
    '--target',
    default='',
    help=
    "Radio source on which to calibrate the attenuators (default='%default'). "
    + "Won't drive antennas if not set.")
parser.add_option('--rfe5-desired',
                  type='float',
                  dest='rfe5_desired_power',
                  default=-47.0,
                  help='Desired RFE5 output power, in dBm (default=%default).')
Example #3
0
    for (ant_name, pol), value in zip(inputs, inputs_attenuation):
        # This assumes that antenna names have the format 'antx', where x is an integer (the antenna number)
        ant_num = int(ant_name.strip()[3:])
        kat.rfe7.req.rfe7_downconverter_attenuation(str(ant_num), pol, value)


################################ DBE getters ##################################

connected_antpols = {}

############################### Main script ###################################

# Parse command-line opts and arguments
parser = standard_script_options(
    usage="%prog [opts]",
    description=
    "This automatically max's out  RFE5 and RFE7 attenuator settings "
    "to achieve safe levels for work on the antenna. Some options are **required**."
)

# Parse the command line
opts, args = parser.parse_args()
# The standard option verification routine below requires this option (otherwise ignored)
opts.observer = 'Max Attenuator'

with verify_and_connect(opts) as kat:

    # Create device array of antennas, based on specification string
    ants = kat.ants  #ant_array(kat, opts.ants)
    user_logger.info('Using antennas: %s' %
                     (' '.join([ant.name for ant in ants]), ))
from katcorelib.observe import (standard_script_options, verify_and_connect,
                                collect_targets, start_session, user_logger)


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


# Default F-engine gain as a function of number of channels
DEFAULT_GAIN = {1024: 116, 4096: 70, 32768: 360}

# Set up standard script options
usage = "%prog [options] <'target/catalogue'> [<'target/catalogue'> ...]"
description = 'Observe a bandpass calibrator to establish some ' \
              'basic health properties of the MeerKAT system.'
parser = standard_script_options(usage, description)
# Add experiment-specific options
parser.add_option('--verify-duration',
                  type='float',
                  default=64.0,
                  help='Length of time to revisit source for verification, '
                  'in seconds (default=%default)')
parser.add_option(
    '--fengine-gain',
    type='int',
    default=0,
    help='Override correlator F-engine gain (average magnitude), '
    'using the default gain value for the mode if 0')
# Set default value for any option (both standard and experiment-specific options)
parser.set_defaults(observer='basic_health',
                    nd_params='off',
Example #5
0
def session_options(parser, short_opts_to_remove=[], long_opts_to_remove=[]):
    """Add options from katcorelib that are valid for all observations.

    Parameters
    ----------
    parser: `optparse.OptionParser`
        Parser populated with standard script options
    short_opts_to_remove: list
        Previous short observation command line options to discard
    long_opts_to_remove: list
        Previous long observation command line options to discard

    Returns
    -------
    parser: `optparse.OptionParser`
        Parser populated with standard script options

    """
    dryrun = False
    group = parser.add_argument_group(
        title="Standard MeerKAT options",
        description="Default observation script options",
    )
    if live_system:
        parser_ = standard_script_options("", "")
        # fudge parser_ class from OptionParser to Group
        for opt in parser_.option_list:
            # Disregarding options we don't want in the group
            long_ = opt.__dict__["_long_opts"][0]
            if "dry-run" in long_:
                dryrun = True
                continue
            if long_ in long_opts_to_remove:
                continue
            args = opt.__dict__["_long_opts"]
            if opt.__dict__["_short_opts"]:
                short = opt.__dict__["_short_opts"][0]
                if short in short_opts_to_remove:
                    continue
                args = opt.__dict__["_short_opts"] + args

            kwargs = {
                "dest":
                opt.__dict__["dest"],
                "type":
                type(opt.__dict__["default"])
                if not isinstance(opt.__dict__["default"], tuple) else None,
                "default":
                opt.__dict__["default"]
                if not isinstance(opt.__dict__["default"], tuple) else None,
                "nargs":
                opt.__dict__["nargs"] if opt.__dict__["nargs"] != 1 else None,
                "metavar":
                opt.__dict__["metavar"] if not opt.__dict__["choices"] else "",
                "choices":
                opt.__dict__["choices"],
                "action":
                opt.__dict__["action"]
                if opt.__dict__["action"] != "store_true" else None,
                "const":
                opt.__dict__["const"]
                if opt.__dict__["action"] == "store_const" else None,
                "help":
                opt.__dict__["help"].replace("%default", "%(default)s")
                if long_ != "--quorum" else opt.__dict__["help"].replace(
                    "%", "%%"),
                "required":
                True if "**required**" in opt.__dict__["help"] else False,
            }

            group.add_argument(*args, **kwargs)

    # something goes wrong in this conversion for opts to args
    # adding this manually
    if dryrun:
        group.add_argument("--dry-run", action="store_true")
    return parser
Example #6
0

def reset_defaults(kat, defaults):
    # reset system to default setting as specified by commands above
    for _checker, _default, setter in defaults:
        try:
            eval(setter)
        except Exception, err:
            print "Cannot set - ", setter, "ERROR :", err


if __name__ == "__main__":

    parser = standard_script_options(
        usage="%prog [options]",
        description=
        "Check the system against the expected default values and optionally reset to these defaults."
    )
    parser.add_option('--defaults_set',
                      default="karoo",
                      metavar='DEFAULTS',
                      help='Selected defaults set to use, ' +
                      '|'.join(defaults_set.keys()) + ' (default="%default")')
    parser.add_option(
        '--reset',
        action='store_true',
        default=False,
        help=
        'Reset system to default values, if this switch is included (default="%default")'
    )
    (opts, args) = parser.parse_args()
Example #7
0
#from katcorelib import ant_array,standard_script_options, verify_and_connect, collect_targets, start_session, user_logger
import katpoint
import pickle
import numpy as np
import StringIO
import logging 
#import fbf_katcp_wrapper as fbf



# read the bandpass solutions from a pickle file
raw_data,bpass_h,bpass_v=pickle.load(open('/home/kat/comm/scripts/bpass.pikl'))

# Set up standard script options
parser = standard_script_options(usage="%prog [options] <'target/catalogue'> [<'target/catalogue'> ...]",
                                 description='Track one or more sources for a specified time. At least one '
                                             'target must be specified. Note also some **required** options below.')
# Add experiment-specific options
#parser.add_option('--project-id',
#                  help='Project ID code the observation (**required**) This is a required option')
parser.add_option('-t', '--track-duration', type='float', default=60.0,
                  help='Length of time to track each source, in seconds (default=%default)')
parser.add_option('-m', '--max-duration', type='float', default=None,
                  help='Maximum duration of the script in seconds, after which script will end '
                       'as soon as the current track finishes (no limit by default)')
parser.add_option('--repeat', action="store_true", default=False,
                  help='Repeatedly loop through the targets until maximum duration (which must be set for this)')
parser.add_option('--reset', action="store_true", default=False,
                          help='Reset the gains to 160.')
parser.add_option('--half-band', action='store_true', default=True,
                          help='Use only inner 50% of output band')