<commit_before># The Hazard Library
# Copyright (C) 2012-2016 GEM Foundation
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Module :mod:`openquake.hazardlib.source.base` defines a base class for
seismic sources.
"""
import abc
import numpy
from decimal import Decimal
from openquake.baselib.slots import with_slots
from openquake.baselib.python3compat import with_metaclass


class SourceGroupCollection(object):
    """
    :param grp_list:
        A list of :class:`openquake.hazardlib.source.base.SourceGroup`
        instances
    :param name:
        The name of the group
    :param grp_interdep:
        Interdependence between groups of sources can be either 'indep' or
        'mutex'.
    """
    @property
    def source_id(self):
        """Name of the source group"""
        # alias useful for the write_source_model function
        return self.name

    def __init__(self, grp_list, name='', grp_interdep='indep'):
        # checks
        assert isinstance(grp_list, list), grp_list
        if grp_interdep not in ['indep', 'mutex']:
            raise ValueError('group interdependence incorrect %s ' %
                             grp_interdep)
        # set instance parameters
        self.grp_list = grp_list
        self.name = name
        self.grp_interdep = grp_interdep

    def __iter__(self):
        return iter(self.grp_list)


class SourceGroup(object):
    """
    :param src_list:
        A list containing seismic sources
    :param name:
        The name of the group
    :param src_interdep:
        A string specifying if the sources in this cluster are independent or
        mutually exclusive
    :param rup_indep:
        A string specifying if the ruptures within each source of the cluster
        are independent or mutually exclusive
    :param weights:
        A dictionary whose keys are the source IDs of the cluster and the
        values are the weights associated with each source
    :param checkw:
        Flag controlling the verification of weights assigned to the sources
        in the group
    """

    @property
    def source_id(self):
        """Name of the source group"""
        # alias useful for the write_source_model function
        return self.name

    def __init__(self, src_list, name, src_interdep='indep',
                 rup_interdep='indep', srcs_weights=None, checkw=True):
        # checks
        self._check_init_variables(src_list, name, src_interdep, rup_interdep,
                                   srcs_weights, checkw)
        # set instance parameters
        self.src_list = src_list
        self.name = name
        self.src_interdep = src_interdep
        self.rup_interdep = rup_interdep
        if srcs_weights is None:
            self.srcs_weights = numpy.ones([len(src_list)])
            self.srcs_weights[0:-2] = Decimal(1./len(src_list))
            self.srcs_weights[-1] = 1 - numpy.sum(self.srcs_weights[0:-2])
        else:
            self.srcs_weights = srcs_weights

    def _check_init_variables(self, src_list, name, src_interdep, rup_interdep,
                              srcs_weights, checkw):<commit_msg>Added tectonic_region_type to the source group<commit_after># The Hazard Library
# Copyright (C) 2012-2016 GEM Foundation
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Module :mod:`openquake.hazardlib.source.base` defines a base class for
seismic sources.
"""
import abc
import numpy
from decimal import Decimal
from openquake.baselib.slots import with_slots
from openquake.baselib.python3compat import with_metaclass


class SourceGroupCollection(object):
    """
    :param grp_list:
        A list of :class:`openquake.hazardlib.source.base.SourceGroup`
        instances
    :param name:
        The name of the group
    :param grp_interdep:
        Interdependence between groups of sources can be either 'indep' or
        'mutex'.
    """
    def __init__(self, grp_list, name='', grp_interdep='indep'):
        # checks
        assert isinstance(grp_list, list), grp_list
        if grp_interdep not in ['indep', 'mutex']:
            raise ValueError('group interdependence incorrect %s ' %
                             grp_interdep)
        # set instance parameters
        self.grp_list = grp_list
        self.name = name
        self.grp_interdep = grp_interdep

    def __iter__(self):
        return iter(self.grp_list)


class SourceGroup(object):
    """
    :param src_list:
        A list containing seismic sources
    :param name:
        The name of the group
    :param src_interdep:
        A string specifying if the sources in this cluster are independent or
        mutually exclusive
    :param rup_indep:
        A string specifying if the ruptures within each source of the cluster
        are independent or mutually exclusive
    :param weights:
        A dictionary whose keys are the source IDs of the cluster and the
        values are the weights associated with each source
    :param checkw:
        Flag controlling the verification of weights assigned to the sources
        in the group
    """

    @property
    def source_id(self):
        """Name of the source group"""
        # alias useful for the write_source_model function
        return self.name

    def __init__(self, src_list, name, src_interdep='indep',
                 rup_interdep='indep', srcs_weights=None, trt='', checkw=True):
        # checks
        self._check_init_variables(src_list, name, src_interdep, rup_interdep,
                                   srcs_weights, checkw)
        # set instance parameters
        self.src_list = src_list
        self.name = name
        self.src_interdep = src_interdep
        self.rup_interdep = rup_interdep
        if srcs_weights is None:
            self.srcs_weights = numpy.ones([len(src_list)])
            self.srcs_weights[0:-2] = Decimal(1./len(src_list))
            self.srcs_weights[-1] = 1 - numpy.sum(self.srcs_weights[0:-2])
        else:
            self.srcs_weights = srcs_weights
        self.tectonic_region_type = trt

    def _check_init_variables(self, src_list, name, src_interdep, rup_interdep,
                              srcs_weights, checkw):
{'fraction_non_alphanumeric': 0.07018970189701897, 'fraction_numerical': 0.004607046070460705, 'mean_word_length': 2.6467391304347827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1192534', 'n_tokens_mistral': 2078, 'n_tokens_neox': 2032, 'n_words': 729}