<commit_before># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Third-party
import numpy as np
from astropy import log as logger
import gary.integrate as gi
import gary.coordinates as gc
import gary.dynamics as gd
from gary.util import rolling_window
from superfreq import SuperFreq

# Project
from .util import estimate_dt_nsteps
from .experimentrunner import OrbitGridExperiment

__all__ = ['FreqVariance']

class FreqVariance(OrbitGridExperiment):
    # failure error codes
    error_codes = {
        1: "Failed to integrate orbit or estimate dt, nsteps.",
        2: "Energy conservation criteria not met.",
        3: "SuperFreq failed on find_fundamental_frequencies()."
    }

    _run_kwargs = ['total_nperiods', 'window_width', 'window_stride',
                   'energy_tolerance', 'nsteps_per_period', 'hamming_p']
    config_defaults = dict(
        total_nperiods=100, # total number of periods to integrate for
        window_width=50, # width of the window (in orbital periods) to compute freqs in
        window_stride=1, # how much to shift window after each computation
        energy_tolerance=1E-7, # Maximum allowed fractional energy difference
        nsteps_per_period=512, # Number of steps per integration period for integration stepsize
        hamming_p=2, # Exponent to use for Hamming filter
        w0_filename='w0.npy', # Name of the initial conditions file
        cache_filename='freqvariance.npy', # Name of the cache file
        potential_filename='potential.yml' # Name of cached potential file
    )

    def __init__(self, cache_path, config_filename=None, overwrite=False, **kwargs):
        total_nperiods = kwargs.get('total_nperiods', self.config_defaults['total_nperiods'])
        window_width = kwargs.get('window_width', self.config_defaults['window_width'])
        window_stride = kwargs.get('window_stride', self.config_defaults['window_stride'])
        self._nwindows = int((total_nperiods - window_width) / window_stride)

        super(FreqVariance, self).__init__(cache_path, config_filename=config_filename,
                                           overwrite=overwrite, **kwargs)

    @property
    def cache_dtype(self):
        dt = [
            ('freqs','f8',(self._nwindows,3)), # three fundamental frequencies computed in windows
            ('amps','f8',(self._nwindows,3)), # amplitudes of frequencies in time series
            ('dE_max','f8'), # maximum energy difference (compared to initial) during integration
            ('is_tube','b1'), # the orbit is a tube orbit
            ('dt','f8'), # timestep used for integration
            ('nsteps','i8'), # number of steps integrated<commit_msg>added a todo<commit_after># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Third-party
import numpy as np
from astropy import log as logger
import gary.integrate as gi
import gary.coordinates as gc
import gary.dynamics as gd
from gary.util import rolling_window
from superfreq import SuperFreq

# Project
from .util import estimate_dt_nsteps
from .experimentrunner import OrbitGridExperiment

__all__ = ['FreqVariance']

class FreqVariance(OrbitGridExperiment):
    # failure error codes
    error_codes = {
        1: "Failed to integrate orbit or estimate dt, nsteps.",
        2: "Energy conservation criteria not met.",
        3: "SuperFreq failed on find_fundamental_frequencies()."
    }

    _run_kwargs = ['total_nperiods', 'window_width', 'window_stride',
                   'energy_tolerance', 'nsteps_per_period', 'hamming_p']
    config_defaults = dict(
        total_nperiods=100, # total number of periods to integrate for
        window_width=50, # width of the window (in orbital periods) to compute freqs in
        window_stride=1, # how much to shift window after each computation
        energy_tolerance=1E-7, # Maximum allowed fractional energy difference
        nsteps_per_period=512, # Number of steps per integration period for integration stepsize
        hamming_p=2, # Exponent to use for Hamming filter
        w0_filename='w0.npy', # Name of the initial conditions file
        cache_filename='freqvariance.npy', # Name of the cache file
        potential_filename='potential.yml' # Name of cached potential file
    )

    # TODO: config file should never be passed to init -- should just take kwargs

    def __init__(self, cache_path, config_filename=None, overwrite=False, **kwargs):
        total_nperiods = kwargs.get('total_nperiods', self.config_defaults['total_nperiods'])
        window_width = kwargs.get('window_width', self.config_defaults['window_width'])
        window_stride = kwargs.get('window_stride', self.config_defaults['window_stride'])
        self._nwindows = int((total_nperiods - window_width) / window_stride)

        super(FreqVariance, self).__init__(cache_path, config_filename=config_filename,
                                           overwrite=overwrite, **kwargs)

    @property
    def cache_dtype(self):
        dt = [
            ('freqs','f8',(self._nwindows,3)), # three fundamental frequencies computed in windows
            ('amps','f8',(self._nwindows,3)), # amplitudes of frequencies in time series
            ('dE_max','f8'), # maximum energy difference (compared to initial) during integration
            ('is_tube','b1'), # the orbit is a tube orbit
            ('dt','f8'), # timestep used for integration
            ('nsteps','i8'), # number of steps integrated
{'fraction_non_alphanumeric': 0.09245830311820159, 'fraction_numerical': 0.009427121102248005, 'mean_word_length': 3.4242181234963915, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4910053', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1519, 'n_words': 468}