<commit_before>"""Record simulated exposures and collect per-tile statistics.
"""
from __future__ import print_function, division, absolute_import

import numpy as np


class ExposureList(object):

    def __init__(self, scheduler, max_nexp=50000):
        self.scheduler = scheduler
        self._exposures = np.empty(max_nexp, dtype=[
            ('mjd', np.float64),
            ('exptime', np.float32),
            ('tileid', np.int32),
            ('passnum', np.int32),
            ('snr2frac_start', np.float32),
            ('snr2frac_stop', np.float32),
            ('seeing', np.float32),
            ('transp', np.float32),
        ])
        ntiles = len(self.scheduler.tileid)
        self._tiledata = np.empty(ntiles, dtype=[
            ('exptime', np.float32),
            ('snr2frac', np.float32),
            ('nexp', np.int32)
        ])
        self.reset()
        
    def reset(self):
        self.nexp = 0
        self._tiledata[:] = 0
        
    def add(self, mjd, exptime, tileid, passnum, snr2frac_start, snr2frac_stop,
            seeing, transp):
        if self.nexp >= len(self._exposures):
            raise RuntimeError(
                'Need to increase max_nexp={}'.format(len(self._exposures)))
        self._exposures[self.nexp] = (
            mjd, exptime, tileid, passnum, snr2frac_start, snr2frac_stop,
            seeing, transp)
        self.nexp += 1
        tileinfo = self._tiledata[self.scheduler.get_tile_index(tileid)]
        tileinfo['exptime'] += exptime
        tileinfo['snr2frac'] = snr2frac_stop
        tileinfo['nexp'] += 1<commit_msg>ExposureList uses Tiles instead of Scheduler<commit_after>"""Record simulated exposures and collect per-tile statistics.
"""
from __future__ import print_function, division, absolute_import

import numpy as np

import desisurvey.tiles


class ExposureList(object):

    def __init__(self, tiles_file=None, max_nexp=50000):
        self.tiles = desisurvey.tiles.get_tiles(tiles_file)
        self._exposures = np.empty(max_nexp, dtype=[
            ('mjd', np.float64),
            ('exptime', np.float32),
            ('tileid', np.int32),
            ('passnum', np.int32),
            ('snr2frac_start', np.float32),
            ('snr2frac_stop', np.float32),
            ('seeing', np.float32),
            ('transp', np.float32),
        ])
        self._tiledata = np.empty(self.tiles.ntiles, dtype=[
            ('exptime', np.float32),
            ('snr2frac', np.float32),
            ('nexp', np.int32)
        ])
        self.reset()

    def reset(self):
        self.nexp = 0
        self._tiledata[:] = 0

    def add(self, mjd, exptime, tileid, passnum, snr2frac_start, snr2frac_stop,
            seeing, transp):
        if self.nexp >= len(self._exposures):
            raise RuntimeError(
                'Need to increase max_nexp={}'.format(len(self._exposures)))
        self._exposures[self.nexp] = (
            mjd, exptime, tileid, passnum, snr2frac_start, snr2frac_stop,
            seeing, transp)
        self.nexp += 1
        tileinfo = self._tiledata[self.tiles.index(tileid)]
        tileinfo['exptime'] += exptime
        tileinfo['snr2frac'] = snr2frac_stop
        tileinfo['nexp'] += 1
{'fraction_non_alphanumeric': 0.13094867807153965, 'fraction_numerical': 0.024883359253499222, 'mean_word_length': 2.219219219219219, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1972193', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1049, 'n_words': 204}