<commit_before>"""Simulate weather conditions affecting observations.
"""
from __future__ import print_function, division, absolute_import

from datetime import datetime

import numpy as np

import astropy.time
import astropy.table
import astropy.units as u

import desiutil.log

import desimodel.weather

import desisurvey.config
import desisurvey.utils


class Weather(object):
    """Simulate weather conditions affecting observations.

    Seeing and transparency values are stored with 32-bit floats to save
    some memory.

    Parameters
    ----------
    start_date : datetime.date or None
        Survey starts on the evening of this date. Use the ``first_day``
        config parameter if None (the default).
    stop_date : datetime.date or None
        Survey stops on the morning of this date. Use the ``last_day``
        config parameter if None (the default).
    time_step : :class:`astropy.units.Quantity`, optional
        Time step for calculating updates. Must evenly divide 24 hours.
    gen : numpy.random.RandomState or None
        Random number generator to use for reproducible samples. Will be
        initialized (un-reproducibly) if None.
    restore : filename or None
        Restore an existing weather simulation from the specified file name.
        All other parameters are ignored when this is provided. A relative path
        name refers to the :meth:`configuration output path
        <desisurvey.config.Configuration.get_path>`.
    """
    def __init__(self, start_date=None, stop_date=None, time_step=5,
                 gen=None, restore=None):
        if not isinstance(time_step, u.Quantity):
            time_step = time_step * u.min
        self.log = desiutil.log.get_logger()
        config = desisurvey.config.Configuration()

        if restore is not None:
            self._table = astropy.table.Table.read(config.get_path(restore))
            self.start_date = desisurvey.utils.get_date(
                self._table.meta['START'])
            self.stop_date = desisurvey.utils.get_date(
                self._table.meta['STOP'])
            self.num_nights = self._table.meta['NIGHTS']
            self.steps_per_day = self._table.meta['STEPS']
            return

        if gen is None:
            self.log.warn('Will generate unreproducible random numbers.')
            gen = np.random.RandomState()<commit_msg>clarify units in docstring [ci skip]<commit_after>"""Simulate weather conditions affecting observations.
"""
from __future__ import print_function, division, absolute_import

from datetime import datetime

import numpy as np

import astropy.time
import astropy.table
import astropy.units as u

import desiutil.log

import desimodel.weather

import desisurvey.config
import desisurvey.utils


class Weather(object):
    """Simulate weather conditions affecting observations.

    Seeing and transparency values are stored with 32-bit floats to save
    some memory.

    Parameters
    ----------
    start_date : datetime.date or None
        Survey starts on the evening of this date. Use the ``first_day``
        config parameter if None (the default).
    stop_date : datetime.date or None
        Survey stops on the morning of this date. Use the ``last_day``
        config parameter if None (the default).
    time_step : float or :class:`astropy.units.Quantity`, optional
        Time step calculating updates. Must evenly divide 24 hours.
        If unitless float, will be interpreted as minutes.
    gen : numpy.random.RandomState or None
        Random number generator to use for reproducible samples. Will be
        initialized (un-reproducibly) if None.
    restore : filename or None
        Restore an existing weather simulation from the specified file name.
        All other parameters are ignored when this is provided. A relative path
        name refers to the :meth:`configuration output path
        <desisurvey.config.Configuration.get_path>`.
    """
    def __init__(self, start_date=None, stop_date=None, time_step=5,
                 gen=None, restore=None):
        if not isinstance(time_step, u.Quantity):
            time_step = time_step * u.min
        self.log = desiutil.log.get_logger()
        config = desisurvey.config.Configuration()

        if restore is not None:
            self._table = astropy.table.Table.read(config.get_path(restore))
            self.start_date = desisurvey.utils.get_date(
                self._table.meta['START'])
            self.stop_date = desisurvey.utils.get_date(
                self._table.meta['STOP'])
            self.num_nights = self._table.meta['NIGHTS']
            self.steps_per_day = self._table.meta['STEPS']
            return

        if gen is None:
            self.log.warn('Will generate unreproducible random numbers.')
            gen = np.random.RandomState()
{'fraction_non_alphanumeric': 0.07859358841778696, 'fraction_numerical': 0.002068252326783868, 'mean_word_length': 2.669195751138088, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4404633', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1261, 'n_words': 433}