<commit_before># Copyright (c) 2016, German Neuroinformatics Node (G-Node)
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.
from numbers import Number

from .entity_with_sources import EntityWithSources
from ..data_array import DataArrayMixin, DataSetMixin
from ..value import DataType
from .dimensions import (SampledDimension, RangeDimension, SetDimension,
                         DimensionType)
from . import util


class DataSet(DataSetMixin):

    def _write_data(self, data, count, offset):
        dataset = self._h5group.get_dataset("data")
        dataset.write_data(data, count, offset)

    def _read_data(self, data, count, offset):
        dataset = self._h5group.get_dataset("data")
        dataset.read_data(data, count, offset)

    @property
    def data_extent(self):
        dataset = self._h5group.get_dataset("data")
        return dataset.shape

    @data_extent.setter
    def data_extent(self, extent):
        dataset = self._h5group.get_dataset("data")
        dataset.shape = extent

    @property
    def data_type(self):
        return self._get_dtype()

    def _get_dtype(self):
        dataset = self._h5group.get_dataset("data")
        return dataset.dtype


class DataArray(EntityWithSources, DataSet, DataArrayMixin):

    def __init__(self, h5group):
        super(DataArray, self).__init__(h5group)

    @classmethod
    def _create_new(cls, parent, name, type_, data_type, shape):
        newentity = super(DataArray, cls)._create_new(parent, name, type_)
        newentity._h5group.create_dataset("data", shape, data_type)
        return newentity

    def _read_data(self, data, count, offset):
        coeff = self.polynom_coefficients
        origin = self.expansion_origin
        if len(coeff) or origin:
            if not origin:
                origin = 0.0

            super(DataArray, self)._read_data(data, count, offset)
            util.apply_polynomial(coeff, origin, data)
        else:
            super(DataArray, self)._read_data(data, count, offset)

    def create_set_dimension(self, index):
        dimgroup = self._h5group.open_group("dimensions")
        return SetDimension._create_new(dimgroup, index)

    def create_sampled_dimension(self, index, sample):
        dimgroup = self._h5group.open_group("dimensions")
        return SampledDimension._create_new(dimgroup, index, sample)

    def create_range_dimension(self, index, range_):
        dimgroup = self._h5group.open_group("dimensions")
        return RangeDimension._create_new(dimgroup, index, range_)

    def append_set_dimension(self):
        index = len(self._h5group.open_group("dimensions")) + 1
        return self.create_set_dimension(index)

    def append_sampled_dimension(self, sample):
        index = len(self._h5group.open_group("dimensions")) + 1
        return self.create_sampled_dimension(index, sample)

    def append_range_dimension(self, range_):
        index = len(self._h5group.open_group("dimensions")) + 1
        return self.create_range_dimension(index, range_)

    def create_alias_range_dimension(self):
        if (len(self.data_extent) > 1 or
                not DataType.is_numeric_dtype(self.dtype)):
            raise ValueError("AliasRangeDimensions only allowed for 1D "
                             "numeric DataArrays.")<commit_msg>Create dimension methods deprecated - Append only<commit_after># Copyright (c) 2016, German Neuroinformatics Node (G-Node)
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.
from numbers import Number

from warnings import warn

from .entity_with_sources import EntityWithSources
from ..data_array import DataArrayMixin, DataSetMixin
from ..value import DataType
from .dimensions import (SampledDimension, RangeDimension, SetDimension,
                         DimensionType)
from . import util


class DataSet(DataSetMixin):

    def _write_data(self, data, count, offset):
        dataset = self._h5group.get_dataset("data")
        dataset.write_data(data, count, offset)

    def _read_data(self, data, count, offset):
        dataset = self._h5group.get_dataset("data")
        dataset.read_data(data, count, offset)

    @property
    def data_extent(self):
        dataset = self._h5group.get_dataset("data")
        return dataset.shape

    @data_extent.setter
    def data_extent(self, extent):
        dataset = self._h5group.get_dataset("data")
        dataset.shape = extent

    @property
    def data_type(self):
        return self._get_dtype()

    def _get_dtype(self):
        dataset = self._h5group.get_dataset("data")
        return dataset.dtype


class DataArray(EntityWithSources, DataSet, DataArrayMixin):

    def __init__(self, h5group):
        super(DataArray, self).__init__(h5group)

    @classmethod
    def _create_new(cls, parent, name, type_, data_type, shape):
        newentity = super(DataArray, cls)._create_new(parent, name, type_)
        newentity._h5group.create_dataset("data", shape, data_type)
        return newentity

    def _read_data(self, data, count, offset):
        coeff = self.polynom_coefficients
        origin = self.expansion_origin
        if len(coeff) or origin:
            if not origin:
                origin = 0.0

            super(DataArray, self)._read_data(data, count, offset)
            util.apply_polynomial(coeff, origin, data)
        else:
            super(DataArray, self)._read_data(data, count, offset)

    def create_set_dimension(self, index):
        warn("This function is deprecated and ignores the index argument")
        return self.append_set_dimension()

    def create_sampled_dimension(self, index, sample):
        warn("This function is deprecated and ignores the index argument")
        return self.append_sampled_dimension(sample)

    def create_range_dimension(self, index, range_):
        warn("This function is deprecated and ignores the index argument")
        return self.append_range_dimension(range_)

    def append_set_dimension(self):
        dimgroup = self._h5group.open_group("dimensions")
        index = len(self._h5group.open_group("dimensions")) + 1
        return SetDimension._create_new(dimgroup, index)

    def append_sampled_dimension(self, sample):
        index = len(self._h5group.open_group("dimensions")) + 1
        dimgroup = self._h5group.open_group("dimensions")
        return SampledDimension._create_new(dimgroup, index, sample)

    def append_range_dimension(self, range_):
        index = len(self._h5group.open_group("dimensions")) + 1
        dimgroup = self._h5group.open_group("dimensions")
        return RangeDimension._create_new(dimgroup, index, range_)

    def create_alias_range_dimension(self):
        warn("This function is deprecated and will be removed. "
             "Use append_alias_range_dimension instead.", DeprecationWarning)
        return self.append_alias_range_dimension()

    def append_alias_range_dimension(self):
        if (len(self.data_extent) > 1 or
                not DataType.is_numeric_dtype(self.dtype)):
            raise ValueError("AliasRangeDimensions only allowed for 1D "
                             "numeric DataArrays.")
{'fraction_non_alphanumeric': 0.08927130949179887, 'fraction_numerical': 0.006722237160527024, 'mean_word_length': 3.174523007856341, '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': '2981586', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2115, 'n_words': 533}