<commit_before>import re

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

from panoptes.mount.mount import AbstractMount
import panoptes.utils.logger as logger
import panoptes.utils.error as error

@logger.set_log_level('debug')
@logger.has_logger
class Mount(AbstractMount):

    """
    iOptron mounts
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self._ra_format = re.compile('(?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})')
        self._dec_format = re.compile('(?P<sign>[\+\-])(?P<degree>\d{2})\*(?P<minute>\d{2}):(?P<second>\d{2})')


    def initialize_mount(self):
        """
            iOptron init procedure:
                    - Version
                    - MountInfo
        """
        self.logger.info('Initializing {} mount'.format(__name__))
        if not self.is_connected():
            self.connect()

        if not self.is_initialized:

            # We trick the mount into thinking it's initialized while we initialize
            self.is_initialized = True

            actual_version = self.serial_query('version')
            actual_mount_info = self.serial_query('mount_info')

            expected_version = self.commands.get('version').get('response')
            expected_mount_info = self.commands.get('mount_info').get('response')
            self.is_initialized = False

            # Test our init procedure for iOptron
            if actual_version != expected_version or actual_mount_info != expected_mount_info:
                self.logger.debug('{} != {}'.format(actual_version, expected_version))
                self.logger.debug('{} != {}'.format(actual_mount_info, expected_mount_info))
                raise error.MountNotFound('Problem initializing mount')
            else:
                self.is_initialized = True


        self.serial_query('set_guide_rate', '050')

        self.logger.debug('Mount initialized: {}'.format(self.is_initialized ))
        return self.is_initialized


    def _mount_coord_to_skycoord(self, mount_ra, mount_dec):
        """
        Converts between iOptron RA/Dec format and a SkyCoord

        @param  mount_ra    RA in mount specific format
        @param  mount_dec   Dec in mount specific format
<commit_msg>Calibrate the mount upon initialization<commit_after>import re

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

from panoptes.mount.mount import AbstractMount
import panoptes.utils.logger as logger
import panoptes.utils.error as error

@logger.set_log_level('debug')
@logger.has_logger
class Mount(AbstractMount):

    """
    iOptron mounts
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self._ra_format = re.compile('(?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})')
        self._dec_format = re.compile('(?P<sign>[\+\-])(?P<degree>\d{2})\*(?P<minute>\d{2}):(?P<second>\d{2})')


    def initialize_mount(self):
        """
            iOptron init procedure:
                    - Version
                    - MountInfo
        """
        self.logger.info('Initializing {} mount'.format(__name__))
        if not self.is_connected():
            self.connect()

        if not self.is_initialized:

            # We trick the mount into thinking it's initialized while we initialize
            self.is_initialized = True

            actual_version = self.serial_query('version')
            actual_mount_info = self.serial_query('mount_info')

            expected_version = self.commands.get('version').get('response')
            expected_mount_info = self.commands.get('mount_info').get('response')
            self.is_initialized = False

            # Test our init procedure for iOptron
            if actual_version != expected_version or actual_mount_info != expected_mount_info:
                self.logger.debug('{} != {}'.format(actual_version, expected_version))
                self.logger.debug('{} != {}'.format(actual_mount_info, expected_mount_info))
                raise error.MountNotFound('Problem initializing mount')
            else:
                self.is_initialized = True
                self.serial_query('calibrate_mount')


        self.serial_query('set_guide_rate', '050')

        self.logger.debug('Mount initialized: {}'.format(self.is_initialized ))
        return self.is_initialized


    def _mount_coord_to_skycoord(self, mount_ra, mount_dec):
        """
        Converts between iOptron RA/Dec format and a SkyCoord

        @param  mount_ra    RA in mount specific format
        @param  mount_dec   Dec in mount specific format

{'fraction_non_alphanumeric': 0.11932917652117823, 'fraction_numerical': 0.0038701354547409157, 'mean_word_length': 2.5922779922779924, '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': '1429460', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1292, 'n_words': 279}