<commit_before>import os
import yaml
import ephem

from astropy import units as u
from astropy.coordinates import SkyCoord

import panoptes.utils.config as config
import panoptes.utils.logger as logger
import panoptes.utils.serial as serial
import panoptes.utils.error as error

@logger.has_logger
@config.has_config
class AbstractMount(object):

    """
    Abstract Base class for controlling a mount

    Methods to be implemented:
        - check_coordinates
        - sync_coordinates
        - slew_to_coordinates
        - slew_to_park
        - echo

    """

    def __init__(self,
                 config=dict(),
                 commands=dict(),
                 site=None,
                 connect_on_startup=True,
                 ):
        """
        Create a new mount class. Sets the following properies:

            - self.non_sidereal_available = False
            - self.PEC_available = False
            - self.is_initialized = False

        After setting, calls the following:

            - _setup_commands
            - _setup_site
        """

        # Create an object for just the mount config items
        self.mount_config = config if len(config) else dict()

        # Check the config for required items
        assert self.mount_config.get('port') is not None, self.logger.error('No mount port specified, cannot create mount\n {}'.format(self.mount_config))

        self.logger.info('Creating mount')

        # Setup commands for mount
        self.commands = self._setup_commands(commands)

        # We set some initial mount properties. May come from config
        self.non_sidereal_available = self.mount_config.setdefault('non_sidereal_available', False)
        self.PEC_available = self.mount_config.setdefault('PEC_available', False)

        # Initial states
        self.is_initialized = False
        self._is_slewing = False
        self._is_parked = False
        self._is_tracking = False

        self.site = site

        # Setup our serial connection at the given port
        self.port = self.mount_config.get('port')
        self.serial = serial.SerialData(port=self.port)

        # Set initial coordinates
        self._target_coordinates = None
        self._current_coordinates = None

        # Setup connection
        self.logger.info('connect_on_startup status: {}'.format(connect_on_startup))
        if connect_on_startup:
            self.initialize_mount()
            self._setup_site(site=self.site)

        self.logger.info('Mount created')

    def is_connected(self):
        """
        Checks the serial connection on the mount to determine if connection is open
        """
        self.logger.info('Mount is_connected: {}'.format(self.serial.is_connected))
        return self.serial.is_connected


    def is_slewing(self):
        """
        Class property that determines if mount is slewing.
        For some mounts, this is a built in function. For mount which do not have it we will have to
        write something based on how the coordinates are changing.
        """
        assert self.is_initialized, self.logger.warning('Mount has not been initialized, cannot check slewing')

        # Make sure response matches what it should for slewing
        if self.serial_query('is_slewing') == '1':
            self._is_slewing = True
        else:
            self._is_slewing = False

        self.logger.info('Mount is_slewing: {}'.format(self._is_slewing))
        return self._is_slewing

    def is_tracking(self):
        """
        Class property that determines if mount is tracking an object.
        """
        assert self._target_coordinates is not None, self.logger.warning("No target to track")

        # Make sure response matches what it should for parked
        if self.serial_query('is_tracking') == self._get_expected_response('is_tracking'):
            self._is_tracking = True
        else:
            self._is_tracking = False

        self.logger.info('Mount is_tracking: {}'.format(self._is_tracking))
        return self._is_tracking

    def is_parked(self):
        """
        Class property that determines if mount is parked.
        For some mounts, this is a built in function. For mount which do not have it we will have to
        write something based on how the coordinates are changing.
        """
        assert self.is_initialized, self.logger.warning('Mount has not been initialized, cannot check parked')

        # Make sure response matches what it should for parked
        if self.serial_query('is_parked') == self._get_expected_response('is_parked'):
            self._is_parked = True
        else:
            self._is_parked = False

        self.logger.info('Mount is_parked: {}'.format(self._is_parked))
        return self._is_parked


<<<<<<< HEAD
=======

>>>>>>> develop
    def get_target_coordinates(self):
        """
        Gets the RA and Dec for the mount's current target. This does NOT necessarily
        reflect the current position of the mount.

        @retval         astropy.coordinates.SkyCoord
        """

        if self._target_coordinates is None:
            self.logger.info("Target coordinates not set")
        else:
            self.logger.info('Mount target_coordinates: {}'.format(self._target_coordinates))

        return self._target_coordinates


    def set_target_coordinates(self, coords):
        """
        Sets the RA and Dec for the mount's current target. This does NOT necessarily
        reflect the current position of the mount.

        @retval         Boolean indicating success
        """
        target_set = False

<<<<<<< HEAD
        # Save the coordinates
        self._target_coordinates = coords

        # Send coordinates to mount

=======
        # Save the skycoord coordinates
        self._target_coordinates = coords

        # Get coordinate format from mount specific class
        mount_coords = self._skycoord_to_mount_coord(self._target_coordinates)

        # Send coordinates to mount
        try:
            self.serial_query('set_ra', mount_coords[0])
            self.serial_query('set_dec', mount_coords[1])
        except:
            self.logger.warning("Problem setting mount coordinates")
>>>>>>> develop

        return target_set


    def get_current_coordinates(self):
        """
        Reads out the current RA/Dec from the mount.

        @retval         astropy.coordinates.SkyCoord
        """
        self.logger.info('Mount current_coordinates')

        mount_ra = self.serial_query('get_ra')
        mount_dec = self.serial_query('get_dec')

        self._current_coordinates = self._mount_coord_to_skycoord(mount_ra, mount_dec)

        return self._current_coordinates


<commit_msg>Fixing merge conflict<commit_after>import os
import yaml
import ephem

from astropy import units as u
from astropy.coordinates import SkyCoord

import panoptes.utils.config as config
import panoptes.utils.logger as logger
import panoptes.utils.serial as serial
import panoptes.utils.error as error

@logger.has_logger
@config.has_config
class AbstractMount(object):

    """
    Abstract Base class for controlling a mount

    Methods to be implemented:
        - check_coordinates
        - sync_coordinates
        - slew_to_coordinates
        - slew_to_park
        - echo

    """

    def __init__(self,
                 config=dict(),
                 commands=dict(),
                 site=None,
                 connect_on_startup=True,
                 ):
        """
        Create a new mount class. Sets the following properies:

            - self.non_sidereal_available = False
            - self.PEC_available = False
            - self.is_initialized = False

        After setting, calls the following:

            - _setup_commands
            - _setup_site
        """

        # Create an object for just the mount config items
        self.mount_config = config if len(config) else dict()

        # Check the config for required items
        assert self.mount_config.get('port') is not None, self.logger.error('No mount port specified, cannot create mount\n {}'.format(self.mount_config))

        self.logger.info('Creating mount')

        # Setup commands for mount
        self.commands = self._setup_commands(commands)

        # We set some initial mount properties. May come from config
        self.non_sidereal_available = self.mount_config.setdefault('non_sidereal_available', False)
        self.PEC_available = self.mount_config.setdefault('PEC_available', False)

        # Initial states
        self.is_initialized = False
        self._is_slewing = False
        self._is_parked = False
        self._is_tracking = False

        self.site = site

        # Setup our serial connection at the given port
        self.port = self.mount_config.get('port')
        self.serial = serial.SerialData(port=self.port)

        # Set initial coordinates
        self._target_coordinates = None
        self._current_coordinates = None

        # Setup connection
        self.logger.info('connect_on_startup status: {}'.format(connect_on_startup))
        if connect_on_startup:
            self.initialize_mount()
            self._setup_site(site=self.site)

        self.logger.info('Mount created')

    def is_connected(self):
        """
        Checks the serial connection on the mount to determine if connection is open
        """
        self.logger.info('Mount is_connected: {}'.format(self.serial.is_connected))
        return self.serial.is_connected


    def is_slewing(self):
        """
        Class property that determines if mount is slewing.
        For some mounts, this is a built in function. For mount which do not have it we will have to
        write something based on how the coordinates are changing.
        """
        assert self.is_initialized, self.logger.warning('Mount has not been initialized, cannot check slewing')

        # Make sure response matches what it should for slewing
        if self.serial_query('is_slewing') == '1':
            self._is_slewing = True
        else:
            self._is_slewing = False

        self.logger.info('Mount is_slewing: {}'.format(self._is_slewing))
        return self._is_slewing

    def is_tracking(self):
        """
        Class property that determines if mount is tracking an object.
        """
        assert self._target_coordinates is not None, self.logger.warning("No target to track")

        # Make sure response matches what it should for parked
        if self.serial_query('is_tracking') == self._get_expected_response('is_tracking'):
            self._is_tracking = True
        else:
            self._is_tracking = False

        self.logger.info('Mount is_tracking: {}'.format(self._is_tracking))
        return self._is_tracking

    def is_parked(self):
        """
        Class property that determines if mount is parked.
        For some mounts, this is a built in function. For mount which do not have it we will have to
        write something based on how the coordinates are changing.
        """
        assert self.is_initialized, self.logger.warning('Mount has not been initialized, cannot check parked')

        # Make sure response matches what it should for parked
        if self.serial_query('is_parked') == self._get_expected_response('is_parked'):
            self._is_parked = True
        else:
            self._is_parked = False

        self.logger.info('Mount is_parked: {}'.format(self._is_parked))
        return self._is_parked


    def get_target_coordinates(self):
        """
        Gets the RA and Dec for the mount's current target. This does NOT necessarily
        reflect the current position of the mount.

        @retval         astropy.coordinates.SkyCoord
        """

        if self._target_coordinates is None:
            self.logger.info("Target coordinates not set")
        else:
            self.logger.info('Mount target_coordinates: {}'.format(self._target_coordinates))

        return self._target_coordinates


    def set_target_coordinates(self, coords):
        """
        Sets the RA and Dec for the mount's current target. This does NOT necessarily
        reflect the current position of the mount.

        @retval         Boolean indicating success
        """
        target_set = False

        # Save the skycoord coordinates
        self._target_coordinates = coords

        # Get coordinate format from mount specific class
        mount_coords = self._skycoord_to_mount_coord(self._target_coordinates)

        # Send coordinates to mount
        try:
            self.serial_query('set_ra', mount_coords[0])
            self.serial_query('set_dec', mount_coords[1])
        except:
            self.logger.warning("Problem setting mount coordinates")

        return target_set


    def get_current_coordinates(self):
        """
        Reads out the current RA/Dec from the mount.

        @retval         astropy.coordinates.SkyCoord
        """
        self.logger.info('Mount current_coordinates')

        mount_ra = self.serial_query('get_ra')
        mount_dec = self.serial_query('get_dec')

        self._current_coordinates = self._mount_coord_to_skycoord(mount_ra, mount_dec)

        return self._current_coordinates



{'fraction_non_alphanumeric': 0.07847567404729627, 'fraction_numerical': 0.00045187528242205153, 'mean_word_length': 2.3272362816336756, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4191638', 'n_tokens_mistral': 3563, 'n_tokens_neox': 3412, 'n_words': 1037}