<commit_before>import os

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

from astroplan import FixedTarget

from matplotlib import pyplot as plt
from matplotlib import cm as cm
plt.style.use('ggplot')

from ..utils.error import *
from ..utils.logger import get_logger
from ..utils.config import load_config
from ..utils import images

from .observation import Observation

# ----------------------------------------------------------------------------
# Target Class
# ----------------------------------------------------------------------------


class Target(FixedTarget):

    """An object describing an astronomical target.

    An object representing a possible target which the scheduler is considering,
    also is the object which the scheduler will return when asked for a target
    to observe.
    """

    def __init__(self, target_config, cameras=None, **kwargs):
        """  A FixedTarget object that we want to gather data about.

        A `Target` represents not only the actual object in the night sky
        (via the `self.coord` astropy.SkyCoord attribute) but also the concept
        of a `visit`, which is a list of `Observation`s.

        """
        self.config = load_config()
        self.logger = get_logger(self)

        assert 'name' in target_config, self.logger.warning("Problem with Target, trying adding a name")
        assert 'position' in target_config, self.logger.warning("Problem with Target, trying adding a position")
        assert isinstance(target_config['name'], str)

        name = target_config.get('name', None)
        sky_coord = None

        try:
            self.logger.debug("Looking up coordinates for {}...".format(name))
            sky_coord = SkyCoord.from_name(name)
        except:
            self.logger.debug("Looking up coordinates failed, using dict")
            sky_coord = SkyCoord(target_config['position'], frame=target_config.get('frame', 'icrs'))

        super().__init__(name=name, coord=sky_coord, **kwargs)

        self.coord.equinox = target_config.get('equinox', '2000')
        self.coord.epoch = target_config.get('epoch', 2000.)
        self.priority = target_config.get('priority', 1.0)

        # proper motion (is tuple of dRA/dt dDec/dt)
        proper_motion = target_config.get('proper_motion', '0.0 0.0').split()
        self.proper_motion = (proper_motion[0], proper_motion[1])

        # Each target as a `visit` that is a list of Observations
        self.logger.debug("Creating visits")
        self._target_dir = '{}/{}/{}'.format(self.config['directories']['images'],
                                             self.name.title().replace(' ', ''),
                                             Time.now().isot.replace('-', '').replace(':', '').split('.')[0])

        self.logger.debug("Target Directory: {}".format(self._target_dir))
        self.visit = [Observation(od, cameras=cameras, target_dir=self._target_dir, visit_num=num)
                      for num, od in enumerate(target_config.get('visit', [{}]))]
        self.logger.debug("Visits: {}".format(self.visit))
        self.visits = self.get_visit_iter()
        self.current_visit = None
        self._done_visiting = False
        self._visit_num = 0

        self._reference_image = None<commit_msg>Make target dir at beginning<commit_after>import os

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

from astroplan import FixedTarget

from matplotlib import pyplot as plt
from matplotlib import cm as cm
plt.style.use('ggplot')

from ..utils.error import *
from ..utils.logger import get_logger
from ..utils.config import load_config
from ..utils import images

from .observation import Observation

# ----------------------------------------------------------------------------
# Target Class
# ----------------------------------------------------------------------------


class Target(FixedTarget):

    """An object describing an astronomical target.

    An object representing a possible target which the scheduler is considering,
    also is the object which the scheduler will return when asked for a target
    to observe.
    """

    def __init__(self, target_config, cameras=None, **kwargs):
        """  A FixedTarget object that we want to gather data about.

        A `Target` represents not only the actual object in the night sky
        (via the `self.coord` astropy.SkyCoord attribute) but also the concept
        of a `visit`, which is a list of `Observation`s.

        """
        self.config = load_config()
        self.logger = get_logger(self)

        assert 'name' in target_config, self.logger.warning("Problem with Target, trying adding a name")
        assert 'position' in target_config, self.logger.warning("Problem with Target, trying adding a position")
        assert isinstance(target_config['name'], str)

        name = target_config.get('name', None)
        sky_coord = None

        try:
            self.logger.debug("Looking up coordinates for {}...".format(name))
            sky_coord = SkyCoord.from_name(name)
        except:
            self.logger.debug("Looking up coordinates failed, using dict")
            sky_coord = SkyCoord(target_config['position'], frame=target_config.get('frame', 'icrs'))

        super().__init__(name=name, coord=sky_coord, **kwargs)

        self.coord.equinox = target_config.get('equinox', '2000')
        self.coord.epoch = target_config.get('epoch', 2000.)
        self.priority = target_config.get('priority', 1.0)

        # proper motion (is tuple of dRA/dt dDec/dt)
        proper_motion = target_config.get('proper_motion', '0.0 0.0').split()
        self.proper_motion = (proper_motion[0], proper_motion[1])

        # Each target as a `visit` that is a list of Observations
        self.logger.debug("Creating visits")
        self._target_dir = '{}/{}/{}'.format(self.config['directories']['images'],
                                             self.name.title().replace(' ', ''),
                                             Time.now().isot.replace('-', '').replace(':', '').split('.')[0])
        try:
            os.mkdir(self._target_dir)
        except OSError as e:
            self.logger.warning("Can't make directory for target: {}".format(e))

        self.logger.debug("Target Directory: {}".format(self._target_dir))
        self.visit = [Observation(od, cameras=cameras, target_dir=self._target_dir, visit_num=num)
                      for num, od in enumerate(target_config.get('visit', [{}]))]
        self.logger.debug("Visits: {}".format(self.visit))
        self.visits = self.get_visit_iter()
        self.current_visit = None
        self._done_visiting = False
        self._visit_num = 0

        self._reference_image = None
{'fraction_non_alphanumeric': 0.15539251650770358, 'fraction_numerical': 0.005282465150403521, 'mean_word_length': 2.328125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5910512', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1772, 'n_words': 525}