def elevations(self):
        headertxt = 'Checking segment_data for downstream rises in streambed elevation...\n'
        txt = ''
        if self.verbose:
            print(headertxt.strip())

        # decide whether to check elevup and elevdn from items 6b/c
        # (see online guide to SFR input; Data Set 6b description)
        passed = False
        if self.sfr.isfropt in [0, 4, 5]:
            pers = sorted(self.segment_data.keys())
            for per in pers:
                segment_data = self.segment_data[per][self.segment_data[per].elevup > -999999]

                # enforce consecutive increasing segment numbers (for indexing)
                segment_data.sort(order='nseg')
                t = _check_numbers(len(segment_data), segment_data.nseg, level=1, datatype='Segment')
                if len(t) > 0:
                    raise Exception('Elevation check requires consecutive segment numbering.')

                # first check for segments where elevdn > elevup
                d_elev = segment_data.elevdn - segment_data.elevup
                segment_data = recfunctions.append_fields(segment_data, names='d_elev', data=d_elev,
                                                          asrecarray=True)
                txt += self._boolean_compare(segment_data[['nseg', 'outseg', 'elevup', 'elevdn',
                                                           'd_elev']].copy(),
                                             col1='d_elev', col2=np.zeros(len(segment_data)),
                                             level0txt='Stress Period {}: '.format(per + 1) + \
                                                       '{} segments encountered with elevdn > elevup.',
                                             level1txt='Backwards segments:',
                                             )

                # next check for rises between segments
                non_outlets = segment_data.outseg > 0
                non_outlets_seg_data = segment_data[non_outlets]  # lake outsegs are < 0
                outseg_elevup = np.array([segment_data.elevup[o - 1] for o in segment_data.outseg if o > 0])
                d_elev2 = outseg_elevup - segment_data.elevdn[non_outlets]
                non_outlets_seg_data = recfunctions.append_fields(non_outlets_seg_data,
                                                                  names=['outseg_elevup', 'd_elev2'],
                                                                  data=[outseg_elevup, d_elev2],
                                                                  asrecarray=True)

                txt += self._boolean_compare(non_outlets_seg_data[['nseg', 'outseg', 'elevdn',
                                                                   'outseg_elevup', 'd_elev2']].copy(),
                                             col1='d_elev2', col2=np.zeros(len(non_outlets_seg_data)),
                                             level0txt='Stress Period {}: '.format(per + 1) + \
                                                       '{} segments encountered with segments encountered ' \
                                                       'with outseg elevup > elevdn.',
                                             level1txt='Backwards segment connections:',
                                             )

            if len(txt) == 0:
                passed = True
        else:
            txt += 'Segment elevup and elevdn not specified for nstrm={} and isfropt={}\n' \
                .format(self.sfr.nstrm, self.sfr.isfropt)
            passed = True
        self._txt_footer(headertxt, txt, 'segment elevations', passed)

        headertxt = 'Checking reach_data for downstream rises in streambed elevation...\n'
        txt = ''
        if self.verbose:
            print(headertxt.strip())
        passed = False
        if self.sfr.nstrm < 0 or self.sfr.reachinput and self.sfr.isfropt in [1, 2, 3]:  # see SFR input instructions
            # first get an outreach for each reach
            if np.diff(self.sfr.reach_data.outreach).max() == 0:  # not sure if this is the best test
                self.sfr.get_outreaches()
            reach_data = self.sfr.reach_data  # inconsistent with other checks that work with
            # reach_data attribute of check class. Want to have get_outreaches as a method of sfr class
            # (for other uses). Not sure if other check methods should also copy reach_data directly from
            # SFR package instance for consistency.

            # use outreach values to get downstream elevations
            non_outlets = reach_data[reach_data.outreach != 0]
            outreach_elevdn = np.array([reach_data.strtop[o - 1] for o in reach_data.outreach])
            d_strtop = outreach_elevdn[reach_data.outreach != 0] - non_outlets.strtop
            non_outlets = recfunctions.append_fields(non_outlets,
                                                     names=['strtopdn', 'd_strtop'],
                                                     data=[outreach_elevdn, d_strtop],
                                                     asrecarray=True)

            txt += self._boolean_compare(non_outlets[['k', 'i', 'j', 'iseg', 'ireach',
                                                      'strtop', 'strtopdn', 'd_strtop', 'reachID']].copy(),
                                         col1='d_strtop', col2=np.zeros(len(non_outlets)),
                                         level0txt='{} reaches encountered with strtop < strtop of downstream reach.',
                                         level1txt='Elevation rises:',
                                         )

            if len(txt) == 0:
                passed = True
        else:
            txt += 'Reach strtop not specified for nstrm={}, reachinput={} and isfropt={}\n' \
                .format(self.sfr.nstrm, self.sfr.reachinput, self.sfr.isfropt)
            passed = True
        self._txt_footer(headertxt, txt, 'reach elevations', passed)

        headertxt = 'Checking reach_data for inconsistencies between streambed elevations and the model grid...\n'
        if self.verbose:
            print(headertxt.strip())
        txt = ''
        if self.sfr.parent.dis is None:
            txt += 'No DIS file supplied; cannot check SFR elevations agains model grid.'
            self._txt_footer(headertxt, txt, '')
            return
        passed = False
        warning = True
        if self.sfr.nstrm < 0 or self.sfr.reachinput and self.sfr.isfropt in [1, 2, 3]:  # see SFR input instructions
            reach_data = self.reach_data
            i, j, k = reach_data.i, reach_data.j, reach_data.k

            # check streambed bottoms in relation to respective cell bottoms
            bots = self.sfr.parent.dis.botm.array[k, i, j]
            streambed_bots = reach_data.strtop - reach_data.strthick
            reach_data = recfunctions.append_fields(reach_data,
                                                    names=['layerbot', 'strbot'],
                                                    data=[bots, streambed_bots],
                                                    asrecarray=True)

            txt += self._boolean_compare(reach_data[['k', 'i', 'j', 'iseg', 'ireach',
                                                     'strtop', 'strthick', 'strbot', 'layerbot',
                                                     'reachID']].copy(),
                                         col1='layerbot', col2='strbot',
                                         level0txt='{} reaches encountered with streambed bottom below layer bottom.',
                                         level1txt='Layer bottom violations:',
                                         )
            if len(txt) > 0:
                warning = False # this constitutes an error (MODFLOW won't run)
            # check streambed elevations in relation to model top
            tops = self.sfr.parent.dis.top.array[i, j]
            reach_data = recfunctions.append_fields(reach_data, names='modeltop', data=tops, asrecarray=True)

            txt += self._boolean_compare(reach_data[['k', 'i', 'j', 'iseg', 'ireach',
                                                     'strtop', 'modeltop', 'reachID']].copy(),
                                         col1='strtop', col2='modeltop',
                                         level0txt='{} reaches encountered with streambed above model top.',
                                         level1txt='Model top violations:',
                                         )

            if len(txt) == 0:
                passed = True
        else:
            txt += 'Reach strtop, strthick not specified for nstrm={}, reachinput={} and isfropt={}\n' \
                .format(self.sfr.nstrm, self.sfr.reachinput, self.sfr.isfropt)
            passed = True
        self._txt_footer(headertxt, txt, 'reach elevations vs. grid elevations', passed, warning=warning)

        # In cases where segment end elevations/thicknesses are used,
        # do these need to be checked for consistency with layer bottoms?

        headertxt = 'Checking segment_data for inconsistencies between segment end elevations and the model grid...\n'
        txt = ''
        if self.verbose:
            print(headertxt.strip())
        passed = False
        if self.sfr.isfropt in [0, 4, 5]:
            reach_data = self.reach_data
            pers = sorted(self.segment_data.keys())
            for per in pers:
                segment_data = self.segment_data[per][self.segment_data[per].elevup > -999999]

                # enforce consecutive increasing segment numbers (for indexing)
                segment_data.sort(order='nseg')
                t = _check_numbers(len(segment_data), segment_data.nseg, level=1, datatype='Segment')
                if len(t) > 0:
                    raise Exception('Elevation check requires consecutive segment numbering.')

            first_reaches = reach_data[reach_data.ireach == 1].copy()
            last_reaches = reach_data[np.append((np.diff(reach_data.iseg) == 1), True)].copy()
            segment_ends = recfunctions.stack_arrays([first_reaches, last_reaches],
                                                     asrecarray=True, usemask=False)
            segment_ends['strtop'] = np.append(segment_data.elevup, segment_data.elevdn)
            i, j = segment_ends.i, segment_ends.j
            tops = self.sfr.parent.dis.top.array[i, j]
            diff = tops - segment_ends.strtop
            segment_ends = recfunctions.append_fields(segment_ends,
                                                      names=['modeltop', 'diff'],
                                                      data=[tops, diff],
                                                      asrecarray=True)

            txt += self._boolean_compare(segment_ends[['k', 'i', 'j', 'iseg',
                                                       'strtop', 'modeltop', 'diff', 'reachID']].copy(),
                                         col1=np.zeros(len(segment_ends)), col2='diff',
                                         level0txt='{} reaches encountered with streambed above model top.',
                                         level1txt='Model top violations:',
                                         )

            if len(txt) == 0:
                passed = True
        else:
            txt += 'Segment elevup and elevdn not specified for nstrm={} and isfropt={}\n' \
                .format(self.sfr.nstrm, self.sfr.isfropt)
            passed = True
        self._txt_footer(headertxt, txt, 'segment elevations vs. model grid', passed)
We intercept the response coming back from the main
dataset/ETHPy150Open modflowpy/flopy/flopy/modflow/mfsfr2.py/check.elevations--crossover with--dataset/ETHPy150Open rcbops/glance-buildpackage/glance/api/middleware/cache.py/CacheFilter.process_response