<commit_before>__author__ = 'giacomov'

import collections
import os
import warnings

from astromodels.sources.source import POINT_SOURCE, EXTENDED_SOURCE, PARTICLE_SOURCE

from astromodels.my_yaml import my_yaml
from astromodels.utils.disk_usage import disk_usage
from astromodels.utils.table import dict_to_table
from astromodels.parameter import Parameter, IndependentVariable
from astromodels.tree import Node, DuplicatedNode
from astromodels.functions.function import get_function


class ModelFileExists(IOError):
    pass


class InvalidInput(ValueError):
    pass


class CannotWriteModel(IOError):
    def __init__(self, directory, message):
        # Add a report on disk usage to the message

        free_space = disk_usage(directory).free

        message += "\nFree space on the file system hosting %s was %.2f Mbytes" % (
            directory, free_space / 1024.0 / 1024.0)

        super(CannotWriteModel, self).__init__(message)


class ModelInternalError(ValueError):

    pass


class Model(Node):

    def __init__(self, *sources):

        # There must be at least one source
        assert len(sources) > 0, "You need to have at least one source in the model."

        # Setup the node

        super(Model, self).__init__("root")

        # Dictionary to keep point sources

        self._point_sources = collections.OrderedDict()

        # Dictionary to keep extended sources

        self._extended_sources = collections.OrderedDict()

        # Dictionary to keep particle sources

        self._particle_sources = collections.OrderedDict()

        # Loop over the provided sources and process them

        for source in sources:

            try:

                self._add_child(source)

            except AttributeError:

                raise InvalidInput("The source name '%s' cannot be used, as it is a protected name. Please use a "
                                   "different name." % source.name)

            except DuplicatedNode:<commit_msg>Improved reporting of errors during initialization<commit_after>__author__ = 'giacomov'

import collections
import os
import warnings

from astromodels.sources.source import Source, POINT_SOURCE, EXTENDED_SOURCE, PARTICLE_SOURCE

from astromodels.my_yaml import my_yaml
from astromodels.utils.disk_usage import disk_usage
from astromodels.utils.table import dict_to_table
from astromodels.parameter import Parameter, IndependentVariable
from astromodels.tree import Node, DuplicatedNode
from astromodels.functions.function import get_function


class ModelFileExists(IOError):
    pass


class InvalidInput(ValueError):
    pass


class CannotWriteModel(IOError):
    def __init__(self, directory, message):
        # Add a report on disk usage to the message

        free_space = disk_usage(directory).free

        message += "\nFree space on the file system hosting %s was %.2f Mbytes" % (
            directory, free_space / 1024.0 / 1024.0)

        super(CannotWriteModel, self).__init__(message)


class ModelInternalError(ValueError):

    pass


class Model(Node):

    def __init__(self, *sources):

        # There must be at least one source
        assert len(sources) > 0, "You need to have at least one source in the model."

        # Setup the node

        super(Model, self).__init__("root")

        # Dictionary to keep point sources

        self._point_sources = collections.OrderedDict()

        # Dictionary to keep extended sources

        self._extended_sources = collections.OrderedDict()

        # Dictionary to keep particle sources

        self._particle_sources = collections.OrderedDict()

        # Loop over the provided sources and process them

        for source in sources:

            try:

                self._add_child(source)

            except AttributeError:

                if isinstance(source, Source):

                    raise InvalidInput("The source name '%s' cannot be used, as it is a protected name. Please use a "
                                       "different name." % source.name)

                else:

                    raise

            except DuplicatedNode:
{'fraction_non_alphanumeric': 0.06448484848484848, 'fraction_numerical': 0.005818181818181818, 'mean_word_length': 2.693822739480752, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '726757', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1034, 'n_words': 360}