<commit_before># -*- coding: utf-8 -*-
"""
Produces fake instrument data for testing.
"""
from __future__ import print_function
from __future__ import absolute_import
import functools
import os

import numpy as np
import pandas as pds
import xarray as xr

import pysat
from pysat.instruments.methods import testing as test

# pysat required parameters
platform = 'pysat'
name = 'testing'

# dictionary of data 'tags' and corresponding description
# tags are used to choose the behaviour of dummy1
tags = {'': 'Regular testing data set',
        'ascend': 'Ascending Integers from 0 testing data set',
        'descend': 'Descending Integers from 0 testing data set',
        'plus10': 'Ascending Integers from 10 testing data set',
        'fives': 'All 5s testing data set',
        'mlt_offset': 'dummy1 is offset by five from regular testing set'}
# dictionary of satellite IDs, list of corresponding tags
# a numeric string can be used in sat_id to change the number of points per day
sat_ids = {'': ['', 'ascend', 'descend', 'plus10', 'fives', 'mlt_offset']}
test_dates = {'': {'': pysat.datetime(2009, 1, 1)}}

meta = pysat.Meta()
meta['uts'] = {'units': 's',
               'long_name': 'Universal Time',
               'custom': False}
meta['Epoch'] = {'units': 'Milliseconds since 1970-1-1',
                 'Bin_Location': 0.5,
                 'notes': 'UTC time at middle of geophysical measurement.',
                 'desc': 'UTC seconds', }
meta['mlt'] = {'units': 'hours',
               'long_name': 'Magnetic Local Time',
               'label': 'MLT',
               'axis': 'MLT',
               'desc': 'Magnetic Local Time',
               'value_min': 0.0,
               'value_max': 24.0,
               'notes': ('Magnetic Local Time is the solar local time of the '
                         'field line at the location where the field crosses '
                         'the magnetic equator. In this case we just simulate '
                         '0-24 with a consistent orbital period and an offste '
                         'with SLT.'),
               'fill': np.nan,
               'scale': 'linear'}
meta['slt'] = {'units': 'hours',
               'long_name': 'Solar Local Time',
               'label': 'SLT',
               'axis': 'SLT',
               'desc': 'Solar Local Time',
               'value_min': 0.0,
               'value_max': 24.0,
               'notes': ('Solar Local Time is the local time (zenith angle of '
                         'sun) of the given locaiton. Overhead noon, +/- 90 '
                         'is 6, 18 SLT .'),
               'fill': np.nan,
               'scale': 'linear'}
meta['orbit_num'] = {'units': '',
                     'long_name': 'Orbit Number',
                     'label': 'Orbit Number',
                     'axis': 'Orbit Number',
                     'desc': 'Orbit Number',
                     'value_min': 0.0,
                     'value_max': 25000.0,
                     'notes': ('Number of orbits since the start of the '
                               'mission. For this simulation we use the '
                               'number of 5820 second periods since the '
                               'start, 2008-01-01.'),
                     'fill': np.nan,
                     'scale': 'linear'}

meta['longitude'] = {'units': 'degrees', 'long_name': 'Longitude'}
meta['latitude'] = {'units': 'degrees', 'long_name': 'Latitude'}
meta['dummy1'] = {'units': '', 'long_name': 'dummy1'}
meta['dummy2'] = {'units': '', 'long_name': 'dummy2'}
meta['dummy3'] = {'units': '', 'long_name': 'dummy3'}
meta['dummy4'] = {'units': '', 'long_name': 'dummy4'}
meta['string_dummy'] = {'units': '', 'long_name': 'string_dummy'}
meta['unicode_dummy'] = {'units': '', 'long_name': 'unicode_dummy'}
meta['int8_dummy'] = {'units': '', 'long_name': 'int8_dummy'}
meta['int16_dummy'] = {'units': '', 'long_name': 'int16_dummy'}
meta['int32_dummy'] = {'units': '', 'long_name': 'int32_dummy'}
meta['int64_dummy'] = {'units': '', 'long_name': 'int64_dummy'}


def init(inst):
    """ Initialization function

    Shifts time index of files by 5-minutes if mangle_file_dates
    set to True at pysat.Instrument instantiation.

    Creates a file list for a given range if the file_date_range
    keyword is set at instantiation.

    Parameters
    ----------
    file_date_range : (pds.date_range)
        Optional keyword argument that specifies the range of dates for which
        test files will be created
    mangle_file_dates : bool
        If True, the loaded file list time index is shifted by 5-minutes.

    """
    inst.new_thing = True

    # work on file index if keyword present
    if 'file_date_range' in inst.kwargs:
        # set list files routine to desired date range
        # attach to the instrument object
        fdr = inst.kwargs['file_date_range']
        inst._list_rtn = functools.partial(list_files, file_date_range=fdr)
        inst.files.refresh()

    # mess with file dates if kwarg option present
    if 'mangle_file_dates' in inst.kwargs:
        if inst.kwargs['mangle_file_dates']:
            inst.files.files.index = \
                inst.files.files.index + pds.DateOffset(minutes=5)

    # Pandas output
    if 'pandas_format' in inst.kwargs:
        inst.pandas_format = inst.kwargs['pandas_format']
        if inst.pandas_format:
            inst._null_data = pds.DataFrame(None)
            inst._data_library = pds.DataFrame
        else:
            inst._null_data = xr.Dataset(None)
            inst._data_library = xr.Dataset


def default(inst):
    """The default function is applied first to data as it is loaded.

    """
    pass


def load(fnames, tag=None, sat_id=None, sim_multi_file_right=False,
         sim_multi_file_left=False, root_date=None, file_date_range=None,
         malformed_index=False, pandas_format=True, **kwargs):
    """ Loads the test files<commit_msg>Revert "BUG: fixed pass through for pandas_format"<commit_after># -*- coding: utf-8 -*-
"""
Produces fake instrument data for testing.
"""
from __future__ import print_function
from __future__ import absolute_import
import functools
import os

import numpy as np
import pandas as pds
import xarray as xr

import pysat
from pysat.instruments.methods import testing as test

# pysat required parameters
platform = 'pysat'
name = 'testing'

# dictionary of data 'tags' and corresponding description
# tags are used to choose the behaviour of dummy1
tags = {'': 'Regular testing data set',
        'ascend': 'Ascending Integers from 0 testing data set',
        'descend': 'Descending Integers from 0 testing data set',
        'plus10': 'Ascending Integers from 10 testing data set',
        'fives': 'All 5s testing data set',
        'mlt_offset': 'dummy1 is offset by five from regular testing set'}
# dictionary of satellite IDs, list of corresponding tags
# a numeric string can be used in sat_id to change the number of points per day
sat_ids = {'': ['', 'ascend', 'descend', 'plus10', 'fives', 'mlt_offset']}
test_dates = {'': {'': pysat.datetime(2009, 1, 1)}}

meta = pysat.Meta()
meta['uts'] = {'units': 's',
               'long_name': 'Universal Time',
               'custom': False}
meta['Epoch'] = {'units': 'Milliseconds since 1970-1-1',
                 'Bin_Location': 0.5,
                 'notes': 'UTC time at middle of geophysical measurement.',
                 'desc': 'UTC seconds', }
meta['mlt'] = {'units': 'hours',
               'long_name': 'Magnetic Local Time',
               'label': 'MLT',
               'axis': 'MLT',
               'desc': 'Magnetic Local Time',
               'value_min': 0.0,
               'value_max': 24.0,
               'notes': ('Magnetic Local Time is the solar local time of the '
                         'field line at the location where the field crosses '
                         'the magnetic equator. In this case we just simulate '
                         '0-24 with a consistent orbital period and an offste '
                         'with SLT.'),
               'fill': np.nan,
               'scale': 'linear'}
meta['slt'] = {'units': 'hours',
               'long_name': 'Solar Local Time',
               'label': 'SLT',
               'axis': 'SLT',
               'desc': 'Solar Local Time',
               'value_min': 0.0,
               'value_max': 24.0,
               'notes': ('Solar Local Time is the local time (zenith angle of '
                         'sun) of the given locaiton. Overhead noon, +/- 90 '
                         'is 6, 18 SLT .'),
               'fill': np.nan,
               'scale': 'linear'}
meta['orbit_num'] = {'units': '',
                     'long_name': 'Orbit Number',
                     'label': 'Orbit Number',
                     'axis': 'Orbit Number',
                     'desc': 'Orbit Number',
                     'value_min': 0.0,
                     'value_max': 25000.0,
                     'notes': ('Number of orbits since the start of the '
                               'mission. For this simulation we use the '
                               'number of 5820 second periods since the '
                               'start, 2008-01-01.'),
                     'fill': np.nan,
                     'scale': 'linear'}

meta['longitude'] = {'units': 'degrees', 'long_name': 'Longitude'}
meta['latitude'] = {'units': 'degrees', 'long_name': 'Latitude'}
meta['dummy1'] = {'units': '', 'long_name': 'dummy1'}
meta['dummy2'] = {'units': '', 'long_name': 'dummy2'}
meta['dummy3'] = {'units': '', 'long_name': 'dummy3'}
meta['dummy4'] = {'units': '', 'long_name': 'dummy4'}
meta['string_dummy'] = {'units': '', 'long_name': 'string_dummy'}
meta['unicode_dummy'] = {'units': '', 'long_name': 'unicode_dummy'}
meta['int8_dummy'] = {'units': '', 'long_name': 'int8_dummy'}
meta['int16_dummy'] = {'units': '', 'long_name': 'int16_dummy'}
meta['int32_dummy'] = {'units': '', 'long_name': 'int32_dummy'}
meta['int64_dummy'] = {'units': '', 'long_name': 'int64_dummy'}


def init(inst):
    """ Initialization function

    Shifts time index of files by 5-minutes if mangle_file_dates
    set to True at pysat.Instrument instantiation.

    Creates a file list for a given range if the file_date_range
    keyword is set at instantiation.

    Parameters
    ----------
    file_date_range : (pds.date_range)
        Optional keyword argument that specifies the range of dates for which
        test files will be created
    mangle_file_dates : bool
        If True, the loaded file list time index is shifted by 5-minutes.

    """
    inst.new_thing = True

    # work on file index if keyword present
    if 'file_date_range' in inst.kwargs:
        # set list files routine to desired date range
        # attach to the instrument object
        fdr = inst.kwargs['file_date_range']
        inst._list_rtn = functools.partial(list_files, file_date_range=fdr)
        inst.files.refresh()

    # mess with file dates if kwarg option present
    if 'mangle_file_dates' in inst.kwargs:
        if inst.kwargs['mangle_file_dates']:
            inst.files.files.index = \
                inst.files.files.index + pds.DateOffset(minutes=5)

    # Pandas output
    if 'pandas_format' in inst.kwargs:
        inst.pandas_format = inst.kwargs['pandas_format']
        inst._load_rtn = functools.partial(load,
                                           pandas_format=inst.pandas_format)

def default(inst):
    """The default function is applied first to data as it is loaded.

    """
    pass


def load(fnames, tag=None, sat_id=None, sim_multi_file_right=False,
         sim_multi_file_left=False, root_date=None, file_date_range=None,
         malformed_index=False, pandas_format=True, **kwargs):
    """ Loads the test files
{'fraction_non_alphanumeric': 0.1293827998981238, 'fraction_numerical': 0.015111639358179812, 'mean_word_length': 2.252346769740475, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1766505', 'n_tokens_mistral': 3554, 'n_tokens_neox': 3346, 'n_words': 1083}