Exemple #1
0
 def __exit__(self, type, value, traceback):
     user_logger.info('Returning telescope to startup state')
     # Ensure known exit state before quitting
     # TODO: Return correlator settings to entry values
     # switch noise-source pattern off (ensure this after each observation)
     noisediode.off(self.array)
     self.array.disconnect()
 def __exit__(self, type, value, traceback):
     """Return telescope to its startup state."""
     user_logger.info("Observation clean up")
     user_logger.info("Returning telescope to startup state")
     # Ensure known exit state before quitting
     # TODO: Return correlator settings to entry values
     # switch noise-source pattern off (ensure this after each observation)
     # if NaN returned at off command, allow to continue
     noisediode.off(self.array, allow_ts_err=True)
     self.array.disconnect()
    def __enter__(self):
        """Verify subarray setup correct for observation before doing any work."""
        user_logger.info("Observation start up")
        user_logger.info("Running astrokat version - %s", astrokat.__version__)
        obs_plan_params = self.opts.obs_plan_params
        if "instrument" in obs_plan_params:
            self.subarray_setup(obs_plan_params["instrument"])

        # TODO: noise diode implementations should be moved to sessions
        # switch noise-source pattern off (known setup starting observation)
        noisediode.off(self.array)

        # TODO: update correlator settings
        # TODO: names of antennas to use for beamformer if not all is desirable
        return self
Exemple #4
0
    def __enter__(self):
        # Verify subarray setup correct for observation before doing any work
        if 'instrument' in self.opts.obs_plan_params.keys():
            self.subarray_setup(self.opts.obs_plan_params['instrument'])

        # TODO: noise diode implementations should be moved to sessions
        # Ensure default setup before starting observation
        # switch noise-source pattern off (known setup starting observation)
        noisediode.off(self.array)

        # TODO: add part that implements noise diode fire per track
        # TODO: move this to a callable function, so do it only if worth while to observe and move back to body with session
        #         # Update correlator settings
        #         if self.feng is not None:
        #             set_fengines(self.session,
        #                          requant_gains=self.feng['requant_gain'],
        #                          fft_shift=self.feng['fft_shift'],
        #                          )
        # #         # Names of antennas to use for beamformer if not all is desirable
        # #         set_bf_weights(self.array, opts.bf_ants, opts.bf_weights)
        #         # keep restore_values
        return self
def observe(session, ref_antenna, target_info, **kwargs):
    """Target observation functionality.

    Parameters
    ----------
    session: `CaptureSession`
    target_info:

    """
    target_visible = False

    target_name = target_info["name"]
    target = target_info["target"]
    duration = target_info["duration"]
    obs_type = target_info["obs_type"]

    # update (Ra, Dec) for horizontal coordinates @ obs time
    if ("azel" in target_info["target_str"]) and ("radec" in target.tags):
        tgt_coord = target_info["target_str"].split('=')[-1].strip()
        ra_hms, dec_dms = _get_radec_from_azel(ref_antenna.observer, tgt_coord,
                                               time.time())

        target.body._ra = ra_hms
        target.body._dec = dec_dms

    # simple way to get telescope to slew to target
    if "slewonly" in kwargs:
        return session.track(target, duration=0.0, announce=False)

    # set noise diode behaviour
    nd_setup = None
    nd_lead = None
    if kwargs.get("noise_diode"):
        nd_setup = kwargs["noise_diode"]
        # user specified lead time
        if "lead_time" in nd_setup:
            nd_lead = nd_setup['lead_time']
        # not a ND pattern
        if "cycle_len" not in nd_setup:
            nd_setup = None

    # implement target specific noise diode behaviour
    nd_period = None
    nd_restore = False
    if target_info["noise_diode"] is not None:
        if "off" in target_info["noise_diode"]:
            user_logger.info('Observation: No ND for target')
            nd_restore = True
            # disable noise diode pattern for target
            noisediode.off(session.kat, lead_time=nd_lead)
        else:
            nd_period = float(target_info["noise_diode"])

    msg = "Initialising {} {} {}".format(obs_type.capitalize(),
                                         ", ".join(target.tags[1:]),
                                         target_name)
    if not np.isnan(duration):  # scan types do not have durations
        msg += " for {} sec".format(duration)
    if np.isnan(duration) or duration > 1:
        user_logger.info(msg)

    # do the different observations depending on requested type
    session.label(obs_type.strip())
    user_logger.trace("TRACE: performing {} observation on {}".format(
        obs_type, target))
    if "drift_scan" in obs_type:
        target_visible = scans.drift_scan(session,
                                          ref_antenna,
                                          target,
                                          duration=duration,
                                          nd_period=nd_period,
                                          lead_time=nd_lead)
    elif "scan" in obs_type:  # compensating for ' and spaces around key values
        if "raster_scan" in obs_type:
            if ("raster_scan"
                    not in kwargs.keys()) or ("num_scans"
                                              not in kwargs["raster_scan"]):
                raise RuntimeError("{} needs 'num_scans' parameter".format(
                    obs_type.capitalize()))
            nscans = float(kwargs["raster_scan"]["num_scans"])
            if "scan_duration" not in kwargs["raster_scan"]:
                kwargs["raster_scan"]["scan_duration"] = duration / nscans
        else:
            if 'scan' not in kwargs.keys():
                kwargs['scan'] = {'duration': duration}
            else:
                kwargs['scan']['duration'] = duration
        # TODO: fix raster scan and remove this scan hack
        if "forwardscan" in obs_type:
            scan_func = scans.forwardscan
            obs_type = "scan"
        elif "reversescan" in obs_type:
            scan_func = scans.reversescan
            obs_type = "scan"
        elif "return_scan" in obs_type:
            scan_func = scans.return_scan
            obs_type = "scan"
        elif "raster_scan" in obs_type:
            scan_func = scans.raster_scan
        else:
            scan_func = scans.scan
        target_visible = scan_func(session,
                                   target,
                                   nd_period=nd_period,
                                   lead_time=nd_lead,
                                   **kwargs[obs_type])

    else:  # track is default
        if nd_period is not None:
            user_logger.trace("TRACE: ts before nd trigger"
                              "{} for {}".format(time.time(), nd_period))
            noisediode.trigger(session.kat,
                               duration=nd_period,
                               lead_time=nd_lead)
            user_logger.trace("TRACE: ts after nd trigger {}".format(
                time.time()))
        user_logger.debug("DEBUG: Starting {}s track on target: "
                          "{} ({})".format(duration, time.time(),
                                           time.ctime(time.time())))
        if session.track(target, duration=duration):
            target_visible = True
    user_logger.trace("TRACE: ts after {} {}".format(obs_type, time.time()))

    if (nd_setup is not None and nd_restore):
        # restore pattern if programmed at setup
        user_logger.info('Observation: Restoring ND pattern')
        noisediode.pattern(
            session.kat,
            nd_setup,
            lead_time=nd_lead,
        )

    return target_visible
Exemple #6
0
def observe(session, target_info, **kwargs):
    """Target observation functionality.

    Parameters
    ----------
    session: `CaptureSession`
    target_info:

    """
    target_visible = False

    target_name = target_info["name"]
    target = target_info["target"]
    duration = target_info["duration"]
    obs_type = target_info["obs_type"]

    # simple way to get telescope to slew to target
    if "slewonly" in kwargs:
        return session.track(target, duration=0.0, announce=False)

    # set noise diode behaviour
    nd_setup = None
    nd_lead = _DEFAULT_LEAD_TIME
    if kwargs.get("noise_diode"):
        nd_setup = kwargs["noise_diode"]
        # user specified lead time
        if "lead_time" in nd_setup:
            nd_lead = nd_setup['lead_time']
        # not a ND pattern
        if "cycle_len" not in nd_setup:
            nd_setup = None

    # implement target specific noise diode behaviour
    nd_period = None
    nd_restore = False
    if target_info["noise_diode"] is not None:
        if "off" in target_info["noise_diode"]:
            user_logger.info('Observation: No ND for target')
            nd_restore = True
            # disable noise diode pattern for target
            noisediode.off(session.kat, lead_time=nd_lead)
        else:
            nd_period = float(target_info["noise_diode"])

    msg = "Initialising {} {} {}".format(obs_type.capitalize(),
                                         ", ".join(target.tags[1:]),
                                         target_name)
    if not np.isnan(duration):  # scan types do not have durations
        msg += " for {} sec".format(duration)
    if np.isnan(duration) or duration > 1:
        user_logger.info(msg)

    # do the different observations depending on requested type
    session.label(obs_type.strip())
    user_logger.trace("TRACE: performing {} observation on {}".format(
        obs_type, target))
    if "scan" in obs_type:  # compensating for ' and spaces around key values
        if "drift_scan" in obs_type:
            scan_func = scans.drift_scan
        # TODO: fix raster scan and remove this scan hack
        elif "forwardscan" in obs_type:
            scan_func = scans.forwardscan
            obs_type = "scan"
        elif "reversescan" in obs_type:
            scan_func = scans.reversescan
            obs_type = "scan"
        elif "return_scan" in obs_type:
            scan_func = scans.return_scan
            obs_type = "scan"
        elif "raster_scan" in obs_type:
            scan_func = scans.raster_scan
        else:
            scan_func = scans.scan
        if obs_type in kwargs:  # user settings other than defaults
            target_visible = scan_func(session,
                                       target,
                                       nd_period=nd_period,
                                       **kwargs[obs_type])
        else:
            target_visible = scan_func(session, target, nd_period=nd_period)
    else:  # track is default
        if nd_period is not None:
            user_logger.trace("TRACE: ts before nd trigger"
                              "{} for {}".format(time.time(), nd_period))
            noisediode.trigger(session.kat,
                               duration=nd_period,
                               lead_time=nd_lead)
            user_logger.trace("TRACE: ts after nd trigger {}".format(
                time.time()))
        user_logger.debug("DEBUG: Starting {}s track on target: "
                          "{} ({})".format(duration, time.time(),
                                           time.ctime(time.time())))
        if session.track(target, duration=duration):
            target_visible = True
    user_logger.trace("TRACE: ts after {} {}".format(obs_type, time.time()))

    if (nd_setup is not None and nd_restore):
        # restore pattern if programmed at setup
        user_logger.info('Observation: Restoring ND pattern')
        noisediode.pattern(
            session.kat,
            nd_setup,
            lead_time=nd_lead,
        )

    return target_visible
Exemple #7
0
def observe(session, target_info, **kwargs):
    target_visible = False

    target_name = target_info['name']
    target = target_info['target']
    duration = target_info['duration']
    obs_type = target_info['obs_type']

    # simple way to get telescope to slew to target
    if 'slewonly' in kwargs:
        return session.track(target, duration=0., announce=False)

    msg = 'Initialising {} {} {}'.format(obs_type.capitalize(), target.tags[1],
                                         target_name)
    if not np.isnan(duration):  # scan types do not have durations
        msg += ' for {} sec'.format(duration)
    if np.isnan(duration) or duration > 1:
        user_logger.info(msg)

    # implement target specific noise diode behaviour
    nd_setup = None
    nd_period = None
    if target_info['noise_diode'] is not None:
        if 'off' in target_info['noise_diode']:
            # if pattern specified, remember settings to reset
            if 'noise_diode' in kwargs:
                if kwargs['noise_diode'] is not None:
                    nd_setup = kwargs['noise_diode']
            # disable noise diode pattern for target
            noisediode.off(session.kat)
        else:
            nd_period = float(target_info['noise_diode'])

    # do the different observations depending on requested type
    session.label(obs_type.strip())
    user_logger.trace('TRACE: performing {} observation on {}'.format(
        obs_type, target))
    if 'scan' in obs_type:  # compensating for ' and spaces around key values
        if 'drift_scan' in obs_type:
            scan_func = scans.drift_scan
        # TODO: fix raster scan and remove this scan hack
        elif 'forwardscan' in obs_type:
            scan_func = scans.forwardscan
            obs_type = 'scan'
        elif 'reversescan' in obs_type:
            scan_func = scans.reversescan
            obs_type = 'scan'
        elif 'return_scan' in obs_type:
            scan_func = scans.return_scan
            obs_type = 'scan'
        elif 'raster_scan' in obs_type:
            scan_func = scans.raster_scan
        else:
            scan_func = scans.scan
        if obs_type in kwargs:  # user settings other than defaults
            target_visible = scan_func(session,
                                       target,
                                       nd_period=nd_period,
                                       **kwargs[obs_type])
        else:
            target_visible = scan_func(session, target, nd_period=nd_period)
    else:  # track is default
        if nd_period is not None:
            user_logger.trace('TRACE: ts before nd trigger {} for {}'.format(
                time.time(), nd_period))
            noisediode.trigger(session.kat, session, duration=nd_period)
            user_logger.trace('TRACE: ts after nd trigger {}'.format(
                time.time()))
        user_logger.debug(
            'DEBUG: Starting {}s track on target: {} ({})'.format(
                duration, time.time(), time.ctime(time.time())))
        if session.track(target, duration=duration):
            target_visible = True
    user_logger.trace('TRACE: ts after {} {}'.format(obs_type, time.time()))

    if nd_setup is not None:
        # restore pattern if programmed at setup
        noisediode.pattern(session.kat, session, nd_setup)

    return target_visible