示例#1
0
def test_warning_message_is_none():
    assert (
        warning_message() ==
        os.linesep.join([
            "WARNING",
            "======="])
    )
示例#2
0
def test_warning_message():
    msg = "Pharetra pharetra massa massa ultricies mi quis hendrerit."

    assert warning_message(msg) == os.linesep.join([
        "WARNING",
        "=======",
        "",
        "Pharetra pharetra massa massa ultricies mi quis hendrerit.",
    ])
示例#3
0
def test_warning_message():
    msg = "Pharetra pharetra massa massa ultricies mi quis hendrerit."

    assert warning_message(msg) == os.linesep.join(
        [
            "WARNING",
            "=======",
            "",
            "Pharetra pharetra massa massa ultricies mi quis hendrerit.",
        ]
    )
示例#4
0
    def _add_depression_finder(self, depression_finder):
        """Test and add the depression finder component."""
        PERMITTED_DEPRESSION_FINDERS = ['DepressionFinderAndRouter']

        # now do a similar thing for the depression finder.
        self.depression_finder_provided = depression_finder
        if self.depression_finder_provided is not None:

            # collect potential kwargs to pass to depression_finder
            # instantiation
            potential_kwargs = ['routing']
            kw = {}
            for p_k in potential_kwargs:
                if p_k in self.kwargs.keys():
                    kw[p_k] = self.kwargs.pop(p_k)

            # NEED TO TEST WHICH FLOWDIRECTOR WAS PROVIDED.
            if self.flow_director._name in ('FlowDirectorMFD',
                                            'FlowDirectorDINF'):
                raise ValueError('The depression finder only works with route '
                                 'to one FlowDirectors such as '
                                 'FlowDirectorSteepest and  FlowDirectorD8. '
                                 'Provide a different FlowDirector.')

            # if D4 is being used here and should be.
            if ((('routing' not in kw) or (kw['routing'] != 'D4')) and
                isinstance(self._grid, RasterModelGrid) and
                (self.flow_director._name in('FlowDirectorSteepest'))):

                message = ('You have specified \n'
                           'flow_director=FlowDirectorSteepest and\n'
                           'depression_finder=DepressionFinderAndRouter\n'
                           'in the instantiation of FlowAccumulator on a '
                           'RasterModelGrid. The default behavior of '
                           'DepressionFinderAndRouter is to use D8 connectivity '
                           'which is in conflict with D4 connectivity used by '
                           'FlowDirectorSteepest. \n'
                           "To fix this, provide the kwarg routing='D4', when "
                           'you instantiate FlowAccumulator.')

                raise ValueError(warning_message(message))

            # depression finder is provided as a string.
            if isinstance(self.depression_finder_provided, six.string_types):

                from landlab.components import DepressionFinderAndRouter
                DEPRESSION_METHODS = {'DepressionFinderAndRouter': DepressionFinderAndRouter
                                    }

                try:
                    DepressionFinder = DEPRESSION_METHODS[self.depression_finder_provided]
                except KeyError:
                    raise ValueError('Component provided in depression_finder '
                                     'is not a valid component. The following '
                                     'components are valid imputs:\n' \
                                     + str(PERMITTED_DEPRESSION_FINDERS))

                self.depression_finder = DepressionFinder(self._grid, **kw)
            # flow director is provided as an instantiated depression finder
            elif isinstance(self.depression_finder_provided, Component):

                if self.depression_finder_provided._name in PERMITTED_DEPRESSION_FINDERS:
                    self.depression_finder = self.depression_finder_provided
                else:
                    raise ValueError('Component provided in depression_finder '
                                     'is not a valid component. The following '
                                     'components are valid imputs:\n' \
                                     + str(PERMITTED_DEPRESSION_FINDERS))

                if len(kw) > 0:
                    raise ValueError('flow_director provided as an instantiated ',
                                     'component and keyword arguments provided. ',
                                     'These kwargs would be ignored.')

                # if D4 is being used here and should be.
                if (self.depression_finder._D8 and
                    (self.flow_director._name in ('FlowDirectorSteepest'))):

                    message = ('You have specified \n'
                               'flow_director=FlowDirectorSteepest and\n'
                               'depression_finder=DepressionFinderAndRouter\n'
                               'in the instantiation of FlowAccumulator on a '
                               'RasterModelGrid. The behavior of the instantiated '
                               'DepressionFinderAndRouter is to use D8 connectivity '
                               'which is in conflict with D4 connectivity used by '
                               'FlowDirectorSteepest. \n'
                               "To fix this, provide the kwarg routing='D4', when "
                               'you instantiate DepressionFinderAndRouter.')

                    raise ValueError(warning_message(message))

            # depression_fiuner is provided as an uninstantiated depression finder
            else:

                if self.depression_finder_provided._name in PERMITTED_DEPRESSION_FINDERS:
                    DepressionFinder = self.depression_finder_provided
                    self.depression_finder = DepressionFinder(self._grid, **kw)
                else:
                    raise ValueError('Component provided in depression_finder '
                                     'is not a valid component. The following '
                                     'components are valid imputs:\n' \
                                     + str(PERMITTED_DEPRESSION_FINDERS))
        else:
            self.depression_finder = None
示例#5
0
    def _add_depression_finder(self, depression_finder):
        """Test and add the depression finder component."""
        PERMITTED_DEPRESSION_FINDERS = ["DepressionFinderAndRouter"]

        # now do a similar thing for the depression finder.
        self.depression_finder_provided = depression_finder
        if self.depression_finder_provided is not None:

            # collect potential kwargs to pass to depression_finder
            # instantiation
            potential_kwargs = ["routing"]
            kw = {}
            for p_k in potential_kwargs:
                if p_k in self.kwargs.keys():
                    kw[p_k] = self.kwargs.pop(p_k)

            # NEED TO TEST WHICH FLOWDIRECTOR WAS PROVIDED.
            if self.flow_director._name in ("FlowDirectorMFD",
                                            "FlowDirectorDINF"):
                msg = ("The depression finder only works with route "
                       "to one FlowDirectors such as "
                       "FlowDirectorSteepest and  FlowDirectorD8. "
                       "Provide a different FlowDirector.")
                raise NotImplementedError(msg)

            # if D4 is being used here and should be.
            if ((("routing" not in kw) or (kw["routing"] != "D4"))
                    and isinstance(self._grid, RasterModelGrid) and
                (self.flow_director._name in ("FlowDirectorSteepest"))):

                message = (
                    "You have specified \n"
                    "flow_director=FlowDirectorSteepest and\n"
                    "depression_finder=DepressionFinderAndRouter\n"
                    "in the instantiation of FlowAccumulator on a "
                    "RasterModelGrid. The default behavior of "
                    "DepressionFinderAndRouter is to use D8 connectivity "
                    "which is in conflict with D4 connectivity used by "
                    "FlowDirectorSteepest. \n"
                    "To fix this, provide the kwarg routing='D4', when "
                    "you instantiate FlowAccumulator.")

                raise ValueError(warning_message(message))

            # depression finder is provided as a string.
            if isinstance(self.depression_finder_provided, six.string_types):

                from landlab.components import DepressionFinderAndRouter

                DEPRESSION_METHODS = {
                    "DepressionFinderAndRouter": DepressionFinderAndRouter
                }

                try:
                    DepressionFinder = DEPRESSION_METHODS[
                        self.depression_finder_provided]
                except KeyError:
                    raise ValueError("Component provided in depression_finder "
                                     "is not a valid component. The following "
                                     "components are valid imputs:\n" +
                                     str(PERMITTED_DEPRESSION_FINDERS))

                self.depression_finder = DepressionFinder(self._grid, **kw)
            # flow director is provided as an instantiated depression finder
            elif isinstance(self.depression_finder_provided, Component):

                if (self.depression_finder_provided._name
                        in PERMITTED_DEPRESSION_FINDERS):
                    self.depression_finder = self.depression_finder_provided
                else:
                    raise ValueError("Component provided in depression_finder "
                                     "is not a valid component. The following "
                                     "components are valid imputs:\n" +
                                     str(PERMITTED_DEPRESSION_FINDERS))

                if len(kw) > 0:
                    raise ValueError(
                        "flow_director provided as an instantiated ",
                        "component and keyword arguments provided. ",
                        "These kwargs would be ignored.",
                    )

            # depression_fiuner is provided as an uninstantiated depression finder
            else:

                if (self.depression_finder_provided._name
                        in PERMITTED_DEPRESSION_FINDERS):
                    DepressionFinder = self.depression_finder_provided
                    self.depression_finder = DepressionFinder(self._grid, **kw)
                else:
                    raise ValueError("Component provided in depression_finder "
                                     "is not a valid component. The following "
                                     "components are valid imputs:\n" +
                                     str(PERMITTED_DEPRESSION_FINDERS))
        else:
            self.depression_finder = None
示例#6
0
    def _add_depression_finder(self, depression_finder):
        """Test and add the depression finder component."""
        PERMITTED_DEPRESSION_FINDERS = ["DepressionFinderAndRouter"]

        # now do a similar thing for the depression finder.
        self.depression_finder_provided = depression_finder
        if self.depression_finder_provided is not None:

            # collect potential kwargs to pass to depression_finder
            # instantiation
            potential_kwargs = ["routing"]
            kw = {}
            for p_k in potential_kwargs:
                if p_k in self.kwargs.keys():
                    kw[p_k] = self.kwargs.pop(p_k)

            # NEED TO TEST WHICH FLOWDIRECTOR WAS PROVIDED.
            if self.flow_director._name in ("FlowDirectorMFD", "FlowDirectorDINF"):
                msg = (
                    "The depression finder only works with route "
                    "to one FlowDirectors such as "
                    "FlowDirectorSteepest and  FlowDirectorD8. "
                    "Provide a different FlowDirector."
                )
                raise NotImplementedError(msg)

            # if D4 is being used here and should be.
            if (
                (("routing" not in kw) or (kw["routing"] != "D4"))
                and isinstance(self._grid, RasterModelGrid)
                and (self.flow_director._name in ("FlowDirectorSteepest"))
            ):

                message = (
                    "You have specified \n"
                    "flow_director=FlowDirectorSteepest and\n"
                    "depression_finder=DepressionFinderAndRouter\n"
                    "in the instantiation of FlowAccumulator on a "
                    "RasterModelGrid. The default behavior of "
                    "DepressionFinderAndRouter is to use D8 connectivity "
                    "which is in conflict with D4 connectivity used by "
                    "FlowDirectorSteepest. \n"
                    "To fix this, provide the kwarg routing='D4', when "
                    "you instantiate FlowAccumulator."
                )

                raise ValueError(warning_message(message))

            # depression finder is provided as a string.
            if isinstance(self.depression_finder_provided, six.string_types):

                from landlab.components import DepressionFinderAndRouter

                DEPRESSION_METHODS = {
                    "DepressionFinderAndRouter": DepressionFinderAndRouter
                }

                try:
                    DepressionFinder = DEPRESSION_METHODS[
                        self.depression_finder_provided
                    ]
                except KeyError:
                    raise ValueError(
                        "Component provided in depression_finder "
                        "is not a valid component. The following "
                        "components are valid imputs:\n"
                        + str(PERMITTED_DEPRESSION_FINDERS)
                    )

                self.depression_finder = DepressionFinder(self._grid, **kw)
            # flow director is provided as an instantiated depression finder
            elif isinstance(self.depression_finder_provided, Component):

                if (
                    self.depression_finder_provided._name
                    in PERMITTED_DEPRESSION_FINDERS
                ):
                    self.depression_finder = self.depression_finder_provided
                else:
                    raise ValueError(
                        "Component provided in depression_finder "
                        "is not a valid component. The following "
                        "components are valid imputs:\n"
                        + str(PERMITTED_DEPRESSION_FINDERS)
                    )

                if len(kw) > 0:
                    raise ValueError(
                        "flow_director provided as an instantiated ",
                        "component and keyword arguments provided. ",
                        "These kwargs would be ignored.",
                    )

            # depression_fiuner is provided as an uninstantiated depression finder
            else:

                if (
                    self.depression_finder_provided._name
                    in PERMITTED_DEPRESSION_FINDERS
                ):
                    DepressionFinder = self.depression_finder_provided
                    self.depression_finder = DepressionFinder(self._grid, **kw)
                else:
                    raise ValueError(
                        "Component provided in depression_finder "
                        "is not a valid component. The following "
                        "components are valid imputs:\n"
                        + str(PERMITTED_DEPRESSION_FINDERS)
                    )
        else:
            self.depression_finder = None
示例#7
0
    def _add_depression_finder(self, depression_finder):
        """Test and add the depression finder component."""
        PERMITTED_DEPRESSION_FINDERS = ['DepressionFinderAndRouter']

        # now do a similar thing for the depression finder.
        self.depression_finder_provided = depression_finder
        if self.depression_finder_provided is not None:

            # collect potential kwargs to pass to depression_finder
            # instantiation
            potential_kwargs = ['routing']
            kw = {}
            for p_k in potential_kwargs:
                if p_k in self.kwargs.keys():
                    kw[p_k] = self.kwargs.pop(p_k)

            # NEED TO TEST WHICH FLOWDIRECTOR WAS PROVIDED.
            if self.flow_director._name in ('FlowDirectorMFD',
                                            'FlowDirectorDINF'):
                raise ValueError('The depression finder only works with route '
                                 'to one FlowDirectors such as '
                                 'FlowDirectorSteepest and  FlowDirectorD8. '
                                 'Provide a different FlowDirector.')

            # if D4 is being used here and should be.
            if ((('routing' not in kw) or (kw['routing'] != 'D4'))
                    and isinstance(self._grid, RasterModelGrid) and
                (self.flow_director._name in ('FlowDirectorSteepest'))):

                message = (
                    'You have specified \n'
                    'flow_director=FlowDirectorSteepest and\n'
                    'depression_finder=DepressionFinderAndRouter\n'
                    'in the instantiation of FlowAccumulator on a '
                    'RasterModelGrid. The default behavior of '
                    'DepressionFinderAndRouter is to use D8 connectivity '
                    'which is in conflict with D4 connectivity used by '
                    'FlowDirectorSteepest. \n'
                    "To fix this, provide the kwarg routing='D4', when "
                    'you instantiate FlowAccumulator.')

                raise ValueError(warning_message(message))

            # depression finder is provided as a string.
            if isinstance(self.depression_finder_provided, six.string_types):

                from landlab.components import DepressionFinderAndRouter
                DEPRESSION_METHODS = {
                    'DepressionFinderAndRouter': DepressionFinderAndRouter
                }

                try:
                    DepressionFinder = DEPRESSION_METHODS[
                        self.depression_finder_provided]
                except KeyError:
                    raise ValueError('Component provided in depression_finder '
                                     'is not a valid component. The following '
                                     'components are valid imputs:\n' \
                                     + str(PERMITTED_DEPRESSION_FINDERS))

                self.depression_finder = DepressionFinder(self._grid, **kw)
            # flow director is provided as an instantiated depression finder
            elif isinstance(self.depression_finder_provided, Component):

                if self.depression_finder_provided._name in PERMITTED_DEPRESSION_FINDERS:
                    self.depression_finder = self.depression_finder_provided
                else:
                    raise ValueError('Component provided in depression_finder '
                                     'is not a valid component. The following '
                                     'components are valid imputs:\n' \
                                     + str(PERMITTED_DEPRESSION_FINDERS))

                if len(kw) > 0:
                    raise ValueError(
                        'flow_director provided as an instantiated ',
                        'component and keyword arguments provided. ',
                        'These kwargs would be ignored.')

                # if D4 is being used here and should be.
                if (self.depression_finder._D8 and
                    (self.flow_director._name in ('FlowDirectorSteepest'))):

                    message = (
                        'You have specified \n'
                        'flow_director=FlowDirectorSteepest and\n'
                        'depression_finder=DepressionFinderAndRouter\n'
                        'in the instantiation of FlowAccumulator on a '
                        'RasterModelGrid. The behavior of the instantiated '
                        'DepressionFinderAndRouter is to use D8 connectivity '
                        'which is in conflict with D4 connectivity used by '
                        'FlowDirectorSteepest. \n'
                        "To fix this, provide the kwarg routing='D4', when "
                        'you instantiate DepressionFinderAndRouter.')

                    raise ValueError(warning_message(message))

            # depression_fiuner is provided as an uninstantiated depression finder
            else:

                if self.depression_finder_provided._name in PERMITTED_DEPRESSION_FINDERS:
                    DepressionFinder = self.depression_finder_provided
                    self.depression_finder = DepressionFinder(self._grid, **kw)
                else:
                    raise ValueError('Component provided in depression_finder '
                                     'is not a valid component. The following '
                                     'components are valid imputs:\n' \
                                     + str(PERMITTED_DEPRESSION_FINDERS))
        else:
            self.depression_finder = None