Exemplo n.º 1
0
    def check(self, f=None, verbose=True, level=1):
        """
        Check package data for common errors.

        Parameters
        ----------
        f : str or file handle
            String defining file name or file handle for summary file
            of check method output. If a string is passed a file handle
            is created. If f is None, check method does not write
            results to a summary file. (default is None)
        verbose : bool
            Boolean flag used to determine if check method results are
            written to the screen.
        level : int
            Check method analysis level. If level=0, summary checks are
            performed. If level=1, full checks are performed.

        Returns
        -------
        None

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow.load('model.nam')
        >>> m.riv.check()

        """
        basechk = super(ModflowRiv, self).check(verbose=False)
        chk = check(self, f=f, verbose=verbose, level=level)
        chk.summary_array = basechk.summary_array

        for per in self.stress_period_data.data.keys():
            if isinstance(self.stress_period_data.data[per], np.recarray):
                spd = self.stress_period_data.data[per]
                inds = (spd.k, spd.i, spd.j) if self.parent.structured else (spd.node)

                # check that river stage and bottom are above model cell bottoms
                # also checks for nan values
                botms = self.parent.dis.botm.array[inds]

                for elev in ['stage', 'rbot']:
                    chk.stress_period_data_values(spd, spd[elev] < botms,
                                                  col=elev,
                                                  error_name='{} below cell bottom'.format(elev),
                                                  error_type='Error')

                # check that river stage is above the rbot
                chk.stress_period_data_values(spd, spd['rbot'] > spd['stage'],
                                              col='stage',
                                              error_name='RIV stage below rbots',
                                              error_type='Error')
        chk.summarize()
        return chk
Exemplo n.º 2
0
    def check(self, f=None, verbose=True, level=1):
        """
        Check model data for common errors.

        Parameters
        ----------
        f : str or file handle
            String defining file name or file handle for summary file
            of check method output. If a string is passed a file handle
            is created. If f is None, check method does not write
            results to a summary file. (default is None)
        verbose : bool
            Boolean flag used to determine if check method results are
            written to the screen
        level : int
            Check method analysis level. If level=0, summary checks are
            performed. If level=1, full checks are performed.

        Returns
        -------
        None

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow.load('model.nam')
        >>> m.check()
        """

        results = {}
        for p in self.packagelist:
            results[p.name[0]] = p.check(f=None, verbose=False,
                                         level=level - 1)

        # check instance for model-level check
        chk = utils.check(self, f=f, verbose=verbose, level=level)

        # model level checks
        # solver check
        if self.version in chk.solver_packages.keys():
            solvers = set(chk.solver_packages[self.version]).intersection(
                set(self.get_package_list()))
            if not solvers:
                chk._add_to_summary('Error', desc='\r    No solver package',
                                    package='model')
            elif len(list(solvers)) > 1:
                for s in solvers:
                    chk._add_to_summary('Error',
                                        desc='\r    Multiple solver packages',
                                        package=s)
            else:
                chk.passed.append('Compatible solver package')

        # check for unit number conflicts
        package_units = {}
        duplicate_units = {}
        for p in self.packagelist:
            for i in range(len(p.name)):
                if p.unit_number[i] != 0:
                    if p.unit_number[i] in package_units.values():
                        duplicate_units[p.name[i]] = p.unit_number[i]
                        otherpackage = [k for k, v in package_units.items()
                                        if v == p.unit_number[i]][0]
                        duplicate_units[otherpackage] = p.unit_number[i]
        if len(duplicate_units) > 0:
            for k, v in duplicate_units.items():
                chk._add_to_summary('Error', package=k, value=v,
                                    desc='unit number conflict')
        else:
            chk.passed.append('Unit number conflicts')

        # add package check results to model level check summary
        for k, r in results.items():
            if r is not None and r.summary_array is not None:  # currently SFR doesn't have one
                chk.summary_array = np.append(chk.summary_array,
                                              r.summary_array).view(
                    np.recarray)
                chk.passed += ['{} package: {}'.format(r.package.name[0], psd)
                               for psd in r.passed]
        chk.summarize()
        return chk
Exemplo n.º 3
0
    def check(self, f=None, verbose=True, level=1):
        """
        Check model data for common errors.

        Parameters
        ----------
        f : str or file handle
            String defining file name or file handle for summary file
            of check method output. If a string is passed a file handle
            is created. If f is None, check method does not write
            results to a summary file. (default is None)
        verbose : bool
            Boolean flag used to determine if check method results are
            written to the screen
        level : int
            Check method analysis level. If level=0, summary checks are
            performed. If level=1, full checks are performed.

        Returns
        -------
        None

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow.load('model.nam')
        >>> m.check()
        """

        results = {}
        for p in self.packagelist:
            results[p.name[0]] = p.check(f=None, verbose=False,
                                         level=level - 1)

        # check instance for model-level check
        chk = utils.check(self, f=f, verbose=verbose, level=level)

        # model level checks
        # solver check
        if self.version in chk.solver_packages.keys():
            solvers = set(chk.solver_packages[self.version]).intersection(
                set(self.get_package_list()))
            if not solvers:
                chk._add_to_summary('Error', desc='\r    No solver package',
                                    package='model')
            elif len(list(solvers)) > 1:
                for s in solvers:
                    chk._add_to_summary('Error',
                                        desc='\r    Multiple solver packages',
                                        package=s)
            else:
                chk.passed.append('Compatible solver package')

        # check for unit number conflicts
        package_units = {}
        duplicate_units = {}
        for p in self.packagelist:
            for i in range(len(p.name)):
                if p.unit_number[i] != 0:
                    if p.unit_number[i] in package_units.values():
                        duplicate_units[p.name[i]] = p.unit_number[i]
                        otherpackage = [k for k, v in package_units.items()
                                        if v == p.unit_number[i]][0]
                        duplicate_units[otherpackage] = p.unit_number[i]
        if len(duplicate_units) > 0:
            for k, v in duplicate_units.items():
                chk._add_to_summary('Error', package=k, value=v,
                                    desc='unit number conflict')
        else:
            chk.passed.append('Unit number conflicts')

        # add package check results to model level check summary
        for k, r in results.items():
            if r is not None and r.summary_array is not None:  # currently SFR doesn't have one
                chk.summary_array = np.append(chk.summary_array,
                                              r.summary_array).view(
                    np.recarray)
                chk.passed += ['{} package: {}'.format(r.package.name[0], psd)
                               for psd in r.passed]
        chk.summarize()
        return chk
Exemplo n.º 4
0
    def check(self, f=None, verbose=True, level=1):
        """
        Check package data for common errors.

        Parameters
        ----------
        f : str or file handle
            String defining file name or file handle for summary file
            of check method output. If a string is passed a file handle
            is created. If f is None, check method does not write
            results to a summary file. (default is None)
        verbose : bool
            Boolean flag used to determine if check method results are
            written to the screen.
        level : int
            Check method analysis level. If level=0, summary checks are
            performed. If level=1, full checks are performed.

        Returns
        -------
        None

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow.load('model.nam')
        >>> m.riv.check()

        """
        basechk = super(ModflowRiv, self).check(verbose=False)
        chk = check(self, f=f, verbose=verbose, level=level)
        chk.summary_array = basechk.summary_array

        for per in self.stress_period_data.data.keys():
            if isinstance(self.stress_period_data.data[per], np.recarray):
                spd = self.stress_period_data.data[per]
                inds = (spd.k, spd.i,
                        spd.j) if self.parent.structured else (spd.node)

                # check that river stage and bottom are above model cell bottoms
                # also checks for nan values
                botms = self.parent.dis.botm.array[inds]

                for elev in ['stage', 'rbot']:
                    chk.stress_period_data_values(
                        spd,
                        spd[elev] < botms,
                        col=elev,
                        error_name='{} below cell bottom'.format(elev),
                        error_type='Error')

                # check that river stage is above the rbot
                chk.stress_period_data_values(
                    spd,
                    spd['rbot'] > spd['stage'],
                    col='stage',
                    error_name='RIV stage below rbots',
                    error_type='Error')
        chk.summarize()
        return chk