<commit_before>"""Simulation utilities that may be used by other packages.
"""
from __future__ import print_function, division, absolute_import
import numpy as np
from astropy.table import Column


def add_calibration_exposures(exposures, flats_per_night=3, arcs_per_night=3,
                              darks_per_night=0, zeroes_per_night=0,
                              exptime=None, readout=30.0):
    """Adds calibration exposures to a set of science exposures and
    assigns exposure IDs.

    Parameters
    ----------
    exposures : :class:`astropy.table.Table`
        A table of science exposures, produced by *e.g.*
        ``desisurvey.progress.Progress.get_exposures()``.
        The exposures must be sorted by increasing MJD/timestamp.
    flats_per_night : :class:`int`, optional
        Add this many arc exposures per night (default 3).
    arcs_per_night : :class:`int`, optional
        Add this many arc exposures per night (default 3).
    darks_per_night : :class:`int`, optional
        Add this many dark exposures per night (default 0).
    zeroes_per_night : :class:`int`, optional
        Add this many zero exposures per night (default 0).
    exptime : :class:`dict`, optional
        A dictionary setting calibration exposure times for each
        calibration flavor.
    readout : :class:`float`, optional
        Set readout time for calibration exposures (default 30.0 s).

    Returns
    -------
    :class:`astropy.table.Table`
        A table augmented with calibration exposures.

    Raises
    ------
    ValueError
        If the input is not sorted by increasing MJD/timestamp.
    """
    if not np.all(np.diff(exposures['MJD']) >= 0):
        raise ValueError("Input is not sorted by increasing MJD!")
    if exptime is None:
        exptime = {'flat': 10.0, 'arc': 10.0, 'dark': 1000.0, 'zero': 0.0}
    output = exposures[:0].copy()
    expid_in_exposures = 'EXPID' in exposures.colnames
    for c in ('RA', 'DEC'):
        if output[c].unit is None:
            output[c].unit = 'deg'
    current_night = '19730703'
    expid = 0
    calib_time = lambda x: exptime[x] + readout
    calib_sequence = (['flat']*flats_per_night + ['arc']*arcs_per_night +
                      ['dark']*darks_per_night + ['zero']*zeroes_per_night)
    calib_times = np.cumsum(np.array([calib_time(c)
                                      for c in calib_sequence]))[::-1]
    # None fields get filled in for each calibration exposure.
    calib_data = {'TILEID': -1,
                  'PASS': -1,
                  'RA': 0.0,
                  'DEC': 0.0,
                  'EBMV': 0.0,
                  'NIGHT': None,
                  'MJD': None,
                  'EXPTIME': None,
                  'SEEING': 0.0,
                  'TRANSPARENCY': 0.0,
                  'AIRMASS': 0.0,
                  'MOONFRAC': 0.0,
                  'MOONALT': 0.0,
                  'MOONSEP': 0.0,
                  'PROGRAM': 'CALIB',
                  'FLAVOR': None
                  }
    if expid_in_exposures:
        calib_data['EXPID'] = None
    for i, night in enumerate(exposures['NIGHT']):
        if night != current_night:
            current_night = night<commit_msg>swap arc/flat calib exposure order<commit_after>"""Simulation utilities that may be used by other packages.
"""
from __future__ import print_function, division, absolute_import
import numpy as np
from astropy.table import Column


def add_calibration_exposures(exposures, flats_per_night=3, arcs_per_night=3,
                              darks_per_night=0, zeroes_per_night=0,
                              exptime=None, readout=30.0):
    """Adds calibration exposures to a set of science exposures and
    assigns exposure IDs.

    Parameters
    ----------
    exposures : :class:`astropy.table.Table`
        A table of science exposures, produced by *e.g.*
        ``desisurvey.progress.Progress.get_exposures()``.
        The exposures must be sorted by increasing MJD/timestamp.
    flats_per_night : :class:`int`, optional
        Add this many arc exposures per night (default 3).
    arcs_per_night : :class:`int`, optional
        Add this many arc exposures per night (default 3).
    darks_per_night : :class:`int`, optional
        Add this many dark exposures per night (default 0).
    zeroes_per_night : :class:`int`, optional
        Add this many zero exposures per night (default 0).
    exptime : :class:`dict`, optional
        A dictionary setting calibration exposure times for each
        calibration flavor.
    readout : :class:`float`, optional
        Set readout time for calibration exposures (default 30.0 s).

    Returns
    -------
    :class:`astropy.table.Table`
        A table augmented with calibration exposures.

    Raises
    ------
    ValueError
        If the input is not sorted by increasing MJD/timestamp.
    """
    if not np.all(np.diff(exposures['MJD']) >= 0):
        raise ValueError("Input is not sorted by increasing MJD!")
    if exptime is None:
        exptime = {'flat': 10.0, 'arc': 10.0, 'dark': 1000.0, 'zero': 0.0}
    output = exposures[:0].copy()
    expid_in_exposures = 'EXPID' in exposures.colnames
    for c in ('RA', 'DEC'):
        if output[c].unit is None:
            output[c].unit = 'deg'
    current_night = '19730703'
    expid = 0
    calib_time = lambda x: exptime[x] + readout
    calib_sequence = (['arc']*arcs_per_night + ['flat']*flats_per_night +
                      ['dark']*darks_per_night + ['zero']*zeroes_per_night)
    calib_times = np.cumsum(np.array([calib_time(c)
                                      for c in calib_sequence]))[::-1]
    # None fields get filled in for each calibration exposure.
    calib_data = {'TILEID': -1,
                  'PASS': -1,
                  'RA': 0.0,
                  'DEC': 0.0,
                  'EBMV': 0.0,
                  'NIGHT': None,
                  'MJD': None,
                  'EXPTIME': None,
                  'SEEING': 0.0,
                  'TRANSPARENCY': 0.0,
                  'AIRMASS': 0.0,
                  'MOONFRAC': 0.0,
                  'MOONALT': 0.0,
                  'MOONSEP': 0.0,
                  'PROGRAM': 'CALIB',
                  'FLAVOR': None
                  }
    if expid_in_exposures:
        calib_data['EXPID'] = None
    for i, night in enumerate(exposures['NIGHT']):
        if night != current_night:
            current_night = night
{'fraction_non_alphanumeric': 0.11345646437994723, 'fraction_numerical': 0.01831444979047028, 'mean_word_length': 1.9750692520775623, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1264490', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1891, 'n_words': 551}