/* Generated by Cython 0.28.3 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "C:\\Python36\\lib\\site-packages\\numpy\\core\\include\\numpy\\arrayobject.h",
            "C:\\Python36\\lib\\site-packages\\numpy\\core\\include\\numpy\\ufuncobject.h",
            "src\\pygeoprocessing\\routing\\LRUCache.h"
        ],
        "include_dirs": [
            "src/pygeoprocessing/routing",
            "C:\\Python36\\lib\\site-packages\\numpy\\core\\include"
        ],
        "language": "c++",
        "name": "pygeoprocessing.routing.routing",
        "sources": [
            "src/pygeoprocessing/routing/routing.pyx"
        ]
    },
    "module_name": "pygeoprocessing.routing.routing"
}
END: Cython Metadata */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.6+ or Python 3.3+.
#else
#define CYTHON_ABI "0_28_3"
#define CYTHON_FUTURE_DIVISION 0
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x02070000
    #define HAVE_LONG_LONG
  #endif
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 0
  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
  #undef SHIFT
  #undef BASE
  #undef MASK
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_MAYBE_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned char     uint8_t;
           typedef unsigned int      uint32_t;
        #else
           typedef unsigned __int8   uint8_t;
           typedef unsigned __int32  uint32_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus) && __cplusplus >= 201103L
    #if __has_cpp_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH [[fallthrough]]
    #elif __has_cpp_attribute(clang::fallthrough)
      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
    #elif __has_cpp_attribute(gnu::fallthrough)
      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__ ) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif

#ifndef __cplusplus
  #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
#endif
#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #else
    #define CYTHON_INLINE inline
  #endif
#endif
template<typename T>
void __Pyx_call_destructor(T& x) {
    x.~T();
}
template<typename T>
class __Pyx_FakeReference {
  public:
    __Pyx_FakeReference() : ptr(NULL) { }
    __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
    T *operator->() { return ptr; }
    T *operator&() { return ptr; }
    operator T&() { return *ptr; }
    template<typename U> bool operator ==(U other) { return *ptr == other; }
    template<typename U> bool operator !=(U other) { return *ptr != other; }
  private:
    T *ptr;
};

#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0; // PyThread_create_key reports success always
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif // TSS (Thread Specific Storage) API
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
  #define PyObject_Unicode             PyObject_Str
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
#else
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif


#define __PYX_ERR(f_index, lineno, Ln_error) \
{ \
  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
}

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__pygeoprocessing__routing__routing
#define __PYX_HAVE_API__pygeoprocessing__routing__routing
/* Early includes */
#include <string.h>
#include <stdio.h>
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#include <stddef.h>
#include <time.h>
#include "ios"
#include "new"
#include "stdexcept"
#include "typeinfo"
#include <list>
#include <utility>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include "LRUCache.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

static PyObject *__pyx_m = NULL;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime = NULL;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;

/* Header.proto */
#if !defined(CYTHON_CCOMPLEX)
  #if defined(__cplusplus)
    #define CYTHON_CCOMPLEX 1
  #elif defined(_Complex_I)
    #define CYTHON_CCOMPLEX 1
  #else
    #define CYTHON_CCOMPLEX 0
  #endif
#endif
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #include <complex>
  #else
    #include <complex.h>
  #endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
  #undef _Complex_I
  #define _Complex_I 1.0fj
#endif


static const char *__pyx_f[] = {
  "src\\pygeoprocessing\\routing\\routing.pyx",
  "stringsource",
  "__init__.pxd",
  "type.pxd",
};
/* BufferFormatStructs.proto */
#define IS_UNSIGNED(type) (((type) -1) > 0)
struct __Pyx_StructField_;
#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0)
typedef struct {
  const char* name;
  struct __Pyx_StructField_* fields;
  size_t size;
  size_t arraysize[8];
  int ndim;
  char typegroup;
  char is_unsigned;
  int flags;
} __Pyx_TypeInfo;
typedef struct __Pyx_StructField_ {
  __Pyx_TypeInfo* type;
  const char* name;
  size_t offset;
} __Pyx_StructField;
typedef struct {
  __Pyx_StructField* field;
  size_t parent_offset;
} __Pyx_BufFmt_StackElem;
typedef struct {
  __Pyx_StructField root;
  __Pyx_BufFmt_StackElem* head;
  size_t fmt_offset;
  size_t new_count, enc_count;
  size_t struct_alignment;
  int is_complex;
  char enc_type;
  char new_packmode;
  char enc_packmode;
  char is_valid_array;
} __Pyx_BufFmt_Context;


/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":730
 * # in Cython to enable them only on the right systems.
 * 
 * ctypedef npy_int8       int8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 */
typedef npy_int8 __pyx_t_5numpy_int8_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":731
 * 
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t
 */
typedef npy_int16 __pyx_t_5numpy_int16_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":732
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int64      int64_t
 * #ctypedef npy_int96      int96_t
 */
typedef npy_int32 __pyx_t_5numpy_int32_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":733
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_int96      int96_t
 * #ctypedef npy_int128     int128_t
 */
typedef npy_int64 __pyx_t_5numpy_int64_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":737
 * #ctypedef npy_int128     int128_t
 * 
 * ctypedef npy_uint8      uint8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 */
typedef npy_uint8 __pyx_t_5numpy_uint8_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":738
 * 
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t
 */
typedef npy_uint16 __pyx_t_5numpy_uint16_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":739
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint64     uint64_t
 * #ctypedef npy_uint96     uint96_t
 */
typedef npy_uint32 __pyx_t_5numpy_uint32_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":740
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_uint96     uint96_t
 * #ctypedef npy_uint128    uint128_t
 */
typedef npy_uint64 __pyx_t_5numpy_uint64_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":744
 * #ctypedef npy_uint128    uint128_t
 * 
 * ctypedef npy_float32    float32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_float64    float64_t
 * #ctypedef npy_float80    float80_t
 */
typedef npy_float32 __pyx_t_5numpy_float32_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":745
 * 
 * ctypedef npy_float32    float32_t
 * ctypedef npy_float64    float64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_float80    float80_t
 * #ctypedef npy_float128   float128_t
 */
typedef npy_float64 __pyx_t_5numpy_float64_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":754
 * # The int types are mapped a bit surprising --
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t
 */
typedef npy_long __pyx_t_5numpy_int_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":755
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   longlong_t
 * 
 */
typedef npy_longlong __pyx_t_5numpy_long_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":756
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_ulong      uint_t
 */
typedef npy_longlong __pyx_t_5numpy_longlong_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":758
 * ctypedef npy_longlong   longlong_t
 * 
 * ctypedef npy_ulong      uint_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t
 */
typedef npy_ulong __pyx_t_5numpy_uint_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":759
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":760
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_intp       intp_t
 */
typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":762
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":763
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":765
 * ctypedef npy_uintp      uintp_t
 * 
 * ctypedef npy_double     float_t             # <<<<<<<<<<<<<<
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t
 */
typedef npy_double __pyx_t_5numpy_float_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":766
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":767
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cfloat      cfloat_t
 */
typedef npy_longdouble __pyx_t_5numpy_longdouble_t;
/* Declarations.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< float > __pyx_t_float_complex;
  #else
    typedef float _Complex __pyx_t_float_complex;
  #endif
#else
    typedef struct { float real, imag; } __pyx_t_float_complex;
#endif
static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

/* Declarations.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< double > __pyx_t_double_complex;
  #else
    typedef double _Complex __pyx_t_double_complex;
  #endif
#else
    typedef struct { double real, imag; } __pyx_t_double_complex;
#endif
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);


/*--- Type declarations ---*/
struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":769
 * ctypedef npy_longdouble longdouble_t
 * 
 * ctypedef npy_cfloat      cfloat_t             # <<<<<<<<<<<<<<
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t
 */
typedef npy_cfloat __pyx_t_5numpy_cfloat_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":770
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":771
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cdouble     complex_t
 */
typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":773
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;
struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType;
struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType;
struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType;
struct __pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel;

/* "pygeoprocessing/routing/routing.pyx":109
 * 
 * # this is the class type that'll get stored in the priority queue
 * cdef struct PixelType:             # <<<<<<<<<<<<<<
 *     double value  # pixel value
 *     int xi  # pixel x coordinate in the raster
 */
struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType {
  double value;
  int xi;
  int yi;
  int priority;
};

/* "pygeoprocessing/routing/routing.pyx":117
 * # this struct is used to record an intermediate flow pixel's last calculated
 * # direction and the flow accumulation value so far
 * cdef struct FlowPixelType:             # <<<<<<<<<<<<<<
 *     int xi
 *     int yi
 */
struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType {
  int xi;
  int yi;
  int last_flow_dir;
  double value;
};

/* "pygeoprocessing/routing/routing.pyx":124
 * 
 * # used to record x/y locations as needed
 * cdef struct CoordinateType:             # <<<<<<<<<<<<<<
 *     int xi
 *     int yi
 */
struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType {
  int xi;
  int yi;
};

/* "pygeoprocessing/routing/routing.pyx":130
 * # this ctype is used to store the block ID and the block buffer as one object
 * # inside Managed Raster
 * ctypedef pair[int, double*] BlockBufferPair             # <<<<<<<<<<<<<<
 * 
 * # this type is used to create a priority queue on the custom Pixel tpye
 */
typedef std::pair<int,double *>  __pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair;

/* "pygeoprocessing/routing/routing.pyx":133
 * 
 * # this type is used to create a priority queue on the custom Pixel tpye
 * ctypedef priority_queue[             # <<<<<<<<<<<<<<
 *     PixelType, deque[PixelType], GreaterPixel] PitPriorityQueueType
 * 
 */
typedef std::priority_queue<struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType,std::deque<struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType> ,__pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel>  __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType;

/* "pygeoprocessing/routing/routing.pyx":137
 * 
 * # this queue is used to record flow directions
 * ctypedef queue[int] IntQueueType             # <<<<<<<<<<<<<<
 * 
 * # type used to store x/y coordinates and a queue to put them in
 */
typedef std::queue<int>  __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType;

/* "pygeoprocessing/routing/routing.pyx":140
 * 
 * # type used to store x/y coordinates and a queue to put them in
 * ctypedef queue[CoordinateType] CoordinateQueueType             # <<<<<<<<<<<<<<
 * 
 * # functor for priority queue of pixels
 */
typedef std::queue<struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType>  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType;
struct __pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel {
  virtual int operator()(struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType &, struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType &);
  virtual ~__pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel() {

    /* "pygeoprocessing/routing/routing.pyx":143
 * 
 * # functor for priority queue of pixels
 * cdef cppclass GreaterPixel nogil:             # <<<<<<<<<<<<<<
 *     bint get "operator()"(PixelType& lhs, PixelType& rhs):
 *         # lhs is > than rhs if its value is greater or if it's equal if
 */
  }
};

/* "pygeoprocessing/routing/routing.pyx":159
 * # a class to allow fast random per-pixel access to a raster for both setting
 * # and reading pixels.
 * cdef class _ManagedRaster:             # <<<<<<<<<<<<<<
 *     cdef LRUCache[int, double*]* lru_cache
 *     cdef cset[int] dirty_blocks
 */
struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster {
  PyObject_HEAD
  struct __pyx_vtabstruct_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_vtab;
  LRUCache<int,double *>  *lru_cache;
  std::set<int>  dirty_blocks;
  int block_xsize;
  int block_ysize;
  int block_xmod;
  int block_ymod;
  int block_xbits;
  int block_ybits;
  int raster_x_size;
  int raster_y_size;
  int block_nx;
  int block_ny;
  int write_mode;
  PyObject *raster_path;
  int band_id;
  int closed;
};



struct __pyx_vtabstruct_15pygeoprocessing_7routing_7routing__ManagedRaster {
  void (*set)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int, double);
  double (*get)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int);
  void (*_load_block)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int);
};
static struct __pyx_vtabstruct_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_vtabptr_15pygeoprocessing_7routing_7routing__ManagedRaster;
static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int, double);
static CYTHON_INLINE double __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int);

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

/* GetModuleGlobalName.proto */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#endif

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);
#define __Pyx_PyObject_Dict_GetItem(obj, name)\
    (likely(PyDict_CheckExact(obj)) ?\
     __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
#else
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
#endif

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* None.proto */
static CYTHON_INLINE long __Pyx_div_long(long, long);

/* UnaryNegOverflows.proto */
#define UNARY_NEG_WOULD_OVERFLOW(x)\
        (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* ExtTypeTest.proto */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

/* IsLittleEndian.proto */
static CYTHON_INLINE int __Pyx_Is_Little_Endian(void);

/* BufferFormatCheck.proto */
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts);
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type);

/* BufferGetAndValidate.proto */
#define __Pyx_GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack)\
    ((obj == Py_None || obj == NULL) ?\
    (__Pyx_ZeroBuffer(buf), 0) :\
    __Pyx__GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack))
static int  __Pyx__GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
    __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static void __Pyx_ZeroBuffer(Py_buffer* buf);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
static Py_ssize_t __Pyx_minusones[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
static Py_ssize_t __Pyx_zeros[] = { 0, 0, 0, 0, 0, 0, 0, 0 };

/* BufferIndexError.proto */
static void __Pyx_RaiseBufferIndexError(int axis);

#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1)
/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
#else
#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
#endif

/* None.proto */
static CYTHON_INLINE int __Pyx_mod_int(int, int);

/* None.proto */
static CYTHON_INLINE int __Pyx_div_int(int, int);

/* BufferFallbackError.proto */
static void __Pyx_RaiseBufferFallbackError(void);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* None.proto */
static CYTHON_INLINE long __Pyx_mod_long(long, long);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_EqObjC(op1, op2, intval, inplace)\
    PyObject_RichCompare(op1, op2, Py_EQ)
    #endif

/* RaiseNoneIterError.proto */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* PyObject_GenericGetAttrNoDict.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
#endif

/* PyObject_GenericGetAttr.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
#endif

/* SetVTable.proto */
static int __Pyx_SetVtable(PyObject *dict, void *vtable);

/* SetupReduce.proto */
static int __Pyx_setup_reduce(PyObject* type_obj);

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* None.proto */
#include <new>

/* BufferStructDeclare.proto */
typedef struct {
  Py_ssize_t shape, strides, suboffsets;
} __Pyx_Buf_DimInfo;
typedef struct {
  size_t refcount;
  Py_buffer pybuffer;
} __Pyx_Buffer;
typedef struct {
  __Pyx_Buffer *rcbuffer;
  char *data;
  __Pyx_Buf_DimInfo diminfo[8];
} __Pyx_LocalBuf_ND;

#if PY_MAJOR_VERSION < 3
    static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
    static void __Pyx_ReleaseBuffer(Py_buffer *view);
#else
    #define __Pyx_GetBuffer PyObject_GetBuffer
    #define __Pyx_ReleaseBuffer PyBuffer_Release
#endif


/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* Print.proto */
static int __Pyx_Print(PyObject*, PyObject *, int);
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CppExceptionConversion.proto */
#ifndef __Pyx_CppExn2PyErr
#include <new>
#include <typeinfo>
#include <stdexcept>
#include <ios>
static void __Pyx_CppExn2PyErr() {
  try {
    if (PyErr_Occurred())
      ; // let the latest Python exn pass through and ignore the current one
    else
      throw;
  } catch (const std::bad_alloc& exn) {
    PyErr_SetString(PyExc_MemoryError, exn.what());
  } catch (const std::bad_cast& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::bad_typeid& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::domain_error& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::invalid_argument& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::ios_base::failure& exn) {
    PyErr_SetString(PyExc_IOError, exn.what());
  } catch (const std::out_of_range& exn) {
    PyErr_SetString(PyExc_IndexError, exn.what());
  } catch (const std::overflow_error& exn) {
    PyErr_SetString(PyExc_OverflowError, exn.what());
  } catch (const std::range_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::underflow_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::exception& exn) {
    PyErr_SetString(PyExc_RuntimeError, exn.what());
  }
  catch (...)
  {
    PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
  }
}
#endif

/* RealImag.proto */
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #define __Pyx_CREAL(z) ((z).real())
    #define __Pyx_CIMAG(z) ((z).imag())
  #else
    #define __Pyx_CREAL(z) (__real__(z))
    #define __Pyx_CIMAG(z) (__imag__(z))
  #endif
#else
    #define __Pyx_CREAL(z) ((z).real)
    #define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(__cplusplus) && CYTHON_CCOMPLEX\
        && (defined(_WIN32) || defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 )) || __cplusplus >= 201103)
    #define __Pyx_SET_CREAL(z,x) ((z).real(x))
    #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
    #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
    #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif

/* Arithmetic.proto */
#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq_float(a, b)   ((a)==(b))
    #define __Pyx_c_sum_float(a, b)  ((a)+(b))
    #define __Pyx_c_diff_float(a, b) ((a)-(b))
    #define __Pyx_c_prod_float(a, b) ((a)*(b))
    #define __Pyx_c_quot_float(a, b) ((a)/(b))
    #define __Pyx_c_neg_float(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero_float(z) ((z)==(float)0)
    #define __Pyx_c_conj_float(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs_float(z)     (::std::abs(z))
        #define __Pyx_c_pow_float(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero_float(z) ((z)==0)
    #define __Pyx_c_conj_float(z)    (conjf(z))
    #if 1
        #define __Pyx_c_abs_float(z)     (cabsf(z))
        #define __Pyx_c_pow_float(a, b)  (cpowf(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sum_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_diff_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prod_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_neg_float(__pyx_t_float_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero_float(__pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conj_float(__pyx_t_float_complex);
    #if 1
        static CYTHON_INLINE float __Pyx_c_abs_float(__pyx_t_float_complex);
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_pow_float(__pyx_t_float_complex, __pyx_t_float_complex);
    #endif
#endif

/* Arithmetic.proto */
#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq_double(a, b)   ((a)==(b))
    #define __Pyx_c_sum_double(a, b)  ((a)+(b))
    #define __Pyx_c_diff_double(a, b) ((a)-(b))
    #define __Pyx_c_prod_double(a, b) ((a)*(b))
    #define __Pyx_c_quot_double(a, b) ((a)/(b))
    #define __Pyx_c_neg_double(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero_double(z) ((z)==(double)0)
    #define __Pyx_c_conj_double(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs_double(z)     (::std::abs(z))
        #define __Pyx_c_pow_double(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero_double(z) ((z)==0)
    #define __Pyx_c_conj_double(z)    (conj(z))
    #if 1
        #define __Pyx_c_abs_double(z)     (cabs(z))
        #define __Pyx_c_pow_double(a, b)  (cpow(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex);
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex);
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex, __pyx_t_double_complex);
    #endif
#endif

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__NPY_TYPES(enum NPY_TYPES value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* PrintOne.proto */
static int __Pyx_PrintOne(PyObject* stream, PyObject *o);

/* CIntFromPy.proto */
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* PyIdentifierFromString.proto */
#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

/* ModuleImport.proto */
static PyObject *__Pyx_ImportModule(const char *name);

/* TypeImport.proto */
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi, double __pyx_v_value); /* proto*/
static CYTHON_INLINE double __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi); /* proto*/
static void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster__load_block(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, int __pyx_v_block_index); /* proto*/

/* Module declarations from 'cpython.buffer' */

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.type' */
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;

/* Module declarations from 'cpython' */

/* Module declarations from 'cpython.object' */

/* Module declarations from 'cpython.ref' */

/* Module declarations from 'cpython.mem' */

/* Module declarations from 'numpy' */

/* Module declarations from 'numpy' */
static PyTypeObject *__pyx_ptype_5numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0;
static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0;
static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/

/* Module declarations from 'cython' */

/* Module declarations from 'libc.stddef' */

/* Module declarations from 'libc.time' */

/* Module declarations from 'libcpp.list' */

/* Module declarations from 'libcpp.utility' */

/* Module declarations from 'libcpp.pair' */

/* Module declarations from 'libcpp.queue' */

/* Module declarations from 'libcpp.stack' */

/* Module declarations from 'libcpp.deque' */

/* Module declarations from 'libcpp.set' */

/* Module declarations from 'pygeoprocessing.routing.routing' */
static PyTypeObject *__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster = 0;
static int __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS;
static int __pyx_v_15pygeoprocessing_7routing_7routing_MANAGED_RASTER_N_BLOCKS;
static double __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;
static double __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2;
static double __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV;
static int *__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY;
static int *__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION;
static int __pyx_f_15pygeoprocessing_7routing_7routing_is_close(double, double); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t = { "float64_t", NULL, sizeof(__pyx_t_5numpy_float64_t), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t = { "uint8_t", NULL, sizeof(__pyx_t_5numpy_uint8_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_uint8_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_uint8_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t = { "int32_t", NULL, sizeof(__pyx_t_5numpy_int32_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int32_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int32_t), 0 };
#define __Pyx_MODULE_NAME "pygeoprocessing.routing.routing"
extern int __pyx_module_is_main_pygeoprocessing__routing__routing;
int __pyx_module_is_main_pygeoprocessing__routing__routing = 0;

/* Implementation of 'pygeoprocessing.routing.routing' */
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_OSError;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_builtin_ImportError;
static const char __pyx_k_os[] = "os";
static const char __pyx_k_xa[] = "xa";
static const char __pyx_k_xb[] = "xb";
static const char __pyx_k_xi[] = "xi";
static const char __pyx_k_ya[] = "ya";
static const char __pyx_k_yb[] = "yb";
static const char __pyx_k_yi[] = "yi";
static const char __pyx_k__52[] = "_";
static const char __pyx_k_dir[] = "dir";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_i_n[] = "i_n";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_file[] = "file";
static const char __pyx_k_gdal[] = "gdal";
static const char __pyx_k_i_sn[] = "i_sn";
static const char __pyx_k_info[] = "info";
static const char __pyx_k_int8[] = "int8";
static const char __pyx_k_join[] = "join";
static const char __pyx_k_log2[] = "log2";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_path[] = "path";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_time[] = "time";
static const char __pyx_k_xi_n[] = "xi_n";
static const char __pyx_k_xi_q[] = "xi_q";
static const char __pyx_k_xoff[] = "xoff";
static const char __pyx_k_yi_n[] = "yi_n";
static const char __pyx_k_yi_q[] = "yi_q";
static const char __pyx_k_yoff[] = "yoff";
static const char __pyx_k_GTiff[] = "GTiff";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_empty[] = "empty";
static const char __pyx_k_error[] = "error";
static const char __pyx_k_int32[] = "int32";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_osgeo[] = "osgeo";
static const char __pyx_k_pixel[] = "pixel";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_uint8[] = "uint8";
static const char __pyx_k_value[] = "value";
static const char __pyx_k_xi_bn[] = "xi_bn";
static const char __pyx_k_xi_sn[] = "xi_sn";
static const char __pyx_k_yi_bn[] = "yi_bn";
static const char __pyx_k_yi_sn[] = "yi_sn";
static const char __pyx_k_LOGGER[] = "LOGGER";
static const char __pyx_k_OpenEx[] = "OpenEx";
static const char __pyx_k_astype[] = "astype";
static const char __pyx_k_double[] = "double";
static const char __pyx_k_gmtime[] = "gmtime";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_isfile[] = "isfile";
static const char __pyx_k_nodata[] = "nodata";
static const char __pyx_k_prefix[] = "prefix";
static const char __pyx_k_reduce[] = "__reduce__";
static const char __pyx_k_rmtree[] = "rmtree";
static const char __pyx_k_shutil[] = "shutil";
static const char __pyx_k_OSError[] = "OSError";
static const char __pyx_k_band_id[] = "band_id";
static const char __pyx_k_float64[] = "float64";
static const char __pyx_k_logging[] = "logging";
static const char __pyx_k_mkdtemp[] = "mkdtemp";
static const char __pyx_k_n_bands[] = "n_bands";
static const char __pyx_k_n_slope[] = "n_slope";
static const char __pyx_k_options[] = "options";
static const char __pyx_k_warning[] = "warning";
static const char __pyx_k_xi_root[] = "xi_root";
static const char __pyx_k_yi_root[] = "yi_root";
static const char __pyx_k_GDT_Byte[] = "GDT_Byte";
static const char __pyx_k_dem_band[] = "dem_band";
static const char __pyx_k_flow_dir[] = "flow_dir";
static const char __pyx_k_getstate[] = "__getstate__";
static const char __pyx_k_makedirs[] = "makedirs";
static const char __pyx_k_n_height[] = "n_height";
static const char __pyx_k_open_set[] = "open_set";
static const char __pyx_k_priority[] = "priority";
static const char __pyx_k_setstate[] = "__setstate__";
static const char __pyx_k_strftime[] = "strftime";
static const char __pyx_k_tempfile[] = "tempfile";
static const char __pyx_k_GA_Update[] = "GA_Update";
static const char __pyx_k_GDT_Int32[] = "GDT_Int32";
static const char __pyx_k_OF_RASTER[] = "OF_RASTER";
static const char __pyx_k_TILED_YES[] = "TILED=YES";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_fill_pits[] = "fill_pits";
static const char __pyx_k_getLogger[] = "getLogger";
static const char __pyx_k_is_outlet[] = "is_outlet";
static const char __pyx_k_pit_queue[] = "pit_queue";
static const char __pyx_k_pixel_val[] = "pixel_val";
static const char __pyx_k_preempted[] = "preempted";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
static const char __pyx_k_stream_mr[] = "stream_mr";
static const char __pyx_k_win_xsize[] = "win_xsize";
static const char __pyx_k_win_ysize[] = "win_ysize";
static const char __pyx_k_CreateCopy[] = "CreateCopy";
static const char __pyx_k_FlushCache[] = "FlushCache";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_WriteArray[] = "WriteArray";
static const char __pyx_k_addHandler[] = "addHandler";
static const char __pyx_k_block_size[] = "block_size";
static const char __pyx_k_center_val[] = "center_val";
static const char __pyx_k_dem_nodata[] = "dem_nodata";
static const char __pyx_k_dem_raster[] = "dem_raster";
static const char __pyx_k_feature_id[] = "feature_id";
static const char __pyx_k_fill_queue[] = "fill_queue";
static const char __pyx_k_flow_accum[] = "flow_accum";
static const char __pyx_k_flow_pixel[] = "flow_pixel";
static const char __pyx_k_iterblocks[] = "iterblocks";
static const char __pyx_k_n_distance[] = "n_distance";
static const char __pyx_k_n_x_blocks[] = "n_x_blocks";
static const char __pyx_k_pour_point[] = "pour_point";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_stream_val[] = "stream_val";
static const char __pyx_k_weight_val[] = "weight_val";
static const char __pyx_k_write_mode[] = "write_mode";
static const char __pyx_k_1f_complete[] = "%.1f%% complete";
static const char __pyx_k_BIGTIFF_YES[] = "BIGTIFF=YES";
static const char __pyx_k_GDT_Float64[] = "GDT_Float64";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_NullHandler[] = "NullHandler";
static const char __pyx_k_ReadAsArray[] = "ReadAsArray";
static const char __pyx_k_base_nodata[] = "base_nodata";
static const char __pyx_k_drain_queue[] = "drain_queue";
static const char __pyx_k_fill_height[] = "fill_height";
static const char __pyx_k_flow_dir_d8[] = "flow_dir_d8";
static const char __pyx_k_mask_nodata[] = "mask_nodata";
static const char __pyx_k_offset_dict[] = "offset_dict";
static const char __pyx_k_offset_only[] = "offset_only";
static const char __pyx_k_raster_path[] = "raster_path";
static const char __pyx_k_raster_size[] = "raster_size";
static const char __pyx_k_root_height[] = "root_height";
static const char __pyx_k_stream_band[] = "stream_band";
static const char __pyx_k_working_dir[] = "working_dir";
static const char __pyx_k_BLOCKXSIZE_d[] = "BLOCKXSIZE=%d";
static const char __pyx_k_BLOCKYSIZE_d[] = "BLOCKYSIZE=%d";
static const char __pyx_k_COMPRESS_LZW[] = "COMPRESS=LZW";
static const char __pyx_k_RuntimeError[] = "RuntimeError";
static const char __pyx_k_channel_band[] = "channel_band";
static const char __pyx_k_fill_pits__s[] = "fill_pits_%s_";
static const char __pyx_k_flow_dir_mfd[] = "flow_dir_mfd";
static const char __pyx_k_is_a_channel[] = "is_a_channel";
static const char __pyx_k_n_iterations[] = "n_iterations";
static const char __pyx_k_nodata_drain[] = "nodata_drain";
static const char __pyx_k_pit_mask_tif[] = "pit_mask.tif";
static const char __pyx_k_search_queue[] = "search_queue";
static const char __pyx_k_search_stack[] = "search_stack";
static const char __pyx_k_stream_array[] = "stream_array";
static const char __pyx_k_GetRasterBand[] = "GetRasterBand";
static const char __pyx_k_backtrace_set[] = "backtrace_set";
static const char __pyx_k_block_offsets[] = "block_offsets";
static const char __pyx_k_current_pixel[] = "current_pixel";
static const char __pyx_k_flow_accum_mr[] = "flow_accum_mr";
static const char __pyx_k_flow_dir_band[] = "flow_dir_band";
static const char __pyx_k_largest_block[] = "largest_block";
static const char __pyx_k_largest_slope[] = "largest_slope";
static const char __pyx_k_last_flow_dir[] = "last_flow_dir";
static const char __pyx_k_last_log_time[] = "last_log_time";
static const char __pyx_k_pit_mask_path[] = "pit_mask_path";
static const char __pyx_k_raster_x_size[] = "raster_x_size";
static const char __pyx_k_raster_y_size[] = "raster_y_size";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
static const char __pyx_k_stream_nodata[] = "stream_nodata";
static const char __pyx_k_stream_raster[] = "stream_raster";
static const char __pyx_k_weight_nodata[] = "weight_nodata";
static const char __pyx_k_weight_raster[] = "weight_raster";
static const char __pyx_k_100_0_complete[] = "100.0% complete";
static const char __pyx_k_Y_m_d__H__M__S[] = "%Y-%m-%d_%H_%M_%S";
static const char __pyx_k_channel_raster[] = "channel_raster";
static const char __pyx_k_downhill_drain[] = "downhill_drain";
static const char __pyx_k_drain_distance[] = "drain_distance";
static const char __pyx_k_flow_dir_d8__s[] = "flow_dir_d8_%s_";
static const char __pyx_k_flow_threshold[] = "flow_threshold";
static const char __pyx_k_geotiff_driver[] = "geotiff_driver";
static const char __pyx_k_GetDriverByName[] = "GetDriverByName";
static const char __pyx_k_base_dem_raster[] = "base_dem_raster";
static const char __pyx_k_dem_block_xsize[] = "dem_block_xsize";
static const char __pyx_k_dem_block_ysize[] = "dem_block_ysize";
static const char __pyx_k_dem_raster_info[] = "dem_raster_info";
static const char __pyx_k_diagonal_nodata[] = "diagonal_nodata";
static const char __pyx_k_distance_nodata[] = "distance_nodata";
static const char __pyx_k_fill_value_list[] = "fill_value_list";
static const char __pyx_k_flow_accum_info[] = "flow_accum_info";
static const char __pyx_k_flow_dir_mfd_mr[] = "flow_dir_mfd_mr";
static const char __pyx_k_flow_dir_nodata[] = "flow_dir_nodata";
static const char __pyx_k_flow_dir_raster[] = "flow_dir_raster";
static const char __pyx_k_flow_dir_weight[] = "flow_dir_weight";
static const char __pyx_k_get_raster_info[] = "get_raster_info";
static const char __pyx_k_i_upstream_flow[] = "i_upstream_flow";
static const char __pyx_k_nodata_neighbor[] = "nodata_neighbor";
static const char __pyx_k_pygeoprocessing[] = "pygeoprocessing";
static const char __pyx_k_s_is_not_a_file[] = "%s is not a file.";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
static const char __pyx_k_target_dem_band[] = "target_dem_band";
static const char __pyx_k_dem_buffer_array[] = "dem_buffer_array";
static const char __pyx_k_n_drain_distance[] = "n_drain_distance";
static const char __pyx_k_raster_path_band[] = "raster_path_band";
static const char __pyx_k_working_dir_path[] = "working_dir_path";
static const char __pyx_k_downhill_neighbor[] = "downhill_neighbor";
static const char __pyx_k_flow_accum_nodata[] = "flow_accum_nodata";
static const char __pyx_k_flow_dir_mfd_band[] = "flow_dir_mfd_band";
static const char __pyx_k_largest_slope_dir[] = "largest_slope_dir";
static const char __pyx_k_raw_weight_nodata[] = "raw_weight_nodata";
static const char __pyx_k_target_dem_raster[] = "target_dem_raster";
static const char __pyx_k_upstream_flow_dir[] = "upstream_flow_dir";
static const char __pyx_k_x_out_of_bounds_s[] = "x out of bounds %s";
static const char __pyx_k_y_out_of_bounds_s[] = "y out of bounds %s";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_compatable_dem_tif[] = "compatable_dem.tif";
static const char __pyx_k_dem_managed_raster[] = "dem_managed_raster";
static const char __pyx_k_drain_search_queue[] = "drain_search_queue";
static const char __pyx_k_nodata_drain_queue[] = "nodata_drain_queue";
static const char __pyx_k_target_offset_dict[] = "target_offset_dict";
static const char __pyx_k_compressed_flow_dir[] = "compressed_flow_dir";
static const char __pyx_k_extract_streams_mfd[] = "extract_streams_mfd";
static const char __pyx_k_flow_dir_mfd_raster[] = "flow_dir_mfd_raster";
static const char __pyx_k_sum_of_flow_weights[] = "sum_of_flow_weights";
static const char __pyx_k_tmp_flow_dir_nodata[] = "tmp_flow_dir_nodata";
static const char __pyx_k_upstream_flow_accum[] = "upstream_flow_accum";
static const char __pyx_k_channel_buffer_array[] = "channel_buffer_array";
static const char __pyx_k_dem_raster_path_band[] = "dem_raster_path_band";
static const char __pyx_k_distance_drain_queue[] = "distance_drain_queue";
static const char __pyx_k_downhill_slope_array[] = "downhill_slope_array";
static const char __pyx_k_flat_region_mask_tif[] = "flat_region_mask.tif";
static const char __pyx_k_flow_accumulation_d8[] = "flow_accumulation_d8";
static const char __pyx_k_flow_dir_raster_info[] = "flow_dir_raster_info";
static const char __pyx_k_generate_read_bounds[] = "_generate_read_bounds";
static const char __pyx_k_modified_offset_dict[] = "modified_offset_dict";
static const char __pyx_k_new_raster_from_base[] = "new_raster_from_base";
static const char __pyx_k_plateau_distance_tif[] = "plateau_distance.tif";
static const char __pyx_k_sum_of_slope_weights[] = "sum_of_slope_weights";
static const char __pyx_k_target_flow_dir_path[] = "target_flow_dir_path";
static const char __pyx_k_trace_flow_threshold[] = "trace_flow_threshold";
static const char __pyx_k_upstream_flow_weight[] = "upstream_flow_weight";
static const char __pyx_k_direction_drain_queue[] = "direction_drain_queue";
static const char __pyx_k_flat_region_mask_path[] = "flat_region_mask_path";
static const char __pyx_k_flow_accumulation_mfd[] = "flow_accumulation_mfd";
static const char __pyx_k_flow_dir_buffer_array[] = "flow_dir_buffer_array";
static const char __pyx_k_nodata_flow_dir_queue[] = "nodata_flow_dir_queue";
static const char __pyx_k_plateau_distance_path[] = "plateau_distance_path";
static const char __pyx_k_plateu_drain_mask_tif[] = "plateu_drain_mask.tif";
static const char __pyx_k_upstream_flow_dir_sum[] = "upstream_flow_dir_sum";
static const char __pyx_k_channel_managed_raster[] = "channel_managed_raster";
static const char __pyx_k_distance_to_channel_d8[] = "distance_to_channel_d8";
static const char __pyx_k_flow_dir_mfd_path_band[] = "flow_dir_mfd_path_band";
static const char __pyx_k_gtiff_creation_options[] = "gtiff_creation_options";
static const char __pyx_k_plateu_drain_mask_path[] = "plateu_drain_mask_path";
static const char __pyx_k_sum_of_downhill_slopes[] = "sum_of_downhill_slopes";
static const char __pyx_k_compatible_dem_complete[] = "compatible dem complete";
static const char __pyx_k_distance_to_channel_mfd[] = "distance_to_channel_mfd";
static const char __pyx_k_flow_dir_managed_raster[] = "flow_dir_managed_raster";
static const char __pyx_k_pit_mask_managed_raster[] = "pit_mask_managed_raster";
static const char __pyx_k_plateau_distance_nodata[] = "plateau_distance_nodata";
static const char __pyx_k_weight_raster_path_band[] = "weight_raster_path_band";
static const char __pyx_k_channel_raster_path_band[] = "channel_raster_path_band";
static const char __pyx_k_compressed_integer_slopes[] = "compressed_integer_slopes";
static const char __pyx_k_distance_to_channel_stack[] = "distance_to_channel_stack";
static const char __pyx_k_filled_dem_managed_raster[] = "filled_dem_managed_raster";
static const char __pyx_k_flow_accum_managed_raster[] = "flow_accum_managed_raster";
static const char __pyx_k_flow_dir_mfd_buffer_array[] = "flow_dir_mfd_buffer_array";
static const char __pyx_k_flow_dir_raster_path_band[] = "flow_dir_raster_path_band";
static const char __pyx_k_target_stream_raster_path[] = "target_stream_raster_path";
static const char __pyx_k_flow_dir_d8_managed_raster[] = "flow_dir_d8_managed_raster";
static const char __pyx_k_trace_threshold_proportion[] = "trace_threshold_proportion";
static const char __pyx_k_working_downhill_slope_sum[] = "working_downhill_slope_sum";
static const char __pyx_k_flow_accum_raster_path_band[] = "flow_accum_raster_path_band";
static const char __pyx_k_flow_dir_mfd_managed_raster[] = "flow_dir_mfd_managed_raster";
static const char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
static const char __pyx_k_nodata_distance_drain_queue[] = "nodata_distance_drain_queue";
static const char __pyx_k_nodata_downhill_slope_array[] = "nodata_downhill_slope_array";
static const char __pyx_k_sum_of_nodata_slope_weights[] = "sum_of_nodata_slope_weights";
static const char __pyx_k_compressed_upstream_flow_dir[] = "compressed_upstream_flow_dir";
static const char __pyx_k_flow_dir_d8_raster_path_band[] = "flow_dir_d8_raster_path_band";
static const char __pyx_k_working_downhill_slope_array[] = "working_downhill_slope_array";
static const char __pyx_k_flow_dir_mfd_raster_path_band[] = "flow_dir_mfd_raster_path_band";
static const char __pyx_k_flow_dir_multiple_flow_dir__s[] = "flow_dir_multiple_flow_dir_%s_";
static const char __pyx_k_is_raster_path_band_formatted[] = "_is_raster_path_band_formatted";
static const char __pyx_k_target_filled_dem_raster_path[] = "target_filled_dem_raster_path";
static const char __pyx_k_target_flow_accum_raster_path[] = "target_flow_accum_raster_path";
static const char __pyx_k_DEFAULT_GTIFF_CREATION_OPTIONS[] = "DEFAULT_GTIFF_CREATION_OPTIONS";
static const char __pyx_k_Error_Block_size_is_not_a_power[] = "Error: Block size is not a power of two: block_xsize: %d, %d, %s. This exception is happeningin Cython, so it will cause a hard seg-fault, but it'sotherwise meant to be a ValueError.";
static const char __pyx_k_Provides_PyGeprocessing_Routing[] = "\nProvides PyGeprocessing Routing functionality.\n\nUnless otherwise specified, all internal computation of rasters are done in\na float64 space. The only possible loss of precision could occur when an\nincoming DEM type is an int64 type and values in that dem exceed 2^52 but GDAL\ndoes not support int64 rasters so no precision loss is possible with a\nfloat64.\n\nD8 float direction conventions follow TauDEM where each flow direction\nis encoded as:\n     321\n     4x0\n     567\n";
static const char __pyx_k_compatable_dem_raster_path_band[] = "compatable_dem_raster_path_band";
static const char __pyx_k_filter_out_incomplete_divergent[] = "filter out incomplete divergent streams";
static const char __pyx_k_flat_region_mask_managed_raster[] = "flat_region_mask_managed_raster";
static const char __pyx_k_numpy_core_multiarray_failed_to[] = "numpy.core.multiarray failed to import";
static const char __pyx_k_plateau_distance_managed_raster[] = "plateau_distance_managed_raster";
static const char __pyx_k_pygeoprocessing_routing_routing[] = "pygeoprocessing.routing.routing";
static const char __pyx_k_s_is_supposed_to_be_a_raster_ba[] = "%s is supposed to be a raster band tuple but it's not.";
static const char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)";
static const char __pyx_k_Error_band_ID_s_is_not_a_valid_b[] = "Error: band ID (%s) is not a valid band number. This exception is happening in Cython, so it will cause a hard seg-fault, but it's otherwise meant to be a ValueError.";
static const char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd";
static const char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported";
static const char __pyx_k_dem_is_not_a_power_of_2_creating[] = "dem is not a power of 2, creating a copy that is.";
static const char __pyx_k_distance_to_channel_managed_rast[] = "distance_to_channel_managed_raster";
static const char __pyx_k_ndarray_is_not_Fortran_contiguou[] = "ndarray is not Fortran contiguous";
static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
static const char __pyx_k_numpy_core_umath_failed_to_impor[] = "numpy.core.umath failed to import";
static const char __pyx_k_plateau_drain_mask_managed_raste[] = "plateau_drain_mask_managed_raster";
static const char __pyx_k_src_pygeoprocessing_routing_rout[] = "src\\pygeoprocessing\\routing\\routing.pyx";
static const char __pyx_k_target_distance_to_channel_raste[] = "target_distance_to_channel_raster_path";
static const char __pyx_k_trace_threshold_proportion_shoul[] = "trace_threshold_proportion should be in the range [0.0, 1.0] actual value is: %s";
static const char __pyx_k_Format_string_allocated_too_shor_2[] = "Format string allocated too short.";
static PyObject *__pyx_kp_s_100_0_complete;
static PyObject *__pyx_kp_s_1f_complete;
static PyObject *__pyx_kp_s_BIGTIFF_YES;
static PyObject *__pyx_kp_s_BLOCKXSIZE_d;
static PyObject *__pyx_kp_s_BLOCKYSIZE_d;
static PyObject *__pyx_kp_s_COMPRESS_LZW;
static PyObject *__pyx_n_s_CreateCopy;
static PyObject *__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS;
static PyObject *__pyx_kp_s_Error_Block_size_is_not_a_power;
static PyObject *__pyx_kp_s_Error_band_ID_s_is_not_a_valid_b;
static PyObject *__pyx_n_s_FlushCache;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor_2;
static PyObject *__pyx_n_s_GA_Update;
static PyObject *__pyx_n_s_GDT_Byte;
static PyObject *__pyx_n_s_GDT_Float64;
static PyObject *__pyx_n_s_GDT_Int32;
static PyObject *__pyx_n_s_GTiff;
static PyObject *__pyx_n_s_GetDriverByName;
static PyObject *__pyx_n_s_GetRasterBand;
static PyObject *__pyx_n_s_ImportError;
static PyObject *__pyx_n_s_LOGGER;
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
static PyObject *__pyx_n_s_NullHandler;
static PyObject *__pyx_n_s_OF_RASTER;
static PyObject *__pyx_n_s_OSError;
static PyObject *__pyx_n_s_OpenEx;
static PyObject *__pyx_n_s_ReadAsArray;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_kp_s_TILED_YES;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_WriteArray;
static PyObject *__pyx_kp_s_Y_m_d__H__M__S;
static PyObject *__pyx_n_s__52;
static PyObject *__pyx_n_s_addHandler;
static PyObject *__pyx_n_s_astype;
static PyObject *__pyx_n_s_backtrace_set;
static PyObject *__pyx_n_s_band_id;
static PyObject *__pyx_n_s_base_dem_raster;
static PyObject *__pyx_n_s_base_nodata;
static PyObject *__pyx_n_s_block_offsets;
static PyObject *__pyx_n_s_block_size;
static PyObject *__pyx_n_s_center_val;
static PyObject *__pyx_n_s_channel_band;
static PyObject *__pyx_n_s_channel_buffer_array;
static PyObject *__pyx_n_s_channel_managed_raster;
static PyObject *__pyx_n_s_channel_raster;
static PyObject *__pyx_n_s_channel_raster_path_band;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_compatable_dem_raster_path_band;
static PyObject *__pyx_kp_s_compatable_dem_tif;
static PyObject *__pyx_kp_s_compatible_dem_complete;
static PyObject *__pyx_n_s_compressed_flow_dir;
static PyObject *__pyx_n_s_compressed_integer_slopes;
static PyObject *__pyx_n_s_compressed_upstream_flow_dir;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_n_s_current_pixel;
static PyObject *__pyx_n_s_dem_band;
static PyObject *__pyx_n_s_dem_block_xsize;
static PyObject *__pyx_n_s_dem_block_ysize;
static PyObject *__pyx_n_s_dem_buffer_array;
static PyObject *__pyx_kp_s_dem_is_not_a_power_of_2_creating;
static PyObject *__pyx_n_s_dem_managed_raster;
static PyObject *__pyx_n_s_dem_nodata;
static PyObject *__pyx_n_s_dem_raster;
static PyObject *__pyx_n_s_dem_raster_info;
static PyObject *__pyx_n_s_dem_raster_path_band;
static PyObject *__pyx_n_s_diagonal_nodata;
static PyObject *__pyx_n_s_dir;
static PyObject *__pyx_n_s_direction_drain_queue;
static PyObject *__pyx_n_s_distance_drain_queue;
static PyObject *__pyx_n_s_distance_nodata;
static PyObject *__pyx_n_s_distance_to_channel_d8;
static PyObject *__pyx_n_s_distance_to_channel_managed_rast;
static PyObject *__pyx_n_s_distance_to_channel_mfd;
static PyObject *__pyx_n_s_distance_to_channel_stack;
static PyObject *__pyx_n_s_double;
static PyObject *__pyx_n_s_downhill_drain;
static PyObject *__pyx_n_s_downhill_neighbor;
static PyObject *__pyx_n_s_downhill_slope_array;
static PyObject *__pyx_n_s_drain_distance;
static PyObject *__pyx_n_s_drain_queue;
static PyObject *__pyx_n_s_drain_search_queue;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_error;
static PyObject *__pyx_n_s_extract_streams_mfd;
static PyObject *__pyx_n_s_feature_id;
static PyObject *__pyx_n_s_file;
static PyObject *__pyx_n_s_fill_height;
static PyObject *__pyx_n_s_fill_pits;
static PyObject *__pyx_kp_s_fill_pits__s;
static PyObject *__pyx_n_s_fill_queue;
static PyObject *__pyx_n_s_fill_value_list;
static PyObject *__pyx_n_s_filled_dem_managed_raster;
static PyObject *__pyx_kp_s_filter_out_incomplete_divergent;
static PyObject *__pyx_n_s_flat_region_mask_managed_raster;
static PyObject *__pyx_n_s_flat_region_mask_path;
static PyObject *__pyx_kp_s_flat_region_mask_tif;
static PyObject *__pyx_n_s_float64;
static PyObject *__pyx_n_s_flow_accum;
static PyObject *__pyx_n_s_flow_accum_info;
static PyObject *__pyx_n_s_flow_accum_managed_raster;
static PyObject *__pyx_n_s_flow_accum_mr;
static PyObject *__pyx_n_s_flow_accum_nodata;
static PyObject *__pyx_n_s_flow_accum_raster_path_band;
static PyObject *__pyx_n_s_flow_accumulation_d8;
static PyObject *__pyx_n_s_flow_accumulation_mfd;
static PyObject *__pyx_n_s_flow_dir;
static PyObject *__pyx_n_s_flow_dir_band;
static PyObject *__pyx_n_s_flow_dir_buffer_array;
static PyObject *__pyx_n_s_flow_dir_d8;
static PyObject *__pyx_kp_s_flow_dir_d8__s;
static PyObject *__pyx_n_s_flow_dir_d8_managed_raster;
static PyObject *__pyx_n_s_flow_dir_d8_raster_path_band;
static PyObject *__pyx_n_s_flow_dir_managed_raster;
static PyObject *__pyx_n_s_flow_dir_mfd;
static PyObject *__pyx_n_s_flow_dir_mfd_band;
static PyObject *__pyx_n_s_flow_dir_mfd_buffer_array;
static PyObject *__pyx_n_s_flow_dir_mfd_managed_raster;
static PyObject *__pyx_n_s_flow_dir_mfd_mr;
static PyObject *__pyx_n_s_flow_dir_mfd_path_band;
static PyObject *__pyx_n_s_flow_dir_mfd_raster;
static PyObject *__pyx_n_s_flow_dir_mfd_raster_path_band;
static PyObject *__pyx_kp_s_flow_dir_multiple_flow_dir__s;
static PyObject *__pyx_n_s_flow_dir_nodata;
static PyObject *__pyx_n_s_flow_dir_raster;
static PyObject *__pyx_n_s_flow_dir_raster_info;
static PyObject *__pyx_n_s_flow_dir_raster_path_band;
static PyObject *__pyx_n_s_flow_dir_weight;
static PyObject *__pyx_n_s_flow_pixel;
static PyObject *__pyx_n_s_flow_threshold;
static PyObject *__pyx_n_s_gdal;
static PyObject *__pyx_n_s_generate_read_bounds;
static PyObject *__pyx_n_s_geotiff_driver;
static PyObject *__pyx_n_s_getLogger;
static PyObject *__pyx_n_s_get_raster_info;
static PyObject *__pyx_n_s_getstate;
static PyObject *__pyx_n_s_gmtime;
static PyObject *__pyx_n_s_gtiff_creation_options;
static PyObject *__pyx_n_s_i_n;
static PyObject *__pyx_n_s_i_sn;
static PyObject *__pyx_n_s_i_upstream_flow;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_info;
static PyObject *__pyx_n_s_int32;
static PyObject *__pyx_n_s_int8;
static PyObject *__pyx_n_s_is_a_channel;
static PyObject *__pyx_n_s_is_outlet;
static PyObject *__pyx_n_s_is_raster_path_band_formatted;
static PyObject *__pyx_n_s_isfile;
static PyObject *__pyx_n_s_iterblocks;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_largest_block;
static PyObject *__pyx_n_s_largest_slope;
static PyObject *__pyx_n_s_largest_slope_dir;
static PyObject *__pyx_n_s_last_flow_dir;
static PyObject *__pyx_n_s_last_log_time;
static PyObject *__pyx_n_s_log2;
static PyObject *__pyx_n_s_logging;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_makedirs;
static PyObject *__pyx_n_s_mask_nodata;
static PyObject *__pyx_n_s_mkdtemp;
static PyObject *__pyx_n_s_modified_offset_dict;
static PyObject *__pyx_n_s_n_bands;
static PyObject *__pyx_n_s_n_distance;
static PyObject *__pyx_n_s_n_drain_distance;
static PyObject *__pyx_n_s_n_height;
static PyObject *__pyx_n_s_n_iterations;
static PyObject *__pyx_n_s_n_slope;
static PyObject *__pyx_n_s_n_x_blocks;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous;
static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou;
static PyObject *__pyx_n_s_new_raster_from_base;
static PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
static PyObject *__pyx_n_s_nodata;
static PyObject *__pyx_n_s_nodata_distance_drain_queue;
static PyObject *__pyx_n_s_nodata_downhill_slope_array;
static PyObject *__pyx_n_s_nodata_drain;
static PyObject *__pyx_n_s_nodata_drain_queue;
static PyObject *__pyx_n_s_nodata_flow_dir_queue;
static PyObject *__pyx_n_s_nodata_neighbor;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_kp_s_numpy_core_multiarray_failed_to;
static PyObject *__pyx_kp_s_numpy_core_umath_failed_to_impor;
static PyObject *__pyx_n_s_offset_dict;
static PyObject *__pyx_n_s_offset_only;
static PyObject *__pyx_n_s_open_set;
static PyObject *__pyx_n_s_options;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_osgeo;
static PyObject *__pyx_n_s_path;
static PyObject *__pyx_n_s_pit_mask_managed_raster;
static PyObject *__pyx_n_s_pit_mask_path;
static PyObject *__pyx_kp_s_pit_mask_tif;
static PyObject *__pyx_n_s_pit_queue;
static PyObject *__pyx_n_s_pixel;
static PyObject *__pyx_n_s_pixel_val;
static PyObject *__pyx_n_s_plateau_distance_managed_raster;
static PyObject *__pyx_n_s_plateau_distance_nodata;
static PyObject *__pyx_n_s_plateau_distance_path;
static PyObject *__pyx_kp_s_plateau_distance_tif;
static PyObject *__pyx_n_s_plateau_drain_mask_managed_raste;
static PyObject *__pyx_n_s_plateu_drain_mask_path;
static PyObject *__pyx_kp_s_plateu_drain_mask_tif;
static PyObject *__pyx_n_s_pour_point;
static PyObject *__pyx_n_s_preempted;
static PyObject *__pyx_n_s_prefix;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_priority;
static PyObject *__pyx_n_s_pygeoprocessing;
static PyObject *__pyx_n_s_pygeoprocessing_routing_routing;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_raster_path;
static PyObject *__pyx_n_s_raster_path_band;
static PyObject *__pyx_n_s_raster_size;
static PyObject *__pyx_n_s_raster_x_size;
static PyObject *__pyx_n_s_raster_y_size;
static PyObject *__pyx_n_s_raw_weight_nodata;
static PyObject *__pyx_n_s_reduce;
static PyObject *__pyx_n_s_reduce_cython;
static PyObject *__pyx_n_s_reduce_ex;
static PyObject *__pyx_n_s_rmtree;
static PyObject *__pyx_n_s_root_height;
static PyObject *__pyx_kp_s_s_is_not_a_file;
static PyObject *__pyx_kp_s_s_is_supposed_to_be_a_raster_ba;
static PyObject *__pyx_n_s_search_queue;
static PyObject *__pyx_n_s_search_stack;
static PyObject *__pyx_n_s_setstate;
static PyObject *__pyx_n_s_setstate_cython;
static PyObject *__pyx_n_s_shutil;
static PyObject *__pyx_kp_s_src_pygeoprocessing_routing_rout;
static PyObject *__pyx_n_s_stream_array;
static PyObject *__pyx_n_s_stream_band;
static PyObject *__pyx_n_s_stream_mr;
static PyObject *__pyx_n_s_stream_nodata;
static PyObject *__pyx_n_s_stream_raster;
static PyObject *__pyx_n_s_stream_val;
static PyObject *__pyx_n_s_strftime;
static PyObject *__pyx_n_s_sum_of_downhill_slopes;
static PyObject *__pyx_n_s_sum_of_flow_weights;
static PyObject *__pyx_n_s_sum_of_nodata_slope_weights;
static PyObject *__pyx_n_s_sum_of_slope_weights;
static PyObject *__pyx_n_s_target_dem_band;
static PyObject *__pyx_n_s_target_dem_raster;
static PyObject *__pyx_n_s_target_distance_to_channel_raste;
static PyObject *__pyx_n_s_target_filled_dem_raster_path;
static PyObject *__pyx_n_s_target_flow_accum_raster_path;
static PyObject *__pyx_n_s_target_flow_dir_path;
static PyObject *__pyx_n_s_target_offset_dict;
static PyObject *__pyx_n_s_target_stream_raster_path;
static PyObject *__pyx_n_s_tempfile;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_time;
static PyObject *__pyx_n_s_tmp_flow_dir_nodata;
static PyObject *__pyx_n_s_trace_flow_threshold;
static PyObject *__pyx_n_s_trace_threshold_proportion;
static PyObject *__pyx_kp_s_trace_threshold_proportion_shoul;
static PyObject *__pyx_n_s_uint8;
static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd;
static PyObject *__pyx_n_s_upstream_flow_accum;
static PyObject *__pyx_n_s_upstream_flow_dir;
static PyObject *__pyx_n_s_upstream_flow_dir_sum;
static PyObject *__pyx_n_s_upstream_flow_weight;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_n_s_warning;
static PyObject *__pyx_n_s_weight_nodata;
static PyObject *__pyx_n_s_weight_raster;
static PyObject *__pyx_n_s_weight_raster_path_band;
static PyObject *__pyx_n_s_weight_val;
static PyObject *__pyx_n_s_win_xsize;
static PyObject *__pyx_n_s_win_ysize;
static PyObject *__pyx_n_s_working_dir;
static PyObject *__pyx_n_s_working_dir_path;
static PyObject *__pyx_n_s_working_downhill_slope_array;
static PyObject *__pyx_n_s_working_downhill_slope_sum;
static PyObject *__pyx_n_s_write_mode;
static PyObject *__pyx_kp_s_x_out_of_bounds_s;
static PyObject *__pyx_n_s_xa;
static PyObject *__pyx_n_s_xb;
static PyObject *__pyx_n_s_xi;
static PyObject *__pyx_n_s_xi_bn;
static PyObject *__pyx_n_s_xi_n;
static PyObject *__pyx_n_s_xi_q;
static PyObject *__pyx_n_s_xi_root;
static PyObject *__pyx_n_s_xi_sn;
static PyObject *__pyx_n_s_xoff;
static PyObject *__pyx_kp_s_y_out_of_bounds_s;
static PyObject *__pyx_n_s_ya;
static PyObject *__pyx_n_s_yb;
static PyObject *__pyx_n_s_yi;
static PyObject *__pyx_n_s_yi_bn;
static PyObject *__pyx_n_s_yi_n;
static PyObject *__pyx_n_s_yi_q;
static PyObject *__pyx_n_s_yi_root;
static PyObject *__pyx_n_s_yi_sn;
static PyObject *__pyx_n_s_yoff;
static int __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster___cinit__(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, PyObject *__pyx_v_raster_path, PyObject *__pyx_v_band_id, PyObject *__pyx_v_write_mode); /* proto */
static void __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_2__dealloc__(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_4close(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing__generate_read_bounds(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_offset_dict, PyObject *__pyx_v_raster_x_size, PyObject *__pyx_v_raster_y_size); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_2fill_pits(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_filled_dem_raster_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_4flow_dir_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_flow_dir_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_6flow_accumulation_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_raster_path_band, PyObject *__pyx_v_target_flow_accum_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_8flow_dir_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_flow_dir_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_10flow_accumulation_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_mfd_raster_path_band, PyObject *__pyx_v_target_flow_accum_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_12distance_to_channel_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_channel_raster_path_band, PyObject *__pyx_v_target_distance_to_channel_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14distance_to_channel_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_mfd_raster_path_band, PyObject *__pyx_v_channel_raster_path_band, PyObject *__pyx_v_target_distance_to_channel_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_16extract_streams_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_accum_raster_path_band, PyObject *__pyx_v_flow_dir_mfd_path_band, double __pyx_v_flow_threshold, PyObject *__pyx_v_target_stream_raster_path, double __pyx_v_trace_threshold_proportion, PyObject *__pyx_v_gtiff_creation_options); /* proto */
static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_18_is_raster_path_band_formatted(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band); /* proto */
static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_7routing__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_float_100_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_k__3;
static PyObject *__pyx_k__7;
static PyObject *__pyx_k__13;
static PyObject *__pyx_k__16;
static PyObject *__pyx_k__22;
static PyObject *__pyx_k__25;
static PyObject *__pyx_k__27;
static PyObject *__pyx_k__31;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_slice__5;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_slice__11;
static PyObject *__pyx_slice__14;
static PyObject *__pyx_slice__20;
static PyObject *__pyx_slice__23;
static PyObject *__pyx_slice__26;
static PyObject *__pyx_slice__28;
static PyObject *__pyx_slice__29;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_codeobj__45;
static PyObject *__pyx_codeobj__47;
static PyObject *__pyx_codeobj__49;
static PyObject *__pyx_codeobj__51;
static PyObject *__pyx_codeobj__54;
static PyObject *__pyx_codeobj__56;
static PyObject *__pyx_codeobj__58;
static PyObject *__pyx_codeobj__60;
static PyObject *__pyx_codeobj__62;
static PyObject *__pyx_codeobj__64;
/* Late includes */

/* "pygeoprocessing/routing/routing.pyx":144
 * # functor for priority queue of pixels
 * cdef cppclass GreaterPixel nogil:
 *     bint get "operator()"(PixelType& lhs, PixelType& rhs):             # <<<<<<<<<<<<<<
 *         # lhs is > than rhs if its value is greater or if it's equal if
 *         # the priority is >.
 */

int __pyx_t_15pygeoprocessing_7routing_7routing_GreaterPixel::operator()(struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType &__pyx_v_lhs, struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType &__pyx_v_rhs) {
  int __pyx_r;
  int __pyx_t_1;

  /* "pygeoprocessing/routing/routing.pyx":147
 *         # lhs is > than rhs if its value is greater or if it's equal if
 *         # the priority is >.
 *         if lhs.value > rhs.value:             # <<<<<<<<<<<<<<
 *             return 1
 *         if lhs.value == rhs.value:
 */
  __pyx_t_1 = ((__pyx_v_lhs.value > __pyx_v_rhs.value) != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":148
 *         # the priority is >.
 *         if lhs.value > rhs.value:
 *             return 1             # <<<<<<<<<<<<<<
 *         if lhs.value == rhs.value:
 *             if lhs.priority > rhs.priority:
 */
    __pyx_r = 1;
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":147
 *         # lhs is > than rhs if its value is greater or if it's equal if
 *         # the priority is >.
 *         if lhs.value > rhs.value:             # <<<<<<<<<<<<<<
 *             return 1
 *         if lhs.value == rhs.value:
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":149
 *         if lhs.value > rhs.value:
 *             return 1
 *         if lhs.value == rhs.value:             # <<<<<<<<<<<<<<
 *             if lhs.priority > rhs.priority:
 *                 return 1
 */
  __pyx_t_1 = ((__pyx_v_lhs.value == __pyx_v_rhs.value) != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":150
 *             return 1
 *         if lhs.value == rhs.value:
 *             if lhs.priority > rhs.priority:             # <<<<<<<<<<<<<<
 *                 return 1
 *         return 0
 */
    __pyx_t_1 = ((__pyx_v_lhs.priority > __pyx_v_rhs.priority) != 0);
    if (__pyx_t_1) {

      /* "pygeoprocessing/routing/routing.pyx":151
 *         if lhs.value == rhs.value:
 *             if lhs.priority > rhs.priority:
 *                 return 1             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
      __pyx_r = 1;
      goto __pyx_L0;

      /* "pygeoprocessing/routing/routing.pyx":150
 *             return 1
 *         if lhs.value == rhs.value:
 *             if lhs.priority > rhs.priority:             # <<<<<<<<<<<<<<
 *                 return 1
 *         return 0
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":149
 *         if lhs.value > rhs.value:
 *             return 1
 *         if lhs.value == rhs.value:             # <<<<<<<<<<<<<<
 *             if lhs.priority > rhs.priority:
 *                 return 1
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":152
 *             if lhs.priority > rhs.priority:
 *                 return 1
 *         return 0             # <<<<<<<<<<<<<<
 * 
 * cdef int is_close(double x, double y):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "pygeoprocessing/routing/routing.pyx":144
 * # functor for priority queue of pixels
 * cdef cppclass GreaterPixel nogil:
 *     bint get "operator()"(PixelType& lhs, PixelType& rhs):             # <<<<<<<<<<<<<<
 *         # lhs is > than rhs if its value is greater or if it's equal if
 *         # the priority is >.
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":154
 *         return 0
 * 
 * cdef int is_close(double x, double y):             # <<<<<<<<<<<<<<
 *     return abs(x-y) <= (1e-8+1e-05*abs(y))
 * 
 */

static int __pyx_f_15pygeoprocessing_7routing_7routing_is_close(double __pyx_v_x, double __pyx_v_y) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_close", 0);

  /* "pygeoprocessing/routing/routing.pyx":155
 * 
 * cdef int is_close(double x, double y):
 *     return abs(x-y) <= (1e-8+1e-05*abs(y))             # <<<<<<<<<<<<<<
 * 
 * # a class to allow fast random per-pixel access to a raster for both setting
 */
  __pyx_r = (fabs((__pyx_v_x - __pyx_v_y)) <= (1e-8 + (1e-05 * fabs(__pyx_v_y))));
  goto __pyx_L0;

  /* "pygeoprocessing/routing/routing.pyx":154
 *         return 0
 * 
 * cdef int is_close(double x, double y):             # <<<<<<<<<<<<<<
 *     return abs(x-y) <= (1e-8+1e-05*abs(y))
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":177
 *     cdef int closed
 * 
 *     def __cinit__(self, raster_path, band_id, write_mode):             # <<<<<<<<<<<<<<
 *         """Create new instance of Managed Raster.
 * 
 */

/* Python wrapper */
static int __pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_raster_path = 0;
  PyObject *__pyx_v_band_id = 0;
  PyObject *__pyx_v_write_mode = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_raster_path,&__pyx_n_s_band_id,&__pyx_n_s_write_mode,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raster_path)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_band_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, 1); __PYX_ERR(0, 177, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_write_mode)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, 2); __PYX_ERR(0, 177, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 177, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_raster_path = values[0];
    __pyx_v_band_id = values[1];
    __pyx_v_write_mode = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 177, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster___cinit__(((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_v_self), __pyx_v_raster_path, __pyx_v_band_id, __pyx_v_write_mode);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster___cinit__(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, PyObject *__pyx_v_raster_path, PyObject *__pyx_v_band_id, PyObject *__pyx_v_write_mode) {
  PyObject *__pyx_v_raster_info = NULL;
  PyObject *__pyx_v_err_msg = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  long __pyx_t_11;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "pygeoprocessing/routing/routing.pyx":192
 *             None.
 *         """
 *         if not os.path.isfile(raster_path):             # <<<<<<<<<<<<<<
 *             LOGGER.error("%s is not a file.", raster_path)
 *             return
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_isfile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_raster_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_raster_path};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 192, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_raster_path};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 192, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 192, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_raster_path);
      __Pyx_GIVEREF(__pyx_v_raster_path);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_raster_path);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 192, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 192, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pygeoprocessing/routing/routing.pyx":193
 *         """
 *         if not os.path.isfile(raster_path):
 *             LOGGER.error("%s is not a file.", raster_path)             # <<<<<<<<<<<<<<
 *             return
 *         raster_info = pygeoprocessing.get_raster_info(raster_path)
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 193, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_error); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 193, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_7 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_s_s_is_not_a_file, __pyx_v_raster_path};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_s_s_is_not_a_file, __pyx_v_raster_path};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 193, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_kp_s_s_is_not_a_file);
      __Pyx_GIVEREF(__pyx_kp_s_s_is_not_a_file);
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_7, __pyx_kp_s_s_is_not_a_file);
      __Pyx_INCREF(__pyx_v_raster_path);
      __Pyx_GIVEREF(__pyx_v_raster_path);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_7, __pyx_v_raster_path);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":194
 *         if not os.path.isfile(raster_path):
 *             LOGGER.error("%s is not a file.", raster_path)
 *             return             # <<<<<<<<<<<<<<
 *         raster_info = pygeoprocessing.get_raster_info(raster_path)
 *         self.raster_x_size, self.raster_y_size = raster_info['raster_size']
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":192
 *             None.
 *         """
 *         if not os.path.isfile(raster_path):             # <<<<<<<<<<<<<<
 *             LOGGER.error("%s is not a file.", raster_path)
 *             return
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":195
 *             LOGGER.error("%s is not a file.", raster_path)
 *             return
 *         raster_info = pygeoprocessing.get_raster_info(raster_path)             # <<<<<<<<<<<<<<
 *         self.raster_x_size, self.raster_y_size = raster_info['raster_size']
 *         self.block_xsize, self.block_ysize = raster_info['block_size']
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_raster_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_raster_path};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_raster_path};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_INCREF(__pyx_v_raster_path);
      __Pyx_GIVEREF(__pyx_v_raster_path);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_raster_path);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_raster_info = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":196
 *             return
 *         raster_info = pygeoprocessing.get_raster_info(raster_path)
 *         self.raster_x_size, self.raster_y_size = raster_info['raster_size']             # <<<<<<<<<<<<<<
 *         self.block_xsize, self.block_ysize = raster_info['block_size']
 *         self.block_xmod = self.block_xsize-1
 */
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 196, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_2);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_2 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_4), 2) < 0) __PYX_ERR(0, 196, __pyx_L1_error)
    __pyx_t_8 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_8 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 196, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 196, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_self->raster_x_size = __pyx_t_7;
  __pyx_v_self->raster_y_size = __pyx_t_9;

  /* "pygeoprocessing/routing/routing.pyx":197
 *         raster_info = pygeoprocessing.get_raster_info(raster_path)
 *         self.raster_x_size, self.raster_y_size = raster_info['raster_size']
 *         self.block_xsize, self.block_ysize = raster_info['block_size']             # <<<<<<<<<<<<<<
 *         self.block_xmod = self.block_xsize-1
 *         self.block_ymod = self.block_ysize-1
 */
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_s_block_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 197, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 197, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 197, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_4), 2) < 0) __PYX_ERR(0, 197, __pyx_L1_error)
    __pyx_t_8 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L7_unpacking_done;
    __pyx_L6_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_8 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 197, __pyx_L1_error)
    __pyx_L7_unpacking_done:;
  }
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 197, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 197, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_self->block_xsize = __pyx_t_9;
  __pyx_v_self->block_ysize = __pyx_t_7;

  /* "pygeoprocessing/routing/routing.pyx":198
 *         self.raster_x_size, self.raster_y_size = raster_info['raster_size']
 *         self.block_xsize, self.block_ysize = raster_info['block_size']
 *         self.block_xmod = self.block_xsize-1             # <<<<<<<<<<<<<<
 *         self.block_ymod = self.block_ysize-1
 * 
 */
  __pyx_v_self->block_xmod = (__pyx_v_self->block_xsize - 1);

  /* "pygeoprocessing/routing/routing.pyx":199
 *         self.block_xsize, self.block_ysize = raster_info['block_size']
 *         self.block_xmod = self.block_xsize-1
 *         self.block_ymod = self.block_ysize-1             # <<<<<<<<<<<<<<
 * 
 *         if not (1 <= band_id <= raster_info['n_bands']):
 */
  __pyx_v_self->block_ymod = (__pyx_v_self->block_ysize - 1);

  /* "pygeoprocessing/routing/routing.pyx":201
 *         self.block_ymod = self.block_ysize-1
 * 
 *         if not (1 <= band_id <= raster_info['n_bands']):             # <<<<<<<<<<<<<<
 *             err_msg = (
 *                 "Error: band ID (%s) is not a valid band number. "
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_int_1, __pyx_v_band_id, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error)
  if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_raster_info, __pyx_n_s_n_bands); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 201, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_band_id, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 201, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_6) != 0);
  if (__pyx_t_5) {

    /* "pygeoprocessing/routing/routing.pyx":206
 *                 "This exception is happening in Cython, so it will cause a "
 *                 "hard seg-fault, but it's otherwise meant to be a "
 *                 "ValueError." % (band_id))             # <<<<<<<<<<<<<<
 *             print(err_msg)
 *             raise ValueError(err_msg)
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Error_band_ID_s_is_not_a_valid_b, __pyx_v_band_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_err_msg = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":207
 *                 "hard seg-fault, but it's otherwise meant to be a "
 *                 "ValueError." % (band_id))
 *             print(err_msg)             # <<<<<<<<<<<<<<
 *             raise ValueError(err_msg)
 *         self.band_id = band_id
 */
    if (__Pyx_PrintOne(0, __pyx_v_err_msg) < 0) __PYX_ERR(0, 207, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":208
 *                 "ValueError." % (band_id))
 *             print(err_msg)
 *             raise ValueError(err_msg)             # <<<<<<<<<<<<<<
 *         self.band_id = band_id
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 208, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":201
 *         self.block_ymod = self.block_ysize-1
 * 
 *         if not (1 <= band_id <= raster_info['n_bands']):             # <<<<<<<<<<<<<<
 *             err_msg = (
 *                 "Error: band ID (%s) is not a valid band number. "
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":209
 *             print(err_msg)
 *             raise ValueError(err_msg)
 *         self.band_id = band_id             # <<<<<<<<<<<<<<
 * 
 *         if (self.block_xsize & (self.block_xsize - 1) != 0) or (
 */
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_band_id); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 209, __pyx_L1_error)
  __pyx_v_self->band_id = __pyx_t_7;

  /* "pygeoprocessing/routing/routing.pyx":211
 *         self.band_id = band_id
 * 
 *         if (self.block_xsize & (self.block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *                 self.block_ysize & (self.block_ysize - 1) != 0):
 *             # If inputs are not a power of two, this will at least print
 */
  __pyx_t_6 = (((__pyx_v_self->block_xsize & (__pyx_v_self->block_xsize - 1)) != 0) != 0);
  if (!__pyx_t_6) {
  } else {
    __pyx_t_5 = __pyx_t_6;
    goto __pyx_L10_bool_binop_done;
  }

  /* "pygeoprocessing/routing/routing.pyx":212
 * 
 *         if (self.block_xsize & (self.block_xsize - 1) != 0) or (
 *                 self.block_ysize & (self.block_ysize - 1) != 0):             # <<<<<<<<<<<<<<
 *             # If inputs are not a power of two, this will at least print
 *             # an error message. Unfortunately with Cython, the exception will
 */
  __pyx_t_6 = (((__pyx_v_self->block_ysize & (__pyx_v_self->block_ysize - 1)) != 0) != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L10_bool_binop_done:;

  /* "pygeoprocessing/routing/routing.pyx":211
 *         self.band_id = band_id
 * 
 *         if (self.block_xsize & (self.block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *                 self.block_ysize & (self.block_ysize - 1) != 0):
 *             # If inputs are not a power of two, this will at least print
 */
  if (__pyx_t_5) {

    /* "pygeoprocessing/routing/routing.pyx":222
 *                 "in Cython, so it will cause a hard seg-fault, but it's"
 *                 "otherwise meant to be a ValueError." % (
 *                     self.block_xsize, self.block_ysize, raster_path))             # <<<<<<<<<<<<<<
 *             print(err_msg)
 *             raise ValueError(err_msg)
 */
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
    __Pyx_INCREF(__pyx_v_raster_path);
    __Pyx_GIVEREF(__pyx_v_raster_path);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_raster_path);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":221
 *                 "block_xsize: %d, %d, %s. This exception is happening"
 *                 "in Cython, so it will cause a hard seg-fault, but it's"
 *                 "otherwise meant to be a ValueError." % (             # <<<<<<<<<<<<<<
 *                     self.block_xsize, self.block_ysize, raster_path))
 *             print(err_msg)
 */
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_Error_Block_size_is_not_a_power, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_err_msg = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":223
 *                 "otherwise meant to be a ValueError." % (
 *                     self.block_xsize, self.block_ysize, raster_path))
 *             print(err_msg)             # <<<<<<<<<<<<<<
 *             raise ValueError(err_msg)
 * 
 */
    if (__Pyx_PrintOne(0, __pyx_v_err_msg) < 0) __PYX_ERR(0, 223, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":224
 *                     self.block_xsize, self.block_ysize, raster_path))
 *             print(err_msg)
 *             raise ValueError(err_msg)             # <<<<<<<<<<<<<<
 * 
 *         self.block_xbits = numpy.log2(self.block_xsize)
 */
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_v_err_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 224, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":211
 *         self.band_id = band_id
 * 
 *         if (self.block_xsize & (self.block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *                 self.block_ysize & (self.block_ysize - 1) != 0):
 *             # If inputs are not a power of two, this will at least print
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":226
 *             raise ValueError(err_msg)
 * 
 *         self.block_xbits = numpy.log2(self.block_xsize)             # <<<<<<<<<<<<<<
 *         self.block_ybits = numpy.log2(self.block_ysize)
 *         self.block_nx = (
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_log2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 226, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 226, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_self->block_xbits = __pyx_t_7;

  /* "pygeoprocessing/routing/routing.pyx":227
 * 
 *         self.block_xbits = numpy.log2(self.block_xsize)
 *         self.block_ybits = numpy.log2(self.block_ysize)             # <<<<<<<<<<<<<<
 *         self.block_nx = (
 *             self.raster_x_size + (self.block_xsize) - 1) / self.block_xsize
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_log2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_10);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_10, function);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_10)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_1};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_1};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 227, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_self->block_ybits = __pyx_t_7;

  /* "pygeoprocessing/routing/routing.pyx":229
 *         self.block_ybits = numpy.log2(self.block_ysize)
 *         self.block_nx = (
 *             self.raster_x_size + (self.block_xsize) - 1) / self.block_xsize             # <<<<<<<<<<<<<<
 *         self.block_ny = (
 *             self.raster_y_size + (self.block_ysize) - 1) / self.block_ysize
 */
  __pyx_t_11 = ((__pyx_v_self->raster_x_size + __pyx_v_self->block_xsize) - 1);
  if (unlikely(__pyx_v_self->block_xsize == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 229, __pyx_L1_error)
  }
  else if (sizeof(long) == sizeof(long) && (!(((int)-1) > 0)) && unlikely(__pyx_v_self->block_xsize == (int)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_11))) {
    PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
    __PYX_ERR(0, 229, __pyx_L1_error)
  }

  /* "pygeoprocessing/routing/routing.pyx":228
 *         self.block_xbits = numpy.log2(self.block_xsize)
 *         self.block_ybits = numpy.log2(self.block_ysize)
 *         self.block_nx = (             # <<<<<<<<<<<<<<
 *             self.raster_x_size + (self.block_xsize) - 1) / self.block_xsize
 *         self.block_ny = (
 */
  __pyx_v_self->block_nx = __Pyx_div_long(__pyx_t_11, __pyx_v_self->block_xsize);

  /* "pygeoprocessing/routing/routing.pyx":231
 *             self.raster_x_size + (self.block_xsize) - 1) / self.block_xsize
 *         self.block_ny = (
 *             self.raster_y_size + (self.block_ysize) - 1) / self.block_ysize             # <<<<<<<<<<<<<<
 * 
 *         self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS)
 */
  __pyx_t_11 = ((__pyx_v_self->raster_y_size + __pyx_v_self->block_ysize) - 1);
  if (unlikely(__pyx_v_self->block_ysize == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 231, __pyx_L1_error)
  }
  else if (sizeof(long) == sizeof(long) && (!(((int)-1) > 0)) && unlikely(__pyx_v_self->block_ysize == (int)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_11))) {
    PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
    __PYX_ERR(0, 231, __pyx_L1_error)
  }

  /* "pygeoprocessing/routing/routing.pyx":230
 *         self.block_nx = (
 *             self.raster_x_size + (self.block_xsize) - 1) / self.block_xsize
 *         self.block_ny = (             # <<<<<<<<<<<<<<
 *             self.raster_y_size + (self.block_ysize) - 1) / self.block_ysize
 * 
 */
  __pyx_v_self->block_ny = __Pyx_div_long(__pyx_t_11, __pyx_v_self->block_ysize);

  /* "pygeoprocessing/routing/routing.pyx":233
 *             self.raster_y_size + (self.block_ysize) - 1) / self.block_ysize
 * 
 *         self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS)             # <<<<<<<<<<<<<<
 *         self.raster_path = <bytes> raster_path
 *         self.write_mode = write_mode
 */
  __pyx_v_self->lru_cache = new LRUCache<int,double *> (__pyx_v_15pygeoprocessing_7routing_7routing_MANAGED_RASTER_N_BLOCKS);

  /* "pygeoprocessing/routing/routing.pyx":234
 * 
 *         self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS)
 *         self.raster_path = <bytes> raster_path             # <<<<<<<<<<<<<<
 *         self.write_mode = write_mode
 *         self.closed = 0
 */
  __pyx_t_3 = __pyx_v_raster_path;
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->raster_path);
  __Pyx_DECREF(__pyx_v_self->raster_path);
  __pyx_v_self->raster_path = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":235
 *         self.lru_cache = new LRUCache[int, double*](MANAGED_RASTER_N_BLOCKS)
 *         self.raster_path = <bytes> raster_path
 *         self.write_mode = write_mode             # <<<<<<<<<<<<<<
 *         self.closed = 0
 * 
 */
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_write_mode); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 235, __pyx_L1_error)
  __pyx_v_self->write_mode = __pyx_t_7;

  /* "pygeoprocessing/routing/routing.pyx":236
 *         self.raster_path = <bytes> raster_path
 *         self.write_mode = write_mode
 *         self.closed = 0             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->closed = 0;

  /* "pygeoprocessing/routing/routing.pyx":177
 *     cdef int closed
 * 
 *     def __cinit__(self, raster_path, band_id, write_mode):             # <<<<<<<<<<<<<<
 *         """Create new instance of Managed Raster.
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_raster_info);
  __Pyx_XDECREF(__pyx_v_err_msg);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":238
 *         self.closed = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         """Deallocate _ManagedRaster.
 * 
 */

/* Python wrapper */
static void __pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_2__dealloc__(((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_2__dealloc__(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "pygeoprocessing/routing/routing.pyx":244
 *         dirty memory blocks back to the raster if `self.write_mode` is True.
 *         """
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     def close(self):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 244, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":238
 *         self.closed = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         """Deallocate _ManagedRaster.
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pygeoprocessing.routing.routing._ManagedRaster.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "pygeoprocessing/routing/routing.pyx":246
 *         self.close()
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         """Close the _ManagedRaster and free up resources.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_5close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_14_ManagedRaster_4close[] = "Close the _ManagedRaster and free up resources.\n\n            This call writes any dirty blocks to disk, frees up the memory\n            allocated as part of the cache, and frees all GDAL references.\n\n            Any subsequent calls to any other functions in _ManagedRaster will\n            have undefined behavior.\n        ";
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_5close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_4close(((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_4close(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self) {
  int __pyx_v_xi_copy;
  int __pyx_v_yi_copy;
  PyArrayObject *__pyx_v_block_array = 0;
  double *__pyx_v_double_buffer;
  int __pyx_v_block_xi;
  int __pyx_v_block_yi;
  int __pyx_v_win_xsize;
  int __pyx_v_win_ysize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  std::list<__pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair> ::iterator __pyx_v_it;
  std::list<__pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair> ::iterator __pyx_v_end;
  PyObject *__pyx_v_raster = NULL;
  PyObject *__pyx_v_raster_band = NULL;
  std::set<int> ::iterator __pyx_v_dirty_itr;
  PyObject *__pyx_v_block_index = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_block_array;
  __Pyx_Buffer __pyx_pybuffer_block_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  double *__pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  __Pyx_RefNannySetupContext("close", 0);
  __pyx_pybuffer_block_array.pybuffer.buf = NULL;
  __pyx_pybuffer_block_array.refcount = 0;
  __pyx_pybuffernd_block_array.data = NULL;
  __pyx_pybuffernd_block_array.rcbuffer = &__pyx_pybuffer_block_array;

  /* "pygeoprocessing/routing/routing.pyx":255
 *             have undefined behavior.
 *         """
 *         if self.closed:             # <<<<<<<<<<<<<<
 *             return
 *         self.closed = 1
 */
  __pyx_t_1 = (__pyx_v_self->closed != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":256
 *         """
 *         if self.closed:
 *             return             # <<<<<<<<<<<<<<
 *         self.closed = 1
 *         cdef int xi_copy, yi_copy
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":255
 *             have undefined behavior.
 *         """
 *         if self.closed:             # <<<<<<<<<<<<<<
 *             return
 *         self.closed = 1
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":257
 *         if self.closed:
 *             return
 *         self.closed = 1             # <<<<<<<<<<<<<<
 *         cdef int xi_copy, yi_copy
 *         cdef numpy.ndarray[double, ndim=2] block_array = numpy.empty(
 */
  __pyx_v_self->closed = 1;

  /* "pygeoprocessing/routing/routing.pyx":259
 *         self.closed = 1
 *         cdef int xi_copy, yi_copy
 *         cdef numpy.ndarray[double, ndim=2] block_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (self.block_ysize, self.block_xsize))
 *         cdef double *double_buffer
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 259, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 259, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":260
 *         cdef int xi_copy, yi_copy
 *         cdef numpy.ndarray[double, ndim=2] block_array = numpy.empty(
 *             (self.block_ysize, self.block_xsize))             # <<<<<<<<<<<<<<
 *         cdef double *double_buffer
 *         cdef int block_xi
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 260, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 259, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":259
 *         self.closed = 1
 *         cdef int xi_copy, yi_copy
 *         cdef numpy.ndarray[double, ndim=2] block_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (self.block_ysize, self.block_xsize))
 *         cdef double *double_buffer
 */
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 259, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_block_array = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 259, __pyx_L1_error)
    } else {__pyx_pybuffernd_block_array.diminfo[0].strides = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_block_array.diminfo[0].shape = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_block_array.diminfo[1].strides = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_block_array.diminfo[1].shape = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_block_array = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":273
 *         cdef int yoff
 * 
 *         cdef clist[BlockBufferPair].iterator it = self.lru_cache.begin()             # <<<<<<<<<<<<<<
 *         cdef clist[BlockBufferPair].iterator end = self.lru_cache.end()
 *         if not self.write_mode:
 */
  __pyx_v_it = __pyx_v_self->lru_cache->begin();

  /* "pygeoprocessing/routing/routing.pyx":274
 * 
 *         cdef clist[BlockBufferPair].iterator it = self.lru_cache.begin()
 *         cdef clist[BlockBufferPair].iterator end = self.lru_cache.end()             # <<<<<<<<<<<<<<
 *         if not self.write_mode:
 *             while it != end:
 */
  __pyx_v_end = __pyx_v_self->lru_cache->end();

  /* "pygeoprocessing/routing/routing.pyx":275
 *         cdef clist[BlockBufferPair].iterator it = self.lru_cache.begin()
 *         cdef clist[BlockBufferPair].iterator end = self.lru_cache.end()
 *         if not self.write_mode:             # <<<<<<<<<<<<<<
 *             while it != end:
 *                 # write the changed value back if desired
 */
  __pyx_t_1 = ((!(__pyx_v_self->write_mode != 0)) != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":276
 *         cdef clist[BlockBufferPair].iterator end = self.lru_cache.end()
 *         if not self.write_mode:
 *             while it != end:             # <<<<<<<<<<<<<<
 *                 # write the changed value back if desired
 *                 PyMem_Free(deref(it).second)
 */
    while (1) {
      __pyx_t_1 = ((__pyx_v_it != __pyx_v_end) != 0);
      if (!__pyx_t_1) break;

      /* "pygeoprocessing/routing/routing.pyx":278
 *             while it != end:
 *                 # write the changed value back if desired
 *                 PyMem_Free(deref(it).second)             # <<<<<<<<<<<<<<
 *                 inc(it)
 *             return
 */
      PyMem_Free((*__pyx_v_it).second);

      /* "pygeoprocessing/routing/routing.pyx":279
 *                 # write the changed value back if desired
 *                 PyMem_Free(deref(it).second)
 *                 inc(it)             # <<<<<<<<<<<<<<
 *             return
 * 
 */
      (void)((++__pyx_v_it));
    }

    /* "pygeoprocessing/routing/routing.pyx":280
 *                 PyMem_Free(deref(it).second)
 *                 inc(it)
 *             return             # <<<<<<<<<<<<<<
 * 
 *         raster = gdal.OpenEx(
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":275
 *         cdef clist[BlockBufferPair].iterator it = self.lru_cache.begin()
 *         cdef clist[BlockBufferPair].iterator end = self.lru_cache.end()
 *         if not self.write_mode:             # <<<<<<<<<<<<<<
 *             while it != end:
 *                 # write the changed value back if desired
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":282
 *             return
 * 
 *         raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *             self.raster_path, gdal.GA_Update | gdal.OF_RASTER)
 *         raster_band = raster.GetRasterBand(self.band_id)
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":283
 * 
 *         raster = gdal.OpenEx(
 *             self.raster_path, gdal.GA_Update | gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *         raster_band = raster.GetRasterBand(self.band_id)
 * 
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Or(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_8 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_self->raster_path, __pyx_t_4};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_self->raster_path, __pyx_t_4};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(__pyx_v_self->raster_path);
    __Pyx_GIVEREF(__pyx_v_self->raster_path);
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_8, __pyx_v_self->raster_path);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_8, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_raster = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":284
 *         raster = gdal.OpenEx(
 *             self.raster_path, gdal.GA_Update | gdal.OF_RASTER)
 *         raster_band = raster.GetRasterBand(self.band_id)             # <<<<<<<<<<<<<<
 * 
 *         # if we get here, we're in write_mode
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 284, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_raster_band = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":288
 *         # if we get here, we're in write_mode
 *         cdef cset[int].iterator dirty_itr
 *         while it != end:             # <<<<<<<<<<<<<<
 *             double_buffer = deref(it).second
 *             block_index = deref(it).first
 */
  while (1) {
    __pyx_t_1 = ((__pyx_v_it != __pyx_v_end) != 0);
    if (!__pyx_t_1) break;

    /* "pygeoprocessing/routing/routing.pyx":289
 *         cdef cset[int].iterator dirty_itr
 *         while it != end:
 *             double_buffer = deref(it).second             # <<<<<<<<<<<<<<
 *             block_index = deref(it).first
 * 
 */
    __pyx_t_9 = (*__pyx_v_it).second;
    __pyx_v_double_buffer = __pyx_t_9;

    /* "pygeoprocessing/routing/routing.pyx":290
 *         while it != end:
 *             double_buffer = deref(it).second
 *             block_index = deref(it).first             # <<<<<<<<<<<<<<
 * 
 *             # write to disk if block is dirty
 */
    __pyx_t_2 = __Pyx_PyInt_From_int((*__pyx_v_it).first); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_block_index, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":293
 * 
 *             # write to disk if block is dirty
 *             dirty_itr = self.dirty_blocks.find(block_index)             # <<<<<<<<<<<<<<
 *             if dirty_itr != self.dirty_blocks.end():
 *                 self.dirty_blocks.erase(dirty_itr)
 */
    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_block_index); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 293, __pyx_L1_error)
    __pyx_v_dirty_itr = __pyx_v_self->dirty_blocks.find(__pyx_t_8);

    /* "pygeoprocessing/routing/routing.pyx":294
 *             # write to disk if block is dirty
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr != self.dirty_blocks.end():             # <<<<<<<<<<<<<<
 *                 self.dirty_blocks.erase(dirty_itr)
 *                 block_xi = block_index % self.block_nx
 */
    __pyx_t_1 = ((__pyx_v_dirty_itr != __pyx_v_self->dirty_blocks.end()) != 0);
    if (__pyx_t_1) {

      /* "pygeoprocessing/routing/routing.pyx":295
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr != self.dirty_blocks.end():
 *                 self.dirty_blocks.erase(dirty_itr)             # <<<<<<<<<<<<<<
 *                 block_xi = block_index % self.block_nx
 *                 block_yi = block_index / self.block_nx
 */
      __pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr);

      /* "pygeoprocessing/routing/routing.pyx":296
 *             if dirty_itr != self.dirty_blocks.end():
 *                 self.dirty_blocks.erase(dirty_itr)
 *                 block_xi = block_index % self.block_nx             # <<<<<<<<<<<<<<
 *                 block_yi = block_index / self.block_nx
 * 
 */
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 296, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyNumber_Remainder(__pyx_v_block_index, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 296, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 296, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_block_xi = __pyx_t_8;

      /* "pygeoprocessing/routing/routing.pyx":297
 *                 self.dirty_blocks.erase(dirty_itr)
 *                 block_xi = block_index % self.block_nx
 *                 block_yi = block_index / self.block_nx             # <<<<<<<<<<<<<<
 * 
 *                 # we need the offsets to subtract from global indexes for
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_nx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_block_index, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_block_yi = __pyx_t_8;

      /* "pygeoprocessing/routing/routing.pyx":301
 *                 # we need the offsets to subtract from global indexes for
 *                 # cached array
 *                 xoff = block_xi << self.block_xbits             # <<<<<<<<<<<<<<
 *                 yoff = block_yi << self.block_ybits
 * 
 */
      __pyx_v_xoff = (__pyx_v_block_xi << __pyx_v_self->block_xbits);

      /* "pygeoprocessing/routing/routing.pyx":302
 *                 # cached array
 *                 xoff = block_xi << self.block_xbits
 *                 yoff = block_yi << self.block_ybits             # <<<<<<<<<<<<<<
 * 
 *                 win_xsize = self.block_xsize
 */
      __pyx_v_yoff = (__pyx_v_block_yi << __pyx_v_self->block_ybits);

      /* "pygeoprocessing/routing/routing.pyx":304
 *                 yoff = block_yi << self.block_ybits
 * 
 *                 win_xsize = self.block_xsize             # <<<<<<<<<<<<<<
 *                 win_ysize = self.block_ysize
 * 
 */
      __pyx_t_8 = __pyx_v_self->block_xsize;
      __pyx_v_win_xsize = __pyx_t_8;

      /* "pygeoprocessing/routing/routing.pyx":305
 * 
 *                 win_xsize = self.block_xsize
 *                 win_ysize = self.block_ysize             # <<<<<<<<<<<<<<
 * 
 *                 # clip window sizes if necessary
 */
      __pyx_t_8 = __pyx_v_self->block_ysize;
      __pyx_v_win_ysize = __pyx_t_8;

      /* "pygeoprocessing/routing/routing.pyx":308
 * 
 *                 # clip window sizes if necessary
 *                 if xoff+win_xsize > self.raster_x_size:             # <<<<<<<<<<<<<<
 *                     win_xsize = win_xsize - (
 *                         xoff+win_xsize - self.raster_x_size)
 */
      __pyx_t_1 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_self->raster_x_size) != 0);
      if (__pyx_t_1) {

        /* "pygeoprocessing/routing/routing.pyx":309
 *                 # clip window sizes if necessary
 *                 if xoff+win_xsize > self.raster_x_size:
 *                     win_xsize = win_xsize - (             # <<<<<<<<<<<<<<
 *                         xoff+win_xsize - self.raster_x_size)
 *                 if yoff+win_ysize > self.raster_y_size:
 */
        __pyx_v_win_xsize = (__pyx_v_win_xsize - ((__pyx_v_xoff + __pyx_v_win_xsize) - __pyx_v_self->raster_x_size));

        /* "pygeoprocessing/routing/routing.pyx":308
 * 
 *                 # clip window sizes if necessary
 *                 if xoff+win_xsize > self.raster_x_size:             # <<<<<<<<<<<<<<
 *                     win_xsize = win_xsize - (
 *                         xoff+win_xsize - self.raster_x_size)
 */
      }

      /* "pygeoprocessing/routing/routing.pyx":311
 *                     win_xsize = win_xsize - (
 *                         xoff+win_xsize - self.raster_x_size)
 *                 if yoff+win_ysize > self.raster_y_size:             # <<<<<<<<<<<<<<
 *                     win_ysize = win_ysize - (
 *                         yoff+win_ysize - self.raster_y_size)
 */
      __pyx_t_1 = (((__pyx_v_yoff + __pyx_v_win_ysize) > __pyx_v_self->raster_y_size) != 0);
      if (__pyx_t_1) {

        /* "pygeoprocessing/routing/routing.pyx":312
 *                         xoff+win_xsize - self.raster_x_size)
 *                 if yoff+win_ysize > self.raster_y_size:
 *                     win_ysize = win_ysize - (             # <<<<<<<<<<<<<<
 *                         yoff+win_ysize - self.raster_y_size)
 * 
 */
        __pyx_v_win_ysize = (__pyx_v_win_ysize - ((__pyx_v_yoff + __pyx_v_win_ysize) - __pyx_v_self->raster_y_size));

        /* "pygeoprocessing/routing/routing.pyx":311
 *                     win_xsize = win_xsize - (
 *                         xoff+win_xsize - self.raster_x_size)
 *                 if yoff+win_ysize > self.raster_y_size:             # <<<<<<<<<<<<<<
 *                     win_ysize = win_ysize - (
 *                         yoff+win_ysize - self.raster_y_size)
 */
      }

      /* "pygeoprocessing/routing/routing.pyx":315
 *                         yoff+win_ysize - self.raster_y_size)
 * 
 *                 for xi_copy in range(win_xsize):             # <<<<<<<<<<<<<<
 *                     for yi_copy in range(win_ysize):
 *                         block_array[yi_copy, xi_copy] = (
 */
      __pyx_t_8 = __pyx_v_win_xsize;
      __pyx_t_10 = __pyx_t_8;
      for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
        __pyx_v_xi_copy = __pyx_t_11;

        /* "pygeoprocessing/routing/routing.pyx":316
 * 
 *                 for xi_copy in range(win_xsize):
 *                     for yi_copy in range(win_ysize):             # <<<<<<<<<<<<<<
 *                         block_array[yi_copy, xi_copy] = (
 *                             double_buffer[
 */
        __pyx_t_12 = __pyx_v_win_ysize;
        __pyx_t_13 = __pyx_t_12;
        for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
          __pyx_v_yi_copy = __pyx_t_14;

          /* "pygeoprocessing/routing/routing.pyx":317
 *                 for xi_copy in range(win_xsize):
 *                     for yi_copy in range(win_ysize):
 *                         block_array[yi_copy, xi_copy] = (             # <<<<<<<<<<<<<<
 *                             double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy])
 */
          __pyx_t_15 = __pyx_v_yi_copy;
          __pyx_t_16 = __pyx_v_xi_copy;
          __pyx_t_17 = -1;
          if (__pyx_t_15 < 0) {
            __pyx_t_15 += __pyx_pybuffernd_block_array.diminfo[0].shape;
            if (unlikely(__pyx_t_15 < 0)) __pyx_t_17 = 0;
          } else if (unlikely(__pyx_t_15 >= __pyx_pybuffernd_block_array.diminfo[0].shape)) __pyx_t_17 = 0;
          if (__pyx_t_16 < 0) {
            __pyx_t_16 += __pyx_pybuffernd_block_array.diminfo[1].shape;
            if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 1;
          } else if (unlikely(__pyx_t_16 >= __pyx_pybuffernd_block_array.diminfo[1].shape)) __pyx_t_17 = 1;
          if (unlikely(__pyx_t_17 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_17);
            __PYX_ERR(0, 317, __pyx_L1_error)
          }
          *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_block_array.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_block_array.diminfo[1].strides) = (__pyx_v_double_buffer[((__pyx_v_yi_copy << __pyx_v_self->block_xbits) + __pyx_v_xi_copy)]);
        }
      }

      /* "pygeoprocessing/routing/routing.pyx":320
 *                             double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy])
 *                 raster_band.WriteArray(             # <<<<<<<<<<<<<<
 *                     block_array[0:win_ysize, 0:win_xsize],
 *                     xoff=xoff, yoff=yoff)
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);

      /* "pygeoprocessing/routing/routing.pyx":321
 *                                 (yi_copy << self.block_xbits) + xi_copy])
 *                 raster_band.WriteArray(
 *                     block_array[0:win_ysize, 0:win_xsize],             # <<<<<<<<<<<<<<
 *                     xoff=xoff, yoff=yoff)
 *             PyMem_Free(double_buffer)
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PySlice_New(__pyx_int_0, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 321, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PySlice_New(__pyx_int_0, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 321, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_6);
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 321, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "pygeoprocessing/routing/routing.pyx":320
 *                             double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy])
 *                 raster_band.WriteArray(             # <<<<<<<<<<<<<<
 *                     block_array[0:win_ysize, 0:win_xsize],
 *                     xoff=xoff, yoff=yoff)
 */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 320, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "pygeoprocessing/routing/routing.pyx":322
 *                 raster_band.WriteArray(
 *                     block_array[0:win_ysize, 0:win_xsize],
 *                     xoff=xoff, yoff=yoff)             # <<<<<<<<<<<<<<
 *             PyMem_Free(double_buffer)
 *             inc(it)
 */
      __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_xoff, __pyx_t_5) < 0) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_yoff, __pyx_t_5) < 0) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pygeoprocessing/routing/routing.pyx":320
 *                             double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy])
 *                 raster_band.WriteArray(             # <<<<<<<<<<<<<<
 *                     block_array[0:win_ysize, 0:win_xsize],
 *                     xoff=xoff, yoff=yoff)
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 320, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pygeoprocessing/routing/routing.pyx":294
 *             # write to disk if block is dirty
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr != self.dirty_blocks.end():             # <<<<<<<<<<<<<<
 *                 self.dirty_blocks.erase(dirty_itr)
 *                 block_xi = block_index % self.block_nx
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":323
 *                     block_array[0:win_ysize, 0:win_xsize],
 *                     xoff=xoff, yoff=yoff)
 *             PyMem_Free(double_buffer)             # <<<<<<<<<<<<<<
 *             inc(it)
 *         raster_band.FlushCache()
 */
    PyMem_Free(__pyx_v_double_buffer);

    /* "pygeoprocessing/routing/routing.pyx":324
 *                     xoff=xoff, yoff=yoff)
 *             PyMem_Free(double_buffer)
 *             inc(it)             # <<<<<<<<<<<<<<
 *         raster_band.FlushCache()
 *         raster_band = None
 */
    (void)((++__pyx_v_it));
  }

  /* "pygeoprocessing/routing/routing.pyx":325
 *             PyMem_Free(double_buffer)
 *             inc(it)
 *         raster_band.FlushCache()             # <<<<<<<<<<<<<<
 *         raster_band = None
 *         raster = None
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_FlushCache); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 325, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 325, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":326
 *             inc(it)
 *         raster_band.FlushCache()
 *         raster_band = None             # <<<<<<<<<<<<<<
 *         raster = None
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":327
 *         raster_band.FlushCache()
 *         raster_band = None
 *         raster = None             # <<<<<<<<<<<<<<
 * 
 *     cdef inline void set(self, int xi, int yi, double value):
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_raster, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":246
 *         self.close()
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         """Close the _ManagedRaster and free up resources.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_block_array);
  __Pyx_XDECREF(__pyx_v_raster);
  __Pyx_XDECREF(__pyx_v_raster_band);
  __Pyx_XDECREF(__pyx_v_block_index);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":329
 *         raster = None
 * 
 *     cdef inline void set(self, int xi, int yi, double value):             # <<<<<<<<<<<<<<
 *         """Set the pixel at `xi,yi` to `value`."""
 *         if xi < 0 or xi >= self.raster_x_size:
 */

static CYTHON_INLINE void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi, double __pyx_v_value) {
  int __pyx_v_block_xi;
  int __pyx_v_block_yi;
  int __pyx_v_block_index;
  std::set<int> ::iterator __pyx_v_dirty_itr;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("set", 0);

  /* "pygeoprocessing/routing/routing.pyx":331
 *     cdef inline void set(self, int xi, int yi, double value):
 *         """Set the pixel at `xi,yi` to `value`."""
 *         if xi < 0 or xi >= self.raster_x_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:
 */
  __pyx_t_2 = ((__pyx_v_xi < 0) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_xi >= __pyx_v_self->raster_x_size) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":332
 *         """Set the pixel at `xi,yi` to `value`."""
 *         if xi < 0 or xi >= self.raster_x_size:
 *             LOGGER.error("x out of bounds %s" % xi)             # <<<<<<<<<<<<<<
 *         if yi < 0 or yi >= self.raster_y_size:
 *             LOGGER.error("y out of bounds %s" % yi)
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_error); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_xi); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_x_out_of_bounds_s, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 332, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":331
 *     cdef inline void set(self, int xi, int yi, double value):
 *         """Set the pixel at `xi,yi` to `value`."""
 *         if xi < 0 or xi >= self.raster_x_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":333
 *         if xi < 0 or xi >= self.raster_x_size:
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits
 */
  __pyx_t_2 = ((__pyx_v_yi < 0) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_yi >= __pyx_v_self->raster_y_size) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":334
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:
 *             LOGGER.error("y out of bounds %s" % yi)             # <<<<<<<<<<<<<<
 *         cdef int block_xi = xi >> self.block_xbits
 *         cdef int block_yi = yi >> self.block_ybits
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_error); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_yi); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_y_out_of_bounds_s, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 334, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":333
 *         if xi < 0 or xi >= self.raster_x_size:
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":335
 *         if yi < 0 or yi >= self.raster_y_size:
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits             # <<<<<<<<<<<<<<
 *         cdef int block_yi = yi >> self.block_ybits
 *         # this is the flat index for the block
 */
  __pyx_v_block_xi = (__pyx_v_xi >> __pyx_v_self->block_xbits);

  /* "pygeoprocessing/routing/routing.pyx":336
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits
 *         cdef int block_yi = yi >> self.block_ybits             # <<<<<<<<<<<<<<
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 */
  __pyx_v_block_yi = (__pyx_v_yi >> __pyx_v_self->block_ybits);

  /* "pygeoprocessing/routing/routing.pyx":338
 *         cdef int block_yi = yi >> self.block_ybits
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi             # <<<<<<<<<<<<<<
 *         if not self.lru_cache.exist(block_index):
 *             self._load_block(block_index)
 */
  __pyx_v_block_index = ((__pyx_v_block_yi * __pyx_v_self->block_nx) + __pyx_v_block_xi);

  /* "pygeoprocessing/routing/routing.pyx":339
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 *         if not self.lru_cache.exist(block_index):             # <<<<<<<<<<<<<<
 *             self._load_block(block_index)
 *         self.lru_cache.get(
 */
  __pyx_t_1 = ((!(__pyx_v_self->lru_cache->exist(__pyx_v_block_index) != 0)) != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":340
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 *         if not self.lru_cache.exist(block_index):
 *             self._load_block(block_index)             # <<<<<<<<<<<<<<
 *         self.lru_cache.get(
 *             block_index)[
 */
    ((struct __pyx_vtabstruct_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_v_self->__pyx_vtab)->_load_block(__pyx_v_self, __pyx_v_block_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 340, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":339
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 *         if not self.lru_cache.exist(block_index):             # <<<<<<<<<<<<<<
 *             self._load_block(block_index)
 *         self.lru_cache.get(
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":343
 *         self.lru_cache.get(
 *             block_index)[
 *                 ((yi & (self.block_ymod)) << self.block_xbits) +             # <<<<<<<<<<<<<<
 *                 (xi & (self.block_xmod))] = value
 *         if self.write_mode:
 */
  (__pyx_v_self->lru_cache->get(__pyx_v_block_index)[(((__pyx_v_yi & __pyx_v_self->block_ymod) << __pyx_v_self->block_xbits) + (__pyx_v_xi & __pyx_v_self->block_xmod))]) = __pyx_v_value;

  /* "pygeoprocessing/routing/routing.pyx":345
 *                 ((yi & (self.block_ymod)) << self.block_xbits) +
 *                 (xi & (self.block_xmod))] = value
 *         if self.write_mode:             # <<<<<<<<<<<<<<
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr == self.dirty_blocks.end():
 */
  __pyx_t_1 = (__pyx_v_self->write_mode != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":346
 *                 (xi & (self.block_xmod))] = value
 *         if self.write_mode:
 *             dirty_itr = self.dirty_blocks.find(block_index)             # <<<<<<<<<<<<<<
 *             if dirty_itr == self.dirty_blocks.end():
 *                 self.dirty_blocks.insert(block_index)
 */
    __pyx_v_dirty_itr = __pyx_v_self->dirty_blocks.find(__pyx_v_block_index);

    /* "pygeoprocessing/routing/routing.pyx":347
 *         if self.write_mode:
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr == self.dirty_blocks.end():             # <<<<<<<<<<<<<<
 *                 self.dirty_blocks.insert(block_index)
 * 
 */
    __pyx_t_1 = ((__pyx_v_dirty_itr == __pyx_v_self->dirty_blocks.end()) != 0);
    if (__pyx_t_1) {

      /* "pygeoprocessing/routing/routing.pyx":348
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr == self.dirty_blocks.end():
 *                 self.dirty_blocks.insert(block_index)             # <<<<<<<<<<<<<<
 * 
 *     cdef inline double get(self, int xi, int yi):
 */
      try {
        __pyx_v_self->dirty_blocks.insert(__pyx_v_block_index);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 348, __pyx_L1_error)
      }

      /* "pygeoprocessing/routing/routing.pyx":347
 *         if self.write_mode:
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr == self.dirty_blocks.end():             # <<<<<<<<<<<<<<
 *                 self.dirty_blocks.insert(block_index)
 * 
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":345
 *                 ((yi & (self.block_ymod)) << self.block_xbits) +
 *                 (xi & (self.block_xmod))] = value
 *         if self.write_mode:             # <<<<<<<<<<<<<<
 *             dirty_itr = self.dirty_blocks.find(block_index)
 *             if dirty_itr == self.dirty_blocks.end():
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":329
 *         raster = None
 * 
 *     cdef inline void set(self, int xi, int yi, double value):             # <<<<<<<<<<<<<<
 *         """Set the pixel at `xi,yi` to `value`."""
 *         if xi < 0 or xi >= self.raster_x_size:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_WriteUnraisable("pygeoprocessing.routing.routing._ManagedRaster.set", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "pygeoprocessing/routing/routing.pyx":350
 *                 self.dirty_blocks.insert(block_index)
 * 
 *     cdef inline double get(self, int xi, int yi):             # <<<<<<<<<<<<<<
 *         """Return the value of the pixel at `xi,yi`."""
 *         if xi < 0 or xi >= self.raster_x_size:
 */

static CYTHON_INLINE double __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, int __pyx_v_xi, int __pyx_v_yi) {
  int __pyx_v_block_xi;
  int __pyx_v_block_yi;
  int __pyx_v_block_index;
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("get", 0);

  /* "pygeoprocessing/routing/routing.pyx":352
 *     cdef inline double get(self, int xi, int yi):
 *         """Return the value of the pixel at `xi,yi`."""
 *         if xi < 0 or xi >= self.raster_x_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:
 */
  __pyx_t_2 = ((__pyx_v_xi < 0) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_xi >= __pyx_v_self->raster_x_size) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":353
 *         """Return the value of the pixel at `xi,yi`."""
 *         if xi < 0 or xi >= self.raster_x_size:
 *             LOGGER.error("x out of bounds %s" % xi)             # <<<<<<<<<<<<<<
 *         if yi < 0 or yi >= self.raster_y_size:
 *             LOGGER.error("y out of bounds %s" % yi)
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_error); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_xi); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_x_out_of_bounds_s, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 353, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":352
 *     cdef inline double get(self, int xi, int yi):
 *         """Return the value of the pixel at `xi,yi`."""
 *         if xi < 0 or xi >= self.raster_x_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":354
 *         if xi < 0 or xi >= self.raster_x_size:
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits
 */
  __pyx_t_2 = ((__pyx_v_yi < 0) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_yi >= __pyx_v_self->raster_y_size) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":355
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:
 *             LOGGER.error("y out of bounds %s" % yi)             # <<<<<<<<<<<<<<
 *         cdef int block_xi = xi >> self.block_xbits
 *         cdef int block_yi = yi >> self.block_ybits
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_error); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_yi); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_y_out_of_bounds_s, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_6};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":354
 *         if xi < 0 or xi >= self.raster_x_size:
 *             LOGGER.error("x out of bounds %s" % xi)
 *         if yi < 0 or yi >= self.raster_y_size:             # <<<<<<<<<<<<<<
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":356
 *         if yi < 0 or yi >= self.raster_y_size:
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits             # <<<<<<<<<<<<<<
 *         cdef int block_yi = yi >> self.block_ybits
 *         # this is the flat index for the block
 */
  __pyx_v_block_xi = (__pyx_v_xi >> __pyx_v_self->block_xbits);

  /* "pygeoprocessing/routing/routing.pyx":357
 *             LOGGER.error("y out of bounds %s" % yi)
 *         cdef int block_xi = xi >> self.block_xbits
 *         cdef int block_yi = yi >> self.block_ybits             # <<<<<<<<<<<<<<
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 */
  __pyx_v_block_yi = (__pyx_v_yi >> __pyx_v_self->block_ybits);

  /* "pygeoprocessing/routing/routing.pyx":359
 *         cdef int block_yi = yi >> self.block_ybits
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi             # <<<<<<<<<<<<<<
 *         if not self.lru_cache.exist(block_index):
 *             self._load_block(block_index)
 */
  __pyx_v_block_index = ((__pyx_v_block_yi * __pyx_v_self->block_nx) + __pyx_v_block_xi);

  /* "pygeoprocessing/routing/routing.pyx":360
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 *         if not self.lru_cache.exist(block_index):             # <<<<<<<<<<<<<<
 *             self._load_block(block_index)
 *         return self.lru_cache.get(
 */
  __pyx_t_1 = ((!(__pyx_v_self->lru_cache->exist(__pyx_v_block_index) != 0)) != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":361
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 *         if not self.lru_cache.exist(block_index):
 *             self._load_block(block_index)             # <<<<<<<<<<<<<<
 *         return self.lru_cache.get(
 *             block_index)[
 */
    ((struct __pyx_vtabstruct_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_v_self->__pyx_vtab)->_load_block(__pyx_v_self, __pyx_v_block_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 361, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":360
 *         # this is the flat index for the block
 *         cdef int block_index = block_yi * self.block_nx + block_xi
 *         if not self.lru_cache.exist(block_index):             # <<<<<<<<<<<<<<
 *             self._load_block(block_index)
 *         return self.lru_cache.get(
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":363
 *             self._load_block(block_index)
 *         return self.lru_cache.get(
 *             block_index)[             # <<<<<<<<<<<<<<
 *                 ((yi & (self.block_ymod)) << self.block_xbits) +
 *                 (xi & (self.block_xmod))]
 */
  __pyx_r = (__pyx_v_self->lru_cache->get(__pyx_v_block_index)[(((__pyx_v_yi & __pyx_v_self->block_ymod) << __pyx_v_self->block_xbits) + (__pyx_v_xi & __pyx_v_self->block_xmod))]);
  goto __pyx_L0;

  /* "pygeoprocessing/routing/routing.pyx":350
 *                 self.dirty_blocks.insert(block_index)
 * 
 *     cdef inline double get(self, int xi, int yi):             # <<<<<<<<<<<<<<
 *         """Return the value of the pixel at `xi,yi`."""
 *         if xi < 0 or xi >= self.raster_x_size:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_WriteUnraisable("pygeoprocessing.routing.routing._ManagedRaster.get", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":367
 *                 (xi & (self.block_xmod))]
 * 
 *     cdef void _load_block(self, int block_index) except *:             # <<<<<<<<<<<<<<
 *         cdef int block_xi = block_index % self.block_nx
 *         cdef int block_yi = block_index / self.block_nx
 */

static void __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster__load_block(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, int __pyx_v_block_index) {
  int __pyx_v_block_xi;
  int __pyx_v_block_yi;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_xi_copy;
  int __pyx_v_yi_copy;
  PyArrayObject *__pyx_v_block_array = 0;
  double *__pyx_v_double_buffer;
  std::list<__pyx_t_15pygeoprocessing_7routing_7routing_BlockBufferPair>  __pyx_v_removed_value_list;
  int __pyx_v_win_xsize;
  int __pyx_v_win_ysize;
  PyObject *__pyx_v_raster = NULL;
  PyObject *__pyx_v_raster_band = NULL;
  std::set<int> ::iterator __pyx_v_dirty_itr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_block_array;
  __Pyx_Buffer __pyx_pybuffer_block_array;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyArrayObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  int __pyx_t_16;
  Py_ssize_t __pyx_t_17;
  Py_ssize_t __pyx_t_18;
  int __pyx_t_19;
  double *__pyx_t_20;
  Py_ssize_t __pyx_t_21;
  Py_ssize_t __pyx_t_22;
  __Pyx_RefNannySetupContext("_load_block", 0);
  __pyx_pybuffer_block_array.pybuffer.buf = NULL;
  __pyx_pybuffer_block_array.refcount = 0;
  __pyx_pybuffernd_block_array.data = NULL;
  __pyx_pybuffernd_block_array.rcbuffer = &__pyx_pybuffer_block_array;

  /* "pygeoprocessing/routing/routing.pyx":368
 * 
 *     cdef void _load_block(self, int block_index) except *:
 *         cdef int block_xi = block_index % self.block_nx             # <<<<<<<<<<<<<<
 *         cdef int block_yi = block_index / self.block_nx
 * 
 */
  if (unlikely(__pyx_v_self->block_nx == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 368, __pyx_L1_error)
  }
  __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx);

  /* "pygeoprocessing/routing/routing.pyx":369
 *     cdef void _load_block(self, int block_index) except *:
 *         cdef int block_xi = block_index % self.block_nx
 *         cdef int block_yi = block_index / self.block_nx             # <<<<<<<<<<<<<<
 * 
 *         # we need the offsets to subtract from global indexes for cached array
 */
  if (unlikely(__pyx_v_self->block_nx == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 369, __pyx_L1_error)
  }
  else if (sizeof(int) == sizeof(long) && (!(((int)-1) > 0)) && unlikely(__pyx_v_self->block_nx == (int)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_block_index))) {
    PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
    __PYX_ERR(0, 369, __pyx_L1_error)
  }
  __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx);

  /* "pygeoprocessing/routing/routing.pyx":372
 * 
 *         # we need the offsets to subtract from global indexes for cached array
 *         cdef int xoff = block_xi << self.block_xbits             # <<<<<<<<<<<<<<
 *         cdef int yoff = block_yi << self.block_ybits
 * 
 */
  __pyx_v_xoff = (__pyx_v_block_xi << __pyx_v_self->block_xbits);

  /* "pygeoprocessing/routing/routing.pyx":373
 *         # we need the offsets to subtract from global indexes for cached array
 *         cdef int xoff = block_xi << self.block_xbits
 *         cdef int yoff = block_yi << self.block_ybits             # <<<<<<<<<<<<<<
 * 
 *         cdef int xi_copy, yi_copy
 */
  __pyx_v_yoff = (__pyx_v_block_yi << __pyx_v_self->block_ybits);

  /* "pygeoprocessing/routing/routing.pyx":384
 *         # initially the win size is the same as the block size unless
 *         # we're at the edge of a raster
 *         cdef int win_xsize = self.block_xsize             # <<<<<<<<<<<<<<
 *         cdef int win_ysize = self.block_ysize
 * 
 */
  __pyx_t_1 = __pyx_v_self->block_xsize;
  __pyx_v_win_xsize = __pyx_t_1;

  /* "pygeoprocessing/routing/routing.pyx":385
 *         # we're at the edge of a raster
 *         cdef int win_xsize = self.block_xsize
 *         cdef int win_ysize = self.block_ysize             # <<<<<<<<<<<<<<
 * 
 *         # load a new block
 */
  __pyx_t_1 = __pyx_v_self->block_ysize;
  __pyx_v_win_ysize = __pyx_t_1;

  /* "pygeoprocessing/routing/routing.pyx":388
 * 
 *         # load a new block
 *         if xoff+win_xsize > self.raster_x_size:             # <<<<<<<<<<<<<<
 *             win_xsize = win_xsize - (xoff+win_xsize - self.raster_x_size)
 *         if yoff+win_ysize > self.raster_y_size:
 */
  __pyx_t_2 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_self->raster_x_size) != 0);
  if (__pyx_t_2) {

    /* "pygeoprocessing/routing/routing.pyx":389
 *         # load a new block
 *         if xoff+win_xsize > self.raster_x_size:
 *             win_xsize = win_xsize - (xoff+win_xsize - self.raster_x_size)             # <<<<<<<<<<<<<<
 *         if yoff+win_ysize > self.raster_y_size:
 *             win_ysize = win_ysize - (yoff+win_ysize - self.raster_y_size)
 */
    __pyx_v_win_xsize = (__pyx_v_win_xsize - ((__pyx_v_xoff + __pyx_v_win_xsize) - __pyx_v_self->raster_x_size));

    /* "pygeoprocessing/routing/routing.pyx":388
 * 
 *         # load a new block
 *         if xoff+win_xsize > self.raster_x_size:             # <<<<<<<<<<<<<<
 *             win_xsize = win_xsize - (xoff+win_xsize - self.raster_x_size)
 *         if yoff+win_ysize > self.raster_y_size:
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":390
 *         if xoff+win_xsize > self.raster_x_size:
 *             win_xsize = win_xsize - (xoff+win_xsize - self.raster_x_size)
 *         if yoff+win_ysize > self.raster_y_size:             # <<<<<<<<<<<<<<
 *             win_ysize = win_ysize - (yoff+win_ysize - self.raster_y_size)
 * 
 */
  __pyx_t_2 = (((__pyx_v_yoff + __pyx_v_win_ysize) > __pyx_v_self->raster_y_size) != 0);
  if (__pyx_t_2) {

    /* "pygeoprocessing/routing/routing.pyx":391
 *             win_xsize = win_xsize - (xoff+win_xsize - self.raster_x_size)
 *         if yoff+win_ysize > self.raster_y_size:
 *             win_ysize = win_ysize - (yoff+win_ysize - self.raster_y_size)             # <<<<<<<<<<<<<<
 * 
 *         raster = gdal.OpenEx(self.raster_path, gdal.OF_RASTER)
 */
    __pyx_v_win_ysize = (__pyx_v_win_ysize - ((__pyx_v_yoff + __pyx_v_win_ysize) - __pyx_v_self->raster_y_size));

    /* "pygeoprocessing/routing/routing.pyx":390
 *         if xoff+win_xsize > self.raster_x_size:
 *             win_xsize = win_xsize - (xoff+win_xsize - self.raster_x_size)
 *         if yoff+win_ysize > self.raster_y_size:             # <<<<<<<<<<<<<<
 *             win_ysize = win_ysize - (yoff+win_ysize - self.raster_y_size)
 * 
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":393
 *             win_ysize = win_ysize - (yoff+win_ysize - self.raster_y_size)
 * 
 *         raster = gdal.OpenEx(self.raster_path, gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *         raster_band = raster.GetRasterBand(self.band_id)
 *         block_array = raster_band.ReadAsArray(
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  __pyx_t_1 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_1 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_self->raster_path, __pyx_t_6};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 393, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_self->raster_path, __pyx_t_6};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 393, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 393, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_4) {
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
    }
    __Pyx_INCREF(__pyx_v_self->raster_path);
    __Pyx_GIVEREF(__pyx_v_self->raster_path);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_1, __pyx_v_self->raster_path);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_1, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 393, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_raster = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":394
 * 
 *         raster = gdal.OpenEx(self.raster_path, gdal.OF_RASTER)
 *         raster_band = raster.GetRasterBand(self.band_id)             # <<<<<<<<<<<<<<
 *         block_array = raster_band.ReadAsArray(
 *             xoff=xoff, yoff=yoff, win_xsize=win_xsize,
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_raster_band = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":395
 *         raster = gdal.OpenEx(self.raster_path, gdal.OF_RASTER)
 *         raster_band = raster.GetRasterBand(self.band_id)
 *         block_array = raster_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             xoff=xoff, yoff=yoff, win_xsize=win_xsize,
 *             win_ysize=win_ysize).astype(numpy.float64)
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":396
 *         raster_band = raster.GetRasterBand(self.band_id)
 *         block_array = raster_band.ReadAsArray(
 *             xoff=xoff, yoff=yoff, win_xsize=win_xsize,             # <<<<<<<<<<<<<<
 *             win_ysize=win_ysize).astype(numpy.float64)
 *         raster_band = None
 */
  __pyx_t_4 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_xoff, __pyx_t_7) < 0) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_yoff, __pyx_t_7) < 0) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_win_xsize, __pyx_t_7) < 0) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":397
 *         block_array = raster_band.ReadAsArray(
 *             xoff=xoff, yoff=yoff, win_xsize=win_xsize,
 *             win_ysize=win_ysize).astype(numpy.float64)             # <<<<<<<<<<<<<<
 *         raster_band = None
 *         raster = None
 */
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_win_ysize, __pyx_t_7) < 0) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":395
 *         raster = gdal.OpenEx(self.raster_path, gdal.OF_RASTER)
 *         raster_band = raster.GetRasterBand(self.band_id)
 *         block_array = raster_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             xoff=xoff, yoff=yoff, win_xsize=win_xsize,
 *             win_ysize=win_ysize).astype(numpy.float64)
 */
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":397
 *         block_array = raster_band.ReadAsArray(
 *             xoff=xoff, yoff=yoff, win_xsize=win_xsize,
 *             win_ysize=win_ysize).astype(numpy.float64)             # <<<<<<<<<<<<<<
 *         raster_band = None
 *         raster = None
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_astype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 397, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 397, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_7) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 397, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer);
    __pyx_t_1 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_1 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_block_array, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
      __pyx_t_9 = __pyx_t_10 = __pyx_t_11 = 0;
    }
    __pyx_pybuffernd_block_array.diminfo[0].strides = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_block_array.diminfo[0].shape = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_block_array.diminfo[1].strides = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_block_array.diminfo[1].shape = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 395, __pyx_L1_error)
  }
  __pyx_t_8 = 0;
  __pyx_v_block_array = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":398
 *             xoff=xoff, yoff=yoff, win_xsize=win_xsize,
 *             win_ysize=win_ysize).astype(numpy.float64)
 *         raster_band = None             # <<<<<<<<<<<<<<
 *         raster = None
 *         double_buffer = <double*>PyMem_Malloc(
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":399
 *             win_ysize=win_ysize).astype(numpy.float64)
 *         raster_band = None
 *         raster = None             # <<<<<<<<<<<<<<
 *         double_buffer = <double*>PyMem_Malloc(
 *             (sizeof(double) << self.block_xbits) * win_ysize)
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_raster, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":400
 *         raster_band = None
 *         raster = None
 *         double_buffer = <double*>PyMem_Malloc(             # <<<<<<<<<<<<<<
 *             (sizeof(double) << self.block_xbits) * win_ysize)
 *         for xi_copy in range(win_xsize):
 */
  __pyx_v_double_buffer = ((double *)PyMem_Malloc((((sizeof(double)) << __pyx_v_self->block_xbits) * __pyx_v_win_ysize)));

  /* "pygeoprocessing/routing/routing.pyx":402
 *         double_buffer = <double*>PyMem_Malloc(
 *             (sizeof(double) << self.block_xbits) * win_ysize)
 *         for xi_copy in range(win_xsize):             # <<<<<<<<<<<<<<
 *             for yi_copy in range(win_ysize):
 *                 double_buffer[(yi_copy << self.block_xbits)+xi_copy] = (
 */
  __pyx_t_1 = __pyx_v_win_xsize;
  __pyx_t_12 = __pyx_t_1;
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_xi_copy = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":403
 *             (sizeof(double) << self.block_xbits) * win_ysize)
 *         for xi_copy in range(win_xsize):
 *             for yi_copy in range(win_ysize):             # <<<<<<<<<<<<<<
 *                 double_buffer[(yi_copy << self.block_xbits)+xi_copy] = (
 *                     block_array[yi_copy, xi_copy])
 */
    __pyx_t_14 = __pyx_v_win_ysize;
    __pyx_t_15 = __pyx_t_14;
    for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
      __pyx_v_yi_copy = __pyx_t_16;

      /* "pygeoprocessing/routing/routing.pyx":405
 *             for yi_copy in range(win_ysize):
 *                 double_buffer[(yi_copy << self.block_xbits)+xi_copy] = (
 *                     block_array[yi_copy, xi_copy])             # <<<<<<<<<<<<<<
 *         self.lru_cache.put(
 *             <int>block_index, <double*>double_buffer, removed_value_list)
 */
      __pyx_t_17 = __pyx_v_yi_copy;
      __pyx_t_18 = __pyx_v_xi_copy;
      __pyx_t_19 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_pybuffernd_block_array.diminfo[0].shape;
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_pybuffernd_block_array.diminfo[0].shape)) __pyx_t_19 = 0;
      if (__pyx_t_18 < 0) {
        __pyx_t_18 += __pyx_pybuffernd_block_array.diminfo[1].shape;
        if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1;
      } else if (unlikely(__pyx_t_18 >= __pyx_pybuffernd_block_array.diminfo[1].shape)) __pyx_t_19 = 1;
      if (unlikely(__pyx_t_19 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_19);
        __PYX_ERR(0, 405, __pyx_L1_error)
      }

      /* "pygeoprocessing/routing/routing.pyx":404
 *         for xi_copy in range(win_xsize):
 *             for yi_copy in range(win_ysize):
 *                 double_buffer[(yi_copy << self.block_xbits)+xi_copy] = (             # <<<<<<<<<<<<<<
 *                     block_array[yi_copy, xi_copy])
 *         self.lru_cache.put(
 */
      (__pyx_v_double_buffer[((__pyx_v_yi_copy << __pyx_v_self->block_xbits) + __pyx_v_xi_copy)]) = (*__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_block_array.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_block_array.diminfo[1].strides));
    }
  }

  /* "pygeoprocessing/routing/routing.pyx":406
 *                 double_buffer[(yi_copy << self.block_xbits)+xi_copy] = (
 *                     block_array[yi_copy, xi_copy])
 *         self.lru_cache.put(             # <<<<<<<<<<<<<<
 *             <int>block_index, <double*>double_buffer, removed_value_list)
 * 
 */
  __pyx_v_self->lru_cache->put(((int)__pyx_v_block_index), ((double *)__pyx_v_double_buffer), __pyx_v_removed_value_list);

  /* "pygeoprocessing/routing/routing.pyx":409
 *             <int>block_index, <double*>double_buffer, removed_value_list)
 * 
 *         if self.write_mode:             # <<<<<<<<<<<<<<
 *             raster = gdal.OpenEx(
 *                 self.raster_path, gdal.GA_Update | gdal.OF_RASTER)
 */
  __pyx_t_2 = (__pyx_v_self->write_mode != 0);
  if (__pyx_t_2) {

    /* "pygeoprocessing/routing/routing.pyx":410
 * 
 *         if self.write_mode:
 *             raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *                 self.raster_path, gdal.GA_Update | gdal.OF_RASTER)
 *             raster_band = raster.GetRasterBand(self.band_id)
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":411
 *         if self.write_mode:
 *             raster = gdal.OpenEx(
 *                 self.raster_path, gdal.GA_Update | gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *             raster_band = raster.GetRasterBand(self.band_id)
 * 
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Or(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    __pyx_t_1 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_1 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_self->raster_path, __pyx_t_4};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 410, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_self->raster_path, __pyx_t_4};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 410, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 410, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_INCREF(__pyx_v_self->raster_path);
      __Pyx_GIVEREF(__pyx_v_self->raster_path);
      PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_1, __pyx_v_self->raster_path);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 410, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_raster, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":412
 *             raster = gdal.OpenEx(
 *                 self.raster_path, gdal.GA_Update | gdal.OF_RASTER)
 *             raster_band = raster.GetRasterBand(self.band_id)             # <<<<<<<<<<<<<<
 * 
 *         block_array = numpy.empty(
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 412, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->band_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 412, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else
      #endif
      {
        __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
        __pyx_t_5 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_raster_band, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":409
 *             <int>block_index, <double*>double_buffer, removed_value_list)
 * 
 *         if self.write_mode:             # <<<<<<<<<<<<<<
 *             raster = gdal.OpenEx(
 *                 self.raster_path, gdal.GA_Update | gdal.OF_RASTER)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":414
 *             raster_band = raster.GetRasterBand(self.band_id)
 * 
 *         block_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (self.block_ysize, self.block_xsize), dtype=numpy.double)
 *         while not removed_value_list.empty():
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":415
 * 
 *         block_array = numpy.empty(
 *             (self.block_ysize, self.block_xsize), dtype=numpy.double)             # <<<<<<<<<<<<<<
 *         while not removed_value_list.empty():
 *             # write the changed value back if desired
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->block_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_self->block_xsize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7);
  __pyx_t_3 = 0;
  __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":414
 *             raster_band = raster.GetRasterBand(self.band_id)
 * 
 *         block_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (self.block_ysize, self.block_xsize), dtype=numpy.double)
 *         while not removed_value_list.empty():
 */
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":415
 * 
 *         block_array = numpy.empty(
 *             (self.block_ysize, self.block_xsize), dtype=numpy.double)             # <<<<<<<<<<<<<<
 *         while not removed_value_list.empty():
 *             # write the changed value back if desired
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_double); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":414
 *             raster_band = raster.GetRasterBand(self.band_id)
 * 
 *         block_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (self.block_ysize, self.block_xsize), dtype=numpy.double)
 *         while not removed_value_list.empty():
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 414, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer);
    __pyx_t_1 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_1 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_block_array, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      }
      __pyx_t_11 = __pyx_t_10 = __pyx_t_9 = 0;
    }
    __pyx_pybuffernd_block_array.diminfo[0].strides = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_block_array.diminfo[0].shape = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_block_array.diminfo[1].strides = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_block_array.diminfo[1].shape = __pyx_pybuffernd_block_array.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 414, __pyx_L1_error)
  }
  __pyx_t_8 = 0;
  __Pyx_DECREF_SET(__pyx_v_block_array, ((PyArrayObject *)__pyx_t_4));
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":416
 *         block_array = numpy.empty(
 *             (self.block_ysize, self.block_xsize), dtype=numpy.double)
 *         while not removed_value_list.empty():             # <<<<<<<<<<<<<<
 *             # write the changed value back if desired
 *             double_buffer = removed_value_list.front().second
 */
  while (1) {
    __pyx_t_2 = ((!(__pyx_v_removed_value_list.empty() != 0)) != 0);
    if (!__pyx_t_2) break;

    /* "pygeoprocessing/routing/routing.pyx":418
 *         while not removed_value_list.empty():
 *             # write the changed value back if desired
 *             double_buffer = removed_value_list.front().second             # <<<<<<<<<<<<<<
 * 
 *             if self.write_mode:
 */
    __pyx_t_20 = __pyx_v_removed_value_list.front().second;
    __pyx_v_double_buffer = __pyx_t_20;

    /* "pygeoprocessing/routing/routing.pyx":420
 *             double_buffer = removed_value_list.front().second
 * 
 *             if self.write_mode:             # <<<<<<<<<<<<<<
 *                 block_index = removed_value_list.front().first
 * 
 */
    __pyx_t_2 = (__pyx_v_self->write_mode != 0);
    if (__pyx_t_2) {

      /* "pygeoprocessing/routing/routing.pyx":421
 * 
 *             if self.write_mode:
 *                 block_index = removed_value_list.front().first             # <<<<<<<<<<<<<<
 * 
 *                 # write back the block if it's dirty
 */
      __pyx_t_1 = __pyx_v_removed_value_list.front().first;
      __pyx_v_block_index = __pyx_t_1;

      /* "pygeoprocessing/routing/routing.pyx":424
 * 
 *                 # write back the block if it's dirty
 *                 dirty_itr = self.dirty_blocks.find(block_index)             # <<<<<<<<<<<<<<
 *                 if dirty_itr != self.dirty_blocks.end():
 *                     self.dirty_blocks.erase(dirty_itr)
 */
      __pyx_v_dirty_itr = __pyx_v_self->dirty_blocks.find(__pyx_v_block_index);

      /* "pygeoprocessing/routing/routing.pyx":425
 *                 # write back the block if it's dirty
 *                 dirty_itr = self.dirty_blocks.find(block_index)
 *                 if dirty_itr != self.dirty_blocks.end():             # <<<<<<<<<<<<<<
 *                     self.dirty_blocks.erase(dirty_itr)
 * 
 */
      __pyx_t_2 = ((__pyx_v_dirty_itr != __pyx_v_self->dirty_blocks.end()) != 0);
      if (__pyx_t_2) {

        /* "pygeoprocessing/routing/routing.pyx":426
 *                 dirty_itr = self.dirty_blocks.find(block_index)
 *                 if dirty_itr != self.dirty_blocks.end():
 *                     self.dirty_blocks.erase(dirty_itr)             # <<<<<<<<<<<<<<
 * 
 *                     block_xi = block_index % self.block_nx
 */
        __pyx_v_self->dirty_blocks.erase(__pyx_v_dirty_itr);

        /* "pygeoprocessing/routing/routing.pyx":428
 *                     self.dirty_blocks.erase(dirty_itr)
 * 
 *                     block_xi = block_index % self.block_nx             # <<<<<<<<<<<<<<
 *                     block_yi = block_index / self.block_nx
 * 
 */
        if (unlikely(__pyx_v_self->block_nx == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
          __PYX_ERR(0, 428, __pyx_L1_error)
        }
        __pyx_v_block_xi = __Pyx_mod_int(__pyx_v_block_index, __pyx_v_self->block_nx);

        /* "pygeoprocessing/routing/routing.pyx":429
 * 
 *                     block_xi = block_index % self.block_nx
 *                     block_yi = block_index / self.block_nx             # <<<<<<<<<<<<<<
 * 
 *                     xoff = block_xi << self.block_xbits
 */
        if (unlikely(__pyx_v_self->block_nx == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
          __PYX_ERR(0, 429, __pyx_L1_error)
        }
        else if (sizeof(int) == sizeof(long) && (!(((int)-1) > 0)) && unlikely(__pyx_v_self->block_nx == (int)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_block_index))) {
          PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
          __PYX_ERR(0, 429, __pyx_L1_error)
        }
        __pyx_v_block_yi = __Pyx_div_int(__pyx_v_block_index, __pyx_v_self->block_nx);

        /* "pygeoprocessing/routing/routing.pyx":431
 *                     block_yi = block_index / self.block_nx
 * 
 *                     xoff = block_xi << self.block_xbits             # <<<<<<<<<<<<<<
 *                     yoff = block_yi << self.block_ybits
 * 
 */
        __pyx_v_xoff = (__pyx_v_block_xi << __pyx_v_self->block_xbits);

        /* "pygeoprocessing/routing/routing.pyx":432
 * 
 *                     xoff = block_xi << self.block_xbits
 *                     yoff = block_yi << self.block_ybits             # <<<<<<<<<<<<<<
 * 
 *                     win_xsize = self.block_xsize
 */
        __pyx_v_yoff = (__pyx_v_block_yi << __pyx_v_self->block_ybits);

        /* "pygeoprocessing/routing/routing.pyx":434
 *                     yoff = block_yi << self.block_ybits
 * 
 *                     win_xsize = self.block_xsize             # <<<<<<<<<<<<<<
 *                     win_ysize = self.block_ysize
 * 
 */
        __pyx_t_1 = __pyx_v_self->block_xsize;
        __pyx_v_win_xsize = __pyx_t_1;

        /* "pygeoprocessing/routing/routing.pyx":435
 * 
 *                     win_xsize = self.block_xsize
 *                     win_ysize = self.block_ysize             # <<<<<<<<<<<<<<
 * 
 *                     if xoff+win_xsize > self.raster_x_size:
 */
        __pyx_t_1 = __pyx_v_self->block_ysize;
        __pyx_v_win_ysize = __pyx_t_1;

        /* "pygeoprocessing/routing/routing.pyx":437
 *                     win_ysize = self.block_ysize
 * 
 *                     if xoff+win_xsize > self.raster_x_size:             # <<<<<<<<<<<<<<
 *                         win_xsize = win_xsize - (
 *                             xoff+win_xsize - self.raster_x_size)
 */
        __pyx_t_2 = (((__pyx_v_xoff + __pyx_v_win_xsize) > __pyx_v_self->raster_x_size) != 0);
        if (__pyx_t_2) {

          /* "pygeoprocessing/routing/routing.pyx":438
 * 
 *                     if xoff+win_xsize > self.raster_x_size:
 *                         win_xsize = win_xsize - (             # <<<<<<<<<<<<<<
 *                             xoff+win_xsize - self.raster_x_size)
 *                     if yoff+win_ysize > self.raster_y_size:
 */
          __pyx_v_win_xsize = (__pyx_v_win_xsize - ((__pyx_v_xoff + __pyx_v_win_xsize) - __pyx_v_self->raster_x_size));

          /* "pygeoprocessing/routing/routing.pyx":437
 *                     win_ysize = self.block_ysize
 * 
 *                     if xoff+win_xsize > self.raster_x_size:             # <<<<<<<<<<<<<<
 *                         win_xsize = win_xsize - (
 *                             xoff+win_xsize - self.raster_x_size)
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":440
 *                         win_xsize = win_xsize - (
 *                             xoff+win_xsize - self.raster_x_size)
 *                     if yoff+win_ysize > self.raster_y_size:             # <<<<<<<<<<<<<<
 *                         win_ysize = win_ysize - (
 *                             yoff+win_ysize - self.raster_y_size)
 */
        __pyx_t_2 = (((__pyx_v_yoff + __pyx_v_win_ysize) > __pyx_v_self->raster_y_size) != 0);
        if (__pyx_t_2) {

          /* "pygeoprocessing/routing/routing.pyx":441
 *                             xoff+win_xsize - self.raster_x_size)
 *                     if yoff+win_ysize > self.raster_y_size:
 *                         win_ysize = win_ysize - (             # <<<<<<<<<<<<<<
 *                             yoff+win_ysize - self.raster_y_size)
 * 
 */
          __pyx_v_win_ysize = (__pyx_v_win_ysize - ((__pyx_v_yoff + __pyx_v_win_ysize) - __pyx_v_self->raster_y_size));

          /* "pygeoprocessing/routing/routing.pyx":440
 *                         win_xsize = win_xsize - (
 *                             xoff+win_xsize - self.raster_x_size)
 *                     if yoff+win_ysize > self.raster_y_size:             # <<<<<<<<<<<<<<
 *                         win_ysize = win_ysize - (
 *                             yoff+win_ysize - self.raster_y_size)
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":444
 *                             yoff+win_ysize - self.raster_y_size)
 * 
 *                     for xi_copy in range(win_xsize):             # <<<<<<<<<<<<<<
 *                         for yi_copy in range(win_ysize):
 *                             block_array[yi_copy, xi_copy] = double_buffer[
 */
        __pyx_t_1 = __pyx_v_win_xsize;
        __pyx_t_12 = __pyx_t_1;
        for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
          __pyx_v_xi_copy = __pyx_t_13;

          /* "pygeoprocessing/routing/routing.pyx":445
 * 
 *                     for xi_copy in range(win_xsize):
 *                         for yi_copy in range(win_ysize):             # <<<<<<<<<<<<<<
 *                             block_array[yi_copy, xi_copy] = double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy]
 */
          __pyx_t_14 = __pyx_v_win_ysize;
          __pyx_t_15 = __pyx_t_14;
          for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
            __pyx_v_yi_copy = __pyx_t_16;

            /* "pygeoprocessing/routing/routing.pyx":446
 *                     for xi_copy in range(win_xsize):
 *                         for yi_copy in range(win_ysize):
 *                             block_array[yi_copy, xi_copy] = double_buffer[             # <<<<<<<<<<<<<<
 *                                 (yi_copy << self.block_xbits) + xi_copy]
 *                     raster_band.WriteArray(
 */
            __pyx_t_21 = __pyx_v_yi_copy;
            __pyx_t_22 = __pyx_v_xi_copy;
            __pyx_t_19 = -1;
            if (__pyx_t_21 < 0) {
              __pyx_t_21 += __pyx_pybuffernd_block_array.diminfo[0].shape;
              if (unlikely(__pyx_t_21 < 0)) __pyx_t_19 = 0;
            } else if (unlikely(__pyx_t_21 >= __pyx_pybuffernd_block_array.diminfo[0].shape)) __pyx_t_19 = 0;
            if (__pyx_t_22 < 0) {
              __pyx_t_22 += __pyx_pybuffernd_block_array.diminfo[1].shape;
              if (unlikely(__pyx_t_22 < 0)) __pyx_t_19 = 1;
            } else if (unlikely(__pyx_t_22 >= __pyx_pybuffernd_block_array.diminfo[1].shape)) __pyx_t_19 = 1;
            if (unlikely(__pyx_t_19 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_19);
              __PYX_ERR(0, 446, __pyx_L1_error)
            }
            *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_block_array.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_block_array.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_block_array.diminfo[1].strides) = (__pyx_v_double_buffer[((__pyx_v_yi_copy << __pyx_v_self->block_xbits) + __pyx_v_xi_copy)]);
          }
        }

        /* "pygeoprocessing/routing/routing.pyx":448
 *                             block_array[yi_copy, xi_copy] = double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy]
 *                     raster_band.WriteArray(             # <<<<<<<<<<<<<<
 *                         block_array[0:win_ysize, 0:win_xsize],
 *                         xoff=xoff, yoff=yoff)
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_raster_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 448, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);

        /* "pygeoprocessing/routing/routing.pyx":449
 *                                 (yi_copy << self.block_xbits) + xi_copy]
 *                     raster_band.WriteArray(
 *                         block_array[0:win_ysize, 0:win_xsize],             # <<<<<<<<<<<<<<
 *                         xoff=xoff, yoff=yoff)
 *             PyMem_Free(double_buffer)
 */
        __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_win_ysize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_7 = PySlice_New(__pyx_int_0, __pyx_t_5, Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_win_xsize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = PySlice_New(__pyx_int_0, __pyx_t_5, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
        __pyx_t_7 = 0;
        __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_block_array), __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "pygeoprocessing/routing/routing.pyx":448
 *                             block_array[yi_copy, xi_copy] = double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy]
 *                     raster_band.WriteArray(             # <<<<<<<<<<<<<<
 *                         block_array[0:win_ysize, 0:win_xsize],
 *                         xoff=xoff, yoff=yoff)
 */
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 448, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pygeoprocessing/routing/routing.pyx":450
 *                     raster_band.WriteArray(
 *                         block_array[0:win_ysize, 0:win_xsize],
 *                         xoff=xoff, yoff=yoff)             # <<<<<<<<<<<<<<
 *             PyMem_Free(double_buffer)
 *             removed_value_list.pop_front()
 */
        __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_xoff); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_xoff, __pyx_t_7) < 0) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_yoff); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_yoff, __pyx_t_7) < 0) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "pygeoprocessing/routing/routing.pyx":448
 *                             block_array[yi_copy, xi_copy] = double_buffer[
 *                                 (yi_copy << self.block_xbits) + xi_copy]
 *                     raster_band.WriteArray(             # <<<<<<<<<<<<<<
 *                         block_array[0:win_ysize, 0:win_xsize],
 *                         xoff=xoff, yoff=yoff)
 */
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 448, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "pygeoprocessing/routing/routing.pyx":425
 *                 # write back the block if it's dirty
 *                 dirty_itr = self.dirty_blocks.find(block_index)
 *                 if dirty_itr != self.dirty_blocks.end():             # <<<<<<<<<<<<<<
 *                     self.dirty_blocks.erase(dirty_itr)
 * 
 */
      }

      /* "pygeoprocessing/routing/routing.pyx":420
 *             double_buffer = removed_value_list.front().second
 * 
 *             if self.write_mode:             # <<<<<<<<<<<<<<
 *                 block_index = removed_value_list.front().first
 * 
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":451
 *                         block_array[0:win_ysize, 0:win_xsize],
 *                         xoff=xoff, yoff=yoff)
 *             PyMem_Free(double_buffer)             # <<<<<<<<<<<<<<
 *             removed_value_list.pop_front()
 * 
 */
    PyMem_Free(__pyx_v_double_buffer);

    /* "pygeoprocessing/routing/routing.pyx":452
 *                         xoff=xoff, yoff=yoff)
 *             PyMem_Free(double_buffer)
 *             removed_value_list.pop_front()             # <<<<<<<<<<<<<<
 * 
 *         if self.write_mode:
 */
    __pyx_v_removed_value_list.pop_front();
  }

  /* "pygeoprocessing/routing/routing.pyx":454
 *             removed_value_list.pop_front()
 * 
 *         if self.write_mode:             # <<<<<<<<<<<<<<
 *             raster_band = None
 *             raster = None
 */
  __pyx_t_2 = (__pyx_v_self->write_mode != 0);
  if (__pyx_t_2) {

    /* "pygeoprocessing/routing/routing.pyx":455
 * 
 *         if self.write_mode:
 *             raster_band = None             # <<<<<<<<<<<<<<
 *             raster = None
 * 
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_raster_band, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":456
 *         if self.write_mode:
 *             raster_band = None
 *             raster = None             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_raster, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":454
 *             removed_value_list.pop_front()
 * 
 *         if self.write_mode:             # <<<<<<<<<<<<<<
 *             raster_band = None
 *             raster = None
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":367
 *                 (xi & (self.block_xmod))]
 * 
 *     cdef void _load_block(self, int block_index) except *:             # <<<<<<<<<<<<<<
 *         cdef int block_xi = block_index % self.block_nx
 *         cdef int block_yi = block_index / self.block_nx
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster._load_block", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_block_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_block_array);
  __Pyx_XDECREF(__pyx_v_raster);
  __Pyx_XDECREF(__pyx_v_raster_band);
  __Pyx_RefNannyFinishContext();
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_6__reduce_cython__(((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_8__setstate_cython__(((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14_ManagedRaster_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._ManagedRaster.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":459
 * 
 * 
 * def _generate_read_bounds(offset_dict, raster_x_size, raster_y_size):             # <<<<<<<<<<<<<<
 *     """Helper function to expand GDAL memory block read bound by 1 pixel.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_1_generate_read_bounds(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing__generate_read_bounds[] = "Helper function to expand GDAL memory block read bound by 1 pixel.\n\n    This function is used in the context of reading a memory block on a GDAL\n    raster plus an additional 1 pixel boundary if it fits into an existing\n    numpy array of size (2+offset_dict['y_size'], 2+offset_dict['x_size']).\n\n    Parameters:\n        offset_dict (dict): dictionary that has values for 'win_xsize',\n            'win_ysize', 'xoff', and 'yoff' to describe the bounding box\n            to read from the raster.\n        raster_x_size, raster_y_size (int): these are the global x/y sizes\n            of the raster that's being read.\n\n    Returns:\n        (xa, xb, ya, yb) (tuple of int): bounds that can be used to slice a\n            numpy array of size\n                (2+offset_dict['y_size'], 2+offset_dict['x_size'])\n        modified_offset_dict (dict): a copy of `offset_dict` with the\n            `win_*size` keys expanded if the modified bounding box will still\n            fit on the array.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_1_generate_read_bounds = {"_generate_read_bounds", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_1_generate_read_bounds, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing__generate_read_bounds};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_1_generate_read_bounds(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_offset_dict = 0;
  PyObject *__pyx_v_raster_x_size = 0;
  PyObject *__pyx_v_raster_y_size = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_generate_read_bounds (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset_dict,&__pyx_n_s_raster_x_size,&__pyx_n_s_raster_y_size,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_offset_dict)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raster_x_size)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_generate_read_bounds", 1, 3, 3, 1); __PYX_ERR(0, 459, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raster_y_size)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_generate_read_bounds", 1, 3, 3, 2); __PYX_ERR(0, 459, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_generate_read_bounds") < 0)) __PYX_ERR(0, 459, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_offset_dict = values[0];
    __pyx_v_raster_x_size = values[1];
    __pyx_v_raster_y_size = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_generate_read_bounds", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 459, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._generate_read_bounds", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing__generate_read_bounds(__pyx_self, __pyx_v_offset_dict, __pyx_v_raster_x_size, __pyx_v_raster_y_size);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing__generate_read_bounds(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_offset_dict, PyObject *__pyx_v_raster_x_size, PyObject *__pyx_v_raster_y_size) {
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_target_offset_dict = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("_generate_read_bounds", 0);

  /* "pygeoprocessing/routing/routing.pyx":481
 *             fit on the array.
 *     """
 *     xa = 1             # <<<<<<<<<<<<<<
 *     xb = -1
 *     ya = 1
 */
  __Pyx_INCREF(__pyx_int_1);
  __pyx_v_xa = __pyx_int_1;

  /* "pygeoprocessing/routing/routing.pyx":482
 *     """
 *     xa = 1
 *     xb = -1             # <<<<<<<<<<<<<<
 *     ya = 1
 *     yb = -1
 */
  __Pyx_INCREF(__pyx_int_neg_1);
  __pyx_v_xb = __pyx_int_neg_1;

  /* "pygeoprocessing/routing/routing.pyx":483
 *     xa = 1
 *     xb = -1
 *     ya = 1             # <<<<<<<<<<<<<<
 *     yb = -1
 *     target_offset_dict = offset_dict.copy()
 */
  __Pyx_INCREF(__pyx_int_1);
  __pyx_v_ya = __pyx_int_1;

  /* "pygeoprocessing/routing/routing.pyx":484
 *     xb = -1
 *     ya = 1
 *     yb = -1             # <<<<<<<<<<<<<<
 *     target_offset_dict = offset_dict.copy()
 *     if offset_dict['xoff'] > 0:
 */
  __Pyx_INCREF(__pyx_int_neg_1);
  __pyx_v_yb = __pyx_int_neg_1;

  /* "pygeoprocessing/routing/routing.pyx":485
 *     ya = 1
 *     yb = -1
 *     target_offset_dict = offset_dict.copy()             # <<<<<<<<<<<<<<
 *     if offset_dict['xoff'] > 0:
 *         xa = None
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_offset_dict, __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 485, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 485, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_target_offset_dict = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":486
 *     yb = -1
 *     target_offset_dict = offset_dict.copy()
 *     if offset_dict['xoff'] > 0:             # <<<<<<<<<<<<<<
 *         xa = None
 *         target_offset_dict['xoff'] -= 1
 */
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 486, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 486, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "pygeoprocessing/routing/routing.pyx":487
 *     target_offset_dict = offset_dict.copy()
 *     if offset_dict['xoff'] > 0:
 *         xa = None             # <<<<<<<<<<<<<<
 *         target_offset_dict['xoff'] -= 1
 *         target_offset_dict['win_xsize'] += 1
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_xa, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":488
 *     if offset_dict['xoff'] > 0:
 *         xa = None
 *         target_offset_dict['xoff'] -= 1             # <<<<<<<<<<<<<<
 *         target_offset_dict['win_xsize'] += 1
 *     if offset_dict['yoff'] > 0:
 */
    __Pyx_INCREF(__pyx_n_s_xoff);
    __pyx_t_5 = __pyx_n_s_xoff;
    __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 488, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_target_offset_dict, __pyx_t_5, __pyx_t_1) < 0)) __PYX_ERR(0, 488, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":489
 *         xa = None
 *         target_offset_dict['xoff'] -= 1
 *         target_offset_dict['win_xsize'] += 1             # <<<<<<<<<<<<<<
 *     if offset_dict['yoff'] > 0:
 *         ya = None
 */
    __Pyx_INCREF(__pyx_n_s_win_xsize);
    __pyx_t_5 = __pyx_n_s_win_xsize;
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 489, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 489, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_target_offset_dict, __pyx_t_5, __pyx_t_2) < 0)) __PYX_ERR(0, 489, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":486
 *     yb = -1
 *     target_offset_dict = offset_dict.copy()
 *     if offset_dict['xoff'] > 0:             # <<<<<<<<<<<<<<
 *         xa = None
 *         target_offset_dict['xoff'] -= 1
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":490
 *         target_offset_dict['xoff'] -= 1
 *         target_offset_dict['win_xsize'] += 1
 *     if offset_dict['yoff'] > 0:             # <<<<<<<<<<<<<<
 *         ya = None
 *         target_offset_dict['yoff'] -= 1
 */
  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "pygeoprocessing/routing/routing.pyx":491
 *         target_offset_dict['win_xsize'] += 1
 *     if offset_dict['yoff'] > 0:
 *         ya = None             # <<<<<<<<<<<<<<
 *         target_offset_dict['yoff'] -= 1
 *         target_offset_dict['win_ysize'] += 1
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_ya, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":492
 *     if offset_dict['yoff'] > 0:
 *         ya = None
 *         target_offset_dict['yoff'] -= 1             # <<<<<<<<<<<<<<
 *         target_offset_dict['win_ysize'] += 1
 *     if (offset_dict['xoff'] + offset_dict['win_xsize'] < raster_x_size):
 */
    __Pyx_INCREF(__pyx_n_s_yoff);
    __pyx_t_5 = __pyx_n_s_yoff;
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 492, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_target_offset_dict, __pyx_t_5, __pyx_t_2) < 0)) __PYX_ERR(0, 492, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":493
 *         ya = None
 *         target_offset_dict['yoff'] -= 1
 *         target_offset_dict['win_ysize'] += 1             # <<<<<<<<<<<<<<
 *     if (offset_dict['xoff'] + offset_dict['win_xsize'] < raster_x_size):
 *         xb = None
 */
    __Pyx_INCREF(__pyx_n_s_win_ysize);
    __pyx_t_5 = __pyx_n_s_win_ysize;
    __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 493, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 493, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_target_offset_dict, __pyx_t_5, __pyx_t_1) < 0)) __PYX_ERR(0, 493, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":490
 *         target_offset_dict['xoff'] -= 1
 *         target_offset_dict['win_xsize'] += 1
 *     if offset_dict['yoff'] > 0:             # <<<<<<<<<<<<<<
 *         ya = None
 *         target_offset_dict['yoff'] -= 1
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":494
 *         target_offset_dict['yoff'] -= 1
 *         target_offset_dict['win_ysize'] += 1
 *     if (offset_dict['xoff'] + offset_dict['win_xsize'] < raster_x_size):             # <<<<<<<<<<<<<<
 *         xb = None
 *         target_offset_dict['win_xsize'] += 1
 */
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_raster_x_size, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "pygeoprocessing/routing/routing.pyx":495
 *         target_offset_dict['win_ysize'] += 1
 *     if (offset_dict['xoff'] + offset_dict['win_xsize'] < raster_x_size):
 *         xb = None             # <<<<<<<<<<<<<<
 *         target_offset_dict['win_xsize'] += 1
 *     if (offset_dict['yoff'] + offset_dict['win_ysize'] < raster_y_size):
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_xb, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":496
 *     if (offset_dict['xoff'] + offset_dict['win_xsize'] < raster_x_size):
 *         xb = None
 *         target_offset_dict['win_xsize'] += 1             # <<<<<<<<<<<<<<
 *     if (offset_dict['yoff'] + offset_dict['win_ysize'] < raster_y_size):
 *         yb = None
 */
    __Pyx_INCREF(__pyx_n_s_win_xsize);
    __pyx_t_5 = __pyx_n_s_win_xsize;
    __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_target_offset_dict, __pyx_t_5, __pyx_t_3) < 0)) __PYX_ERR(0, 496, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":494
 *         target_offset_dict['yoff'] -= 1
 *         target_offset_dict['win_ysize'] += 1
 *     if (offset_dict['xoff'] + offset_dict['win_xsize'] < raster_x_size):             # <<<<<<<<<<<<<<
 *         xb = None
 *         target_offset_dict['win_xsize'] += 1
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":497
 *         xb = None
 *         target_offset_dict['win_xsize'] += 1
 *     if (offset_dict['yoff'] + offset_dict['win_ysize'] < raster_y_size):             # <<<<<<<<<<<<<<
 *         yb = None
 *         target_offset_dict['win_ysize'] += 1
 */
  __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_v_raster_y_size, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 497, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 497, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "pygeoprocessing/routing/routing.pyx":498
 *         target_offset_dict['win_xsize'] += 1
 *     if (offset_dict['yoff'] + offset_dict['win_ysize'] < raster_y_size):
 *         yb = None             # <<<<<<<<<<<<<<
 *         target_offset_dict['win_ysize'] += 1
 *     return (xa, xb, ya, yb), target_offset_dict
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_yb, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":499
 *     if (offset_dict['yoff'] + offset_dict['win_ysize'] < raster_y_size):
 *         yb = None
 *         target_offset_dict['win_ysize'] += 1             # <<<<<<<<<<<<<<
 *     return (xa, xb, ya, yb), target_offset_dict
 * 
 */
    __Pyx_INCREF(__pyx_n_s_win_ysize);
    __pyx_t_5 = __pyx_n_s_win_ysize;
    __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_target_offset_dict, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(__pyx_v_target_offset_dict, __pyx_t_5, __pyx_t_1) < 0)) __PYX_ERR(0, 499, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":497
 *         xb = None
 *         target_offset_dict['win_xsize'] += 1
 *     if (offset_dict['yoff'] + offset_dict['win_ysize'] < raster_y_size):             # <<<<<<<<<<<<<<
 *         yb = None
 *         target_offset_dict['win_ysize'] += 1
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":500
 *         yb = None
 *         target_offset_dict['win_ysize'] += 1
 *     return (xa, xb, ya, yb), target_offset_dict             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 500, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_xa);
  __Pyx_GIVEREF(__pyx_v_xa);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_xa);
  __Pyx_INCREF(__pyx_v_xb);
  __Pyx_GIVEREF(__pyx_v_xb);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_xb);
  __Pyx_INCREF(__pyx_v_ya);
  __Pyx_GIVEREF(__pyx_v_ya);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_ya);
  __Pyx_INCREF(__pyx_v_yb);
  __Pyx_GIVEREF(__pyx_v_yb);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_yb);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_v_target_offset_dict);
  __Pyx_GIVEREF(__pyx_v_target_offset_dict);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_target_offset_dict);
  __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pygeoprocessing/routing/routing.pyx":459
 * 
 * 
 * def _generate_read_bounds(offset_dict, raster_x_size, raster_y_size):             # <<<<<<<<<<<<<<
 *     """Helper function to expand GDAL memory block read bound by 1 pixel.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._generate_read_bounds", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_target_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":503
 * 
 * 
 * def fill_pits(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_filled_dem_raster_path,
 *         working_dir=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_3fill_pits(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_2fill_pits[] = "Fill the pits in a DEM.\n\n        This function defines pits as hydrologically connected regions that do\n        not drain to the edge of the raster or a nodata pixel. After the call\n        pits are filled to the height of the lowest pour point.\n\n    Parameters:\n        dem_raster_path_band (tuple): a path, band number tuple indicating the\n            DEM calculate flow direction.\n        target_filled_dem_raster_path (string): path the pit filled dem,\n            that's created by a call to this function. It is functionally a\n            copy of `dem_raster_path_band[0]` with the pit pixels raised to\n            the pour point. For runtime efficiency, this raster is tiled and\n            its blocksize is set to (1<<BLOCK_BITS, 1<<BLOCK_BITS) even if\n            `dem_raster_path_band[0]` was not tiled or a different block size.\n        working_dir (string): If not None, indicates where temporary files\n            should be created during this run. If this directory doesn't exist\n            it is created by this call. If None, a temporary directory is\n            created by tempdir.mkdtemp which is removed after the function\n            call completes successfully.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_3fill_pits = {"fill_pits", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_3fill_pits, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_2fill_pits};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_3fill_pits(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dem_raster_path_band = 0;
  PyObject *__pyx_v_target_filled_dem_raster_path = 0;
  PyObject *__pyx_v_working_dir = 0;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fill_pits (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dem_raster_path_band,&__pyx_n_s_target_filled_dem_raster_path,&__pyx_n_s_working_dir,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pygeoprocessing/routing/routing.pyx":505
 * def fill_pits(
 *         dem_raster_path_band, target_filled_dem_raster_path,
 *         working_dir=None,             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 *     """Fill the pits in a DEM.
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = __pyx_k__3;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dem_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_filled_dem_raster_path)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("fill_pits", 0, 2, 4, 1); __PYX_ERR(0, 503, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_working_dir);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fill_pits") < 0)) __PYX_ERR(0, 503, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_dem_raster_path_band = values[0];
    __pyx_v_target_filled_dem_raster_path = values[1];
    __pyx_v_working_dir = values[2];
    __pyx_v_gtiff_creation_options = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fill_pits", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 503, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.fill_pits", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_2fill_pits(__pyx_self, __pyx_v_dem_raster_path_band, __pyx_v_target_filled_dem_raster_path, __pyx_v_working_dir, __pyx_v_gtiff_creation_options);

  /* "pygeoprocessing/routing/routing.pyx":503
 * 
 * 
 * def fill_pits(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_filled_dem_raster_path,
 *         working_dir=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_2fill_pits(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_filled_dem_raster_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_gtiff_creation_options) {
  PyArrayObject *__pyx_v_dem_buffer_array = 0;
  int __pyx_v_win_ysize;
  int __pyx_v_win_xsize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_xi_root;
  int __pyx_v_yi_root;
  int __pyx_v_i_n;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_q;
  int __pyx_v_yi_q;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  int __pyx_v_downhill_neighbor;
  int __pyx_v_nodata_neighbor;
  int __pyx_v_downhill_drain;
  int __pyx_v_nodata_drain;
  std::queue<struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType>  __pyx_v_search_queue;
  std::queue<struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType>  __pyx_v_fill_queue;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType __pyx_v_pixel;
  __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType __pyx_v_pit_queue;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  int __pyx_v_n_x_blocks;
  double __pyx_v_center_val;
  double __pyx_v_dem_nodata;
  double __pyx_v_fill_height;
  int __pyx_v_feature_id;
  time_t __pyx_v_last_log_time;
  PyObject *__pyx_v_dem_raster_info = NULL;
  PyObject *__pyx_v_base_nodata = NULL;
  long __pyx_v_mask_nodata;
  PyObject *__pyx_v_working_dir_path = NULL;
  PyObject *__pyx_v_flat_region_mask_path = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flat_region_mask_managed_raster = NULL;
  PyObject *__pyx_v_pit_mask_path = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_pit_mask_managed_raster = NULL;
  PyObject *__pyx_v_geotiff_driver = NULL;
  PyObject *__pyx_v_base_dem_raster = NULL;
  PyObject *__pyx_v_target_dem_raster = NULL;
  PyObject *__pyx_v_target_dem_band = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_filled_dem_managed_raster = NULL;
  PyObject *__pyx_v_offset_dict = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_modified_offset_dict = NULL;
  double __pyx_v_n_height;
  long __pyx_v_pour_point;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_dem_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_dem_buffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  double __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  Py_ssize_t __pyx_t_17;
  PyObject *(*__pyx_t_18)(PyObject *);
  PyArrayObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  long __pyx_t_22;
  long __pyx_t_23;
  long __pyx_t_24;
  long __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  int __pyx_t_28;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_29;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType __pyx_t_30;
  __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType __pyx_t_31;
  __Pyx_RefNannySetupContext("fill_pits", 0);
  __pyx_pybuffer_dem_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_dem_buffer_array.refcount = 0;
  __pyx_pybuffernd_dem_buffer_array.data = NULL;
  __pyx_pybuffernd_dem_buffer_array.rcbuffer = &__pyx_pybuffer_dem_buffer_array;

  /* "pygeoprocessing/routing/routing.pyx":586
 *     # used for time-delayed logging
 *     cdef time_t last_log_time
 *     last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     # determine dem nodata in the working type, or set an improbable value
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":590
 *     # determine dem nodata in the working type, or set an improbable value
 *     # if one can't be determined
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_dem_raster_info = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":591
 *     # if one can't be determined
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *     if base_nodata is not None:
 *         # cast to a float64 since that's our operating array type
 */
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_base_nodata = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":592
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:             # <<<<<<<<<<<<<<
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)
 */
  __pyx_t_6 = (__pyx_v_base_nodata != Py_None);
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {

    /* "pygeoprocessing/routing/routing.pyx":594
 *     if base_nodata is not None:
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)             # <<<<<<<<<<<<<<
 *     else:
 *         # pick some very improbable value since it's hard to deal with NaNs
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 594, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 594, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_base_nodata};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 594, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_base_nodata};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 594, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 594, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL;
        __Pyx_INCREF(__pyx_v_base_nodata);
        __Pyx_GIVEREF(__pyx_v_base_nodata);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_base_nodata);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 594, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 594, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_dem_nodata = __pyx_t_8;

    /* "pygeoprocessing/routing/routing.pyx":592
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:             # <<<<<<<<<<<<<<
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)
 */
    goto __pyx_L3;
  }

  /* "pygeoprocessing/routing/routing.pyx":597
 *     else:
 *         # pick some very improbable value since it's hard to deal with NaNs
 *         dem_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 * 
 *     # these are used to determine if a sample is within the raster
 */
  /*else*/ {
    __pyx_v_dem_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;
  }
  __pyx_L3:;

  /* "pygeoprocessing/routing/routing.pyx":600
 * 
 *     # these are used to determine if a sample is within the raster
 *     raster_x_size, raster_y_size = dem_raster_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     # this is the nodata value for all the flat region and pit masks
 */
  __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 600, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_2);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 600, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 600, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 600, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_5), 2) < 0) __PYX_ERR(0, 600, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 600, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 600, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 600, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_raster_x_size = __pyx_t_10;
  __pyx_v_raster_y_size = __pyx_t_11;

  /* "pygeoprocessing/routing/routing.pyx":603
 * 
 *     # this is the nodata value for all the flat region and pit masks
 *     mask_nodata = 0             # <<<<<<<<<<<<<<
 * 
 *     # set up the working dir for the mask rasters
 */
  __pyx_v_mask_nodata = 0;

  /* "pygeoprocessing/routing/routing.pyx":606
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
    __Pyx_XGOTREF(__pyx_t_12);
    __Pyx_XGOTREF(__pyx_t_13);
    __Pyx_XGOTREF(__pyx_t_14);
    /*try:*/ {

      /* "pygeoprocessing/routing/routing.pyx":607
 *     # set up the working dir for the mask rasters
 *     try:
 *         if working_dir is not None:             # <<<<<<<<<<<<<<
 *             os.makedirs(working_dir)
 *     except OSError:
 */
      __pyx_t_7 = (__pyx_v_working_dir != Py_None);
      __pyx_t_6 = (__pyx_t_7 != 0);
      if (__pyx_t_6) {

        /* "pygeoprocessing/routing/routing.pyx":608
 *     try:
 *         if working_dir is not None:
 *             os.makedirs(working_dir)             # <<<<<<<<<<<<<<
 *     except OSError:
 *         pass
 */
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 608, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 608, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
          }
        }
        if (!__pyx_t_2) {
          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 608, __pyx_L6_error)
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_working_dir};
            __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 608, __pyx_L6_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_3);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_working_dir};
            __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 608, __pyx_L6_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_3);
          } else
          #endif
          {
            __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 608, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
            __Pyx_INCREF(__pyx_v_working_dir);
            __Pyx_GIVEREF(__pyx_v_working_dir);
            PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_working_dir);
            __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 608, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pygeoprocessing/routing/routing.pyx":607
 *     # set up the working dir for the mask rasters
 *     try:
 *         if working_dir is not None:             # <<<<<<<<<<<<<<
 *             os.makedirs(working_dir)
 *     except OSError:
 */
      }

      /* "pygeoprocessing/routing/routing.pyx":606
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
    }
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    goto __pyx_L11_try_end;
    __pyx_L6_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":609
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 *     except OSError:             # <<<<<<<<<<<<<<
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 */
    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError);
    if (__pyx_t_11) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L7_exception_handled;
    }
    goto __pyx_L8_except_error;
    __pyx_L8_except_error:;

    /* "pygeoprocessing/routing/routing.pyx":606
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_13);
    __Pyx_XGIVEREF(__pyx_t_14);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
    goto __pyx_L1_error;
    __pyx_L7_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_13);
    __Pyx_XGIVEREF(__pyx_t_14);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
    __pyx_L11_try_end:;
  }

  /* "pygeoprocessing/routing/routing.pyx":611
 *     except OSError:
 *         pass
 *     working_dir_path = tempfile.mkdtemp(             # <<<<<<<<<<<<<<
 *         dir=working_dir, prefix='fill_pits_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":612
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir, prefix='fill_pits_%s_' % time.strftime(             # <<<<<<<<<<<<<<
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 * 
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dir, __pyx_v_working_dir) < 0) __PYX_ERR(0, 612, __pyx_L1_error)
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_strftime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":613
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir, prefix='fill_pits_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))             # <<<<<<<<<<<<<<
 * 
 *     # this raster is used to keep track of what pixels have been searched for
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_gmtime); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_16);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_16, function);
    }
  }
  if (__pyx_t_15) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 613, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 613, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_s_Y_m_d__H__M__S, __pyx_t_2};
    __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 612, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_s_Y_m_d__H__M__S, __pyx_t_2};
    __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 612, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_15 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 612, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (__pyx_t_16) {
      __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_16); __pyx_t_16 = NULL;
    }
    __Pyx_INCREF(__pyx_kp_s_Y_m_d__H__M__S);
    __Pyx_GIVEREF(__pyx_kp_s_Y_m_d__H__M__S);
    PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, __pyx_kp_s_Y_m_d__H__M__S);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_15, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 612, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":612
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir, prefix='fill_pits_%s_' % time.strftime(             # <<<<<<<<<<<<<<
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 * 
 */
  __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_fill_pits__s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_4) < 0) __PYX_ERR(0, 612, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":611
 *     except OSError:
 *         pass
 *     working_dir_path = tempfile.mkdtemp(             # <<<<<<<<<<<<<<
 *         dir=working_dir, prefix='fill_pits_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_working_dir_path = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":618
 *     # a plateau or pit. if a pixel is set, it means it is part of a locally
 *     # undrained area
 *     flat_region_mask_path = os.path.join(             # <<<<<<<<<<<<<<
 *         working_dir_path, 'flat_region_mask.tif')
 *     n_x_blocks = raster_x_size >> BLOCK_BITS + 1
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":619
 *     # undrained area
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')             # <<<<<<<<<<<<<<
 *     n_x_blocks = raster_x_size >> BLOCK_BITS + 1
 * 
 */
  __pyx_t_1 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_flat_region_mask_tif};
    __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_flat_region_mask_tif};
    __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 618, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(__pyx_v_working_dir_path);
    __Pyx_GIVEREF(__pyx_v_working_dir_path);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_v_working_dir_path);
    __Pyx_INCREF(__pyx_kp_s_flat_region_mask_tif);
    __Pyx_GIVEREF(__pyx_kp_s_flat_region_mask_tif);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_kp_s_flat_region_mask_tif);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_flat_region_mask_path = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":620
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')
 *     n_x_blocks = raster_x_size >> BLOCK_BITS + 1             # <<<<<<<<<<<<<<
 * 
 *     pygeoprocessing.new_raster_from_base(
 */
  __pyx_v_n_x_blocks = (__pyx_v_raster_x_size >> (__pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS + 1));

  /* "pygeoprocessing/routing/routing.pyx":622
 *     n_x_blocks = raster_x_size >> BLOCK_BITS + 1
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":623
 * 
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,             # <<<<<<<<<<<<<<
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":624
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":622
 *     n_x_blocks = raster_x_size >> BLOCK_BITS + 1
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __Pyx_INCREF(__pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_v_flat_region_mask_path);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_15);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":624
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_15 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_fill_value_list, __pyx_t_4) < 0) __PYX_ERR(0, 624, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":625
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     flat_region_mask_managed_raster = _ManagedRaster(
 *         flat_region_mask_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 624, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":622
 *     n_x_blocks = raster_x_size >> BLOCK_BITS + 1
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":626
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flat_region_mask_path, 1, 1)
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 626, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_v_flat_region_mask_path);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_flat_region_mask_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_1);
  __pyx_t_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_4, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 626, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_flat_region_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":632
 *     # been searched as part of the search for a pour point for pit number
 *     # `feature_id`
 *     pit_mask_path = os.path.join(working_dir_path, 'pit_mask.tif')             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 632, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 632, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_join); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 632, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_working_dir_path, __pyx_kp_s_pit_mask_tif};
    __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 632, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_15);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_working_dir_path, __pyx_kp_s_pit_mask_tif};
    __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 632, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_15);
  } else
  #endif
  {
    __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 632, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(__pyx_v_working_dir_path);
    __Pyx_GIVEREF(__pyx_v_working_dir_path);
    PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_v_working_dir_path);
    __Pyx_INCREF(__pyx_kp_s_pit_mask_tif);
    __Pyx_GIVEREF(__pyx_kp_s_pit_mask_tif);
    PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_kp_s_pit_mask_tif);
    __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 632, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_pit_mask_path = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":633
 *     # `feature_id`
 *     pit_mask_path = os.path.join(working_dir_path, 'pit_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":634
 *     pit_mask_path = os.path.join(working_dir_path, 'pit_mask.tif')
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,             # <<<<<<<<<<<<<<
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 634, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 634, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 634, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":635
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     pit_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":633
 *     # `feature_id`
 *     pit_mask_path = os.path.join(working_dir_path, 'pit_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_15);
  __Pyx_INCREF(__pyx_v_pit_mask_path);
  __Pyx_GIVEREF(__pyx_v_pit_mask_path);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_pit_mask_path);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_1);
  __pyx_t_15 = 0;
  __pyx_t_5 = 0;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":635
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     pit_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_fill_value_list, __pyx_t_15) < 0) __PYX_ERR(0, 635, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":636
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     pit_mask_managed_raster = _ManagedRaster(
 *         pit_mask_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 635, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":633
 *     # `feature_id`
 *     pit_mask_path = os.path.join(working_dir_path, 'pit_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], pit_mask_path, gdal.GDT_Int32,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":637
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     pit_mask_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         pit_mask_path, 1, 1)
 * 
 */
  __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_INCREF(__pyx_v_pit_mask_path);
  __Pyx_GIVEREF(__pyx_v_pit_mask_path);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_pit_mask_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_int_1);
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_v_pit_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":641
 * 
 *     # copy the base DEM to the target and set up for writing
 *     geotiff_driver = gdal.GetDriverByName('GTiff')             # <<<<<<<<<<<<<<
 *     base_dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *     geotiff_driver.CreateCopy(
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 641, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 641, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 641, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_v_geotiff_driver = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":642
 *     # copy the base DEM to the target and set up for writing
 *     geotiff_driver = gdal.GetDriverByName('GTiff')
 *     base_dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     geotiff_driver.CreateCopy(
 *         target_filled_dem_raster_path, base_dem_raster,
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_15, __pyx_t_5};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_15, __pyx_t_5};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_2 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_4) {
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __pyx_t_4 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_5);
    __pyx_t_15 = 0;
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_base_dem_raster = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":643
 *     geotiff_driver = gdal.GetDriverByName('GTiff')
 *     base_dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *     geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *         target_filled_dem_raster_path, base_dem_raster,
 *         options=gtiff_creation_options)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_geotiff_driver, __pyx_n_s_CreateCopy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":644
 *     base_dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *     geotiff_driver.CreateCopy(
 *         target_filled_dem_raster_path, base_dem_raster,             # <<<<<<<<<<<<<<
 *         options=gtiff_creation_options)
 *     target_dem_raster = gdal.OpenEx(
 */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_target_filled_dem_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_filled_dem_raster_path);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_filled_dem_raster_path);
  __Pyx_INCREF(__pyx_v_base_dem_raster);
  __Pyx_GIVEREF(__pyx_v_base_dem_raster);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_base_dem_raster);

  /* "pygeoprocessing/routing/routing.pyx":645
 *     geotiff_driver.CreateCopy(
 *         target_filled_dem_raster_path, base_dem_raster,
 *         options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     target_dem_raster = gdal.OpenEx(
 *         target_filled_dem_raster_path, gdal.OF_RASTER)
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 645, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":643
 *     geotiff_driver = gdal.GetDriverByName('GTiff')
 *     base_dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *     geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *         target_filled_dem_raster_path, base_dem_raster,
 *         options=gtiff_creation_options)
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":646
 *         target_filled_dem_raster_path, base_dem_raster,
 *         options=gtiff_creation_options)
 *     target_dem_raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *         target_filled_dem_raster_path, gdal.OF_RASTER)
 *     target_dem_band = target_dem_raster.GetRasterBand(dem_raster_path_band[1])
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":647
 *         options=gtiff_creation_options)
 *     target_dem_raster = gdal.OpenEx(
 *         target_filled_dem_raster_path, gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     target_dem_band = target_dem_raster.GetRasterBand(dem_raster_path_band[1])
 *     filled_dem_managed_raster = _ManagedRaster(
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_target_filled_dem_raster_path, __pyx_t_1};
    __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 646, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_target_filled_dem_raster_path, __pyx_t_1};
    __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 646, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_15 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 646, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_INCREF(__pyx_v_target_filled_dem_raster_path);
    __Pyx_GIVEREF(__pyx_v_target_filled_dem_raster_path);
    PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, __pyx_v_target_filled_dem_raster_path);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 646, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_target_dem_raster = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":648
 *     target_dem_raster = gdal.OpenEx(
 *         target_filled_dem_raster_path, gdal.OF_RASTER)
 *     target_dem_band = target_dem_raster.GetRasterBand(dem_raster_path_band[1])             # <<<<<<<<<<<<<<
 *     filled_dem_managed_raster = _ManagedRaster(
 *         target_filled_dem_raster_path, dem_raster_path_band[1], 1)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 648, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_15};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 648, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_15};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 648, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 648, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_15);
      __pyx_t_15 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 648, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_target_dem_band = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":650
 *     target_dem_band = target_dem_raster.GetRasterBand(dem_raster_path_band[1])
 *     filled_dem_managed_raster = _ManagedRaster(
 *         target_filled_dem_raster_path, dem_raster_path_band[1], 1)             # <<<<<<<<<<<<<<
 * 
 *     # feature_id will start at 1 since the mask nodata is 0.
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 650, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":649
 *         target_filled_dem_raster_path, gdal.OF_RASTER)
 *     target_dem_band = target_dem_raster.GetRasterBand(dem_raster_path_band[1])
 *     filled_dem_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         target_filled_dem_raster_path, dem_raster_path_band[1], 1)
 * 
 */
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_target_filled_dem_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_filled_dem_raster_path);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_target_filled_dem_raster_path);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_1);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_filled_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":653
 * 
 *     # feature_id will start at 1 since the mask nodata is 0.
 *     feature_id = 0             # <<<<<<<<<<<<<<
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 */
  __pyx_v_feature_id = 0;

  /* "pygeoprocessing/routing/routing.pyx":656
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":657
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):             # <<<<<<<<<<<<<<
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":656
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":657
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):             # <<<<<<<<<<<<<<
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 657, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 657, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":656
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (likely(PyList_CheckExact(__pyx_t_15)) || PyTuple_CheckExact(__pyx_t_15)) {
    __pyx_t_5 = __pyx_t_15; __Pyx_INCREF(__pyx_t_5); __pyx_t_17 = 0;
    __pyx_t_18 = NULL;
  } else {
    __pyx_t_17 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 656, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_18 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 656, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  for (;;) {
    if (likely(!__pyx_t_18)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_15 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_17); __Pyx_INCREF(__pyx_t_15); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 656, __pyx_L1_error)
        #else
        __pyx_t_15 = PySequence_ITEM(__pyx_t_5, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        #endif
      } else {
        if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_17); __Pyx_INCREF(__pyx_t_15); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 656, __pyx_L1_error)
        #else
        __pyx_t_15 = PySequence_ITEM(__pyx_t_5, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 656, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        #endif
      }
    } else {
      __pyx_t_15 = __pyx_t_18(__pyx_t_5);
      if (unlikely(!__pyx_t_15)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 656, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_15);
    }
    __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_15);
    __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":658
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 */
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_v_win_xsize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":659
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']             # <<<<<<<<<<<<<<
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']
 */
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 659, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 659, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_v_win_ysize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":660
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']             # <<<<<<<<<<<<<<
 *         yoff = offset_dict['yoff']
 * 
 */
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 660, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 660, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_v_xoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":661
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']             # <<<<<<<<<<<<<<
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 661, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 661, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_v_yoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":663
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    __pyx_t_6 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
    if (__pyx_t_6) {

      /* "pygeoprocessing/routing/routing.pyx":664
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
      __pyx_v_last_log_time = time(NULL);

      /* "pygeoprocessing/routing/routing.pyx":665
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))
 */
      __pyx_t_15 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 665, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_15);
      __pyx_t_15 = 0;

      /* "pygeoprocessing/routing/routing.pyx":666
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 666, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 666, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 666, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);

      /* "pygeoprocessing/routing/routing.pyx":667
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 */
      __pyx_t_1 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "pygeoprocessing/routing/routing.pyx":666
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 666, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_11 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_kp_s_1f_complete, __pyx_t_4};
        __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 666, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_kp_s_1f_complete, __pyx_t_4};
        __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 666, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 666, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 666, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

      /* "pygeoprocessing/routing/routing.pyx":663
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":670
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 670, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 670, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":671
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata
 */
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 671, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_15, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 671, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 671, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_15, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 671, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 671, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":670
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 670, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15);
    __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":672
 *         dem_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)             # <<<<<<<<<<<<<<
 *         dem_buffer_array[:] = dem_nodata
 * 
 */
    __pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":670
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 670, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 670, __pyx_L1_error)
    __pyx_t_19 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
      __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_11 < 0)) {
        PyErr_Fetch(&__pyx_t_14, &__pyx_t_13, &__pyx_t_12);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dem_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_14, __pyx_t_13, __pyx_t_12);
        }
        __pyx_t_14 = __pyx_t_13 = __pyx_t_12 = 0;
      }
      __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 670, __pyx_L1_error)
    }
    __pyx_t_19 = 0;
    __Pyx_XDECREF_SET(__pyx_v_dem_buffer_array, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":673
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata             # <<<<<<<<<<<<<<
 * 
 *         # attempt to expand read block by a pixel boundary
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_dem_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 673, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_slice__5, __pyx_t_1) < 0)) __PYX_ERR(0, 673, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":676
 * 
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(
 */
    __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 676, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);

    /* "pygeoprocessing/routing/routing.pyx":677
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)             # <<<<<<<<<<<<<<
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)
 */
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 677, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 677, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_15)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_4, __pyx_t_3};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_4, __pyx_t_3};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    {
      __pyx_t_16 = PyTuple_New(3+__pyx_t_11); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_v_offset_dict);
      PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_11, __pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_11, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_16, 2+__pyx_t_11, __pyx_t_3);
      __pyx_t_4 = 0;
      __pyx_t_3 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
      PyObject* sequence = __pyx_t_1;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 676, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_15 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_16 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_16);
      #else
      __pyx_t_15 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext;
      index = 0; __pyx_t_15 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_15)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_15);
      index = 1; __pyx_t_16 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_16)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_16);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_3), 2) < 0) __PYX_ERR(0, 676, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L17_unpacking_done;
      __pyx_L16_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 676, __pyx_L1_error)
      __pyx_L17_unpacking_done:;
    }

    /* "pygeoprocessing/routing/routing.pyx":676
 * 
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(
 */
    if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) {
      PyObject* sequence = __pyx_t_15;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 676, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_20 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_20 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_20);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_3,&__pyx_t_4,&__pyx_t_2,&__pyx_t_20};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 676, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_3,&__pyx_t_4,&__pyx_t_2,&__pyx_t_20};
      __pyx_t_21 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 676, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_21);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_21)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_9(__pyx_t_21); if (unlikely(!item)) goto __pyx_L18_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_21), 4) < 0) __PYX_ERR(0, 676, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      goto __pyx_L19_unpacking_done;
      __pyx_L18_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 676, __pyx_L1_error)
      __pyx_L19_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_20);
    __pyx_t_20 = 0;
    __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_16);
    __pyx_t_16 = 0;

    /* "pygeoprocessing/routing/routing.pyx":678
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_target_dem_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);

    /* "pygeoprocessing/routing/routing.pyx":679
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)             # <<<<<<<<<<<<<<
 * 
 *         # search block for locally undrained pixels
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 679, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_15 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 679, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
    } else {
      __pyx_t_15 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 678, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
    }

    /* "pygeoprocessing/routing/routing.pyx":678
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_empty_tuple, __pyx_t_15); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":679
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)             # <<<<<<<<<<<<<<
 * 
 *         # search block for locally undrained pixels
 */
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_astype); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 679, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 679, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 679, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_20)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_20);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
      }
    }
    if (!__pyx_t_20) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_15)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_16};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_16};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 679, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_20); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_20); __pyx_t_20 = NULL;
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_16);
        __pyx_t_16 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":678
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = target_dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_15 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_2 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_2);
    __pyx_t_15 = 0;
    __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_t_16, __pyx_t_1) < 0)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":682
 * 
 *         # search block for locally undrained pixels
 *         for yi in range(1, win_ysize+1):             # <<<<<<<<<<<<<<
 *             for xi in range(1, win_xsize+1):
 *                 center_val = dem_buffer_array[yi, xi]
 */
    __pyx_t_22 = (__pyx_v_win_ysize + 1);
    __pyx_t_23 = __pyx_t_22;
    for (__pyx_t_11 = 1; __pyx_t_11 < __pyx_t_23; __pyx_t_11+=1) {
      __pyx_v_yi = __pyx_t_11;

      /* "pygeoprocessing/routing/routing.pyx":683
 *         # search block for locally undrained pixels
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):             # <<<<<<<<<<<<<<
 *                 center_val = dem_buffer_array[yi, xi]
 *                 if is_close(center_val, dem_nodata):
 */
      __pyx_t_24 = (__pyx_v_win_xsize + 1);
      __pyx_t_25 = __pyx_t_24;
      for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_25; __pyx_t_10+=1) {
        __pyx_v_xi = __pyx_t_10;

        /* "pygeoprocessing/routing/routing.pyx":684
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 center_val = dem_buffer_array[yi, xi]             # <<<<<<<<<<<<<<
 *                 if is_close(center_val, dem_nodata):
 *                     continue
 */
        __pyx_t_26 = __pyx_v_yi;
        __pyx_t_27 = __pyx_v_xi;
        __pyx_t_28 = -1;
        if (__pyx_t_26 < 0) {
          __pyx_t_26 += __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_26 < 0)) __pyx_t_28 = 0;
        } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_28 = 0;
        if (__pyx_t_27 < 0) {
          __pyx_t_27 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_27 < 0)) __pyx_t_28 = 1;
        } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_28 = 1;
        if (unlikely(__pyx_t_28 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_28);
          __PYX_ERR(0, 684, __pyx_L1_error)
        }
        __pyx_v_center_val = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides));

        /* "pygeoprocessing/routing/routing.pyx":685
 *             for xi in range(1, win_xsize+1):
 *                 center_val = dem_buffer_array[yi, xi]
 *                 if is_close(center_val, dem_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_center_val, __pyx_v_dem_nodata) != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":686
 *                 center_val = dem_buffer_array[yi, xi]
 *                 if is_close(center_val, dem_nodata):
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # this value is set in case it turns out to be the root of a
 */
          goto __pyx_L22_continue;

          /* "pygeoprocessing/routing/routing.pyx":685
 *             for xi in range(1, win_xsize+1):
 *                 center_val = dem_buffer_array[yi, xi]
 *                 if is_close(center_val, dem_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":691
 *                 # pit, we'll start the fill from this pixel in the last phase
 *                 # of the algorithm
 *                 xi_root = xi-1+xoff             # <<<<<<<<<<<<<<
 *                 yi_root = yi-1+yoff
 * 
 */
        __pyx_v_xi_root = ((__pyx_v_xi - 1) + __pyx_v_xoff);

        /* "pygeoprocessing/routing/routing.pyx":692
 *                 # of the algorithm
 *                 xi_root = xi-1+xoff
 *                 yi_root = yi-1+yoff             # <<<<<<<<<<<<<<
 * 
 *                 if flat_region_mask_managed_raster.get(
 */
        __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff);

        /* "pygeoprocessing/routing/routing.pyx":695
 * 
 *                 if flat_region_mask_managed_raster.get(
 *                         xi_root, yi_root) != mask_nodata:             # <<<<<<<<<<<<<<
 *                     # already been searched
 *                     continue
 */
        __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root) != __pyx_v_mask_nodata) != 0);

        /* "pygeoprocessing/routing/routing.pyx":694
 *                 yi_root = yi-1+yoff
 * 
 *                 if flat_region_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root) != mask_nodata:
 *                     # already been searched
 */
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":697
 *                         xi_root, yi_root) != mask_nodata:
 *                     # already been searched
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # search neighbors for downhill or nodata
 */
          goto __pyx_L22_continue;

          /* "pygeoprocessing/routing/routing.pyx":694
 *                 yi_root = yi-1+yoff
 * 
 *                 if flat_region_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root) != mask_nodata:
 *                     # already been searched
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":700
 * 
 *                 # search neighbors for downhill or nodata
 *                 downhill_neighbor = 0             # <<<<<<<<<<<<<<
 *                 nodata_neighbor = 0
 * 
 */
        __pyx_v_downhill_neighbor = 0;

        /* "pygeoprocessing/routing/routing.pyx":701
 *                 # search neighbors for downhill or nodata
 *                 downhill_neighbor = 0
 *                 nodata_neighbor = 0             # <<<<<<<<<<<<<<
 * 
 *                 for i_n in range(8):
 */
        __pyx_v_nodata_neighbor = 0;

        /* "pygeoprocessing/routing/routing.pyx":703
 *                 nodata_neighbor = 0
 * 
 *                 for i_n in range(8):             # <<<<<<<<<<<<<<
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
        for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
          __pyx_v_i_n = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":704
 * 
 *                 for i_n in range(8):
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or
 */
          __pyx_v_xi_n = (__pyx_v_xi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

          /* "pygeoprocessing/routing/routing.pyx":705
 *                 for i_n in range(8):
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                     if (xi_n < 0 or xi_n >= raster_x_size or
 *                             yi_n < 0 or yi_n >= raster_y_size):
 */
          __pyx_v_yi_n = (__pyx_v_yi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

          /* "pygeoprocessing/routing/routing.pyx":706
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 */
          __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
          if (!__pyx_t_7) {
          } else {
            __pyx_t_6 = __pyx_t_7;
            goto __pyx_L29_bool_binop_done;
          }
          __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
          if (!__pyx_t_7) {
          } else {
            __pyx_t_6 = __pyx_t_7;
            goto __pyx_L29_bool_binop_done;
          }

          /* "pygeoprocessing/routing/routing.pyx":707
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or
 *                             yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                         # it'll drain off the edge of the raster
 *                         nodata_neighbor = 1
 */
          __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
          if (!__pyx_t_7) {
          } else {
            __pyx_t_6 = __pyx_t_7;
            goto __pyx_L29_bool_binop_done;
          }
          __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
          __pyx_t_6 = __pyx_t_7;
          __pyx_L29_bool_binop_done:;

          /* "pygeoprocessing/routing/routing.pyx":706
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 */
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":709
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 *                         nodata_neighbor = 1             # <<<<<<<<<<<<<<
 *                         break
 *                     n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 */
            __pyx_v_nodata_neighbor = 1;

            /* "pygeoprocessing/routing/routing.pyx":710
 *                         # it'll drain off the edge of the raster
 *                         nodata_neighbor = 1
 *                         break             # <<<<<<<<<<<<<<
 *                     n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 *                     if is_close(n_height, dem_nodata):
 */
            goto __pyx_L27_break;

            /* "pygeoprocessing/routing/routing.pyx":706
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":711
 *                         nodata_neighbor = 1
 *                         break
 *                     n_height = filled_dem_managed_raster.get(xi_n, yi_n)             # <<<<<<<<<<<<<<
 *                     if is_close(n_height, dem_nodata):
 *                         # it'll drain to nodata
 */
          __pyx_v_n_height = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);

          /* "pygeoprocessing/routing/routing.pyx":712
 *                         break
 *                     n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 *                     if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                         # it'll drain to nodata
 *                         nodata_neighbor = 1
 */
          __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_dem_nodata) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":714
 *                     if is_close(n_height, dem_nodata):
 *                         # it'll drain to nodata
 *                         nodata_neighbor = 1             # <<<<<<<<<<<<<<
 *                         break
 *                     if n_height < center_val:
 */
            __pyx_v_nodata_neighbor = 1;

            /* "pygeoprocessing/routing/routing.pyx":715
 *                         # it'll drain to nodata
 *                         nodata_neighbor = 1
 *                         break             # <<<<<<<<<<<<<<
 *                     if n_height < center_val:
 *                         # it'll drain downhill
 */
            goto __pyx_L27_break;

            /* "pygeoprocessing/routing/routing.pyx":712
 *                         break
 *                     n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 *                     if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                         # it'll drain to nodata
 *                         nodata_neighbor = 1
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":716
 *                         nodata_neighbor = 1
 *                         break
 *                     if n_height < center_val:             # <<<<<<<<<<<<<<
 *                         # it'll drain downhill
 *                         downhill_neighbor = 1
 */
          __pyx_t_6 = ((__pyx_v_n_height < __pyx_v_center_val) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":718
 *                     if n_height < center_val:
 *                         # it'll drain downhill
 *                         downhill_neighbor = 1             # <<<<<<<<<<<<<<
 *                         break
 * 
 */
            __pyx_v_downhill_neighbor = 1;

            /* "pygeoprocessing/routing/routing.pyx":719
 *                         # it'll drain downhill
 *                         downhill_neighbor = 1
 *                         break             # <<<<<<<<<<<<<<
 * 
 *                 if downhill_neighbor or nodata_neighbor:
 */
            goto __pyx_L27_break;

            /* "pygeoprocessing/routing/routing.pyx":716
 *                         nodata_neighbor = 1
 *                         break
 *                     if n_height < center_val:             # <<<<<<<<<<<<<<
 *                         # it'll drain downhill
 *                         downhill_neighbor = 1
 */
          }
        }
        __pyx_L27_break:;

        /* "pygeoprocessing/routing/routing.pyx":721
 *                         break
 * 
 *                 if downhill_neighbor or nodata_neighbor:             # <<<<<<<<<<<<<<
 *                     # it drains, so skip
 *                     continue
 */
        __pyx_t_7 = (__pyx_v_downhill_neighbor != 0);
        if (!__pyx_t_7) {
        } else {
          __pyx_t_6 = __pyx_t_7;
          goto __pyx_L36_bool_binop_done;
        }
        __pyx_t_7 = (__pyx_v_nodata_neighbor != 0);
        __pyx_t_6 = __pyx_t_7;
        __pyx_L36_bool_binop_done:;
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":723
 *                 if downhill_neighbor or nodata_neighbor:
 *                     # it drains, so skip
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # otherwise, this pixel doesn't drain locally, search to see
 */
          goto __pyx_L22_continue;

          /* "pygeoprocessing/routing/routing.pyx":721
 *                         break
 * 
 *                 if downhill_neighbor or nodata_neighbor:             # <<<<<<<<<<<<<<
 *                     # it drains, so skip
 *                     continue
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":727
 *                 # otherwise, this pixel doesn't drain locally, search to see
 *                 # if it's a pit or plateau
 *                 search_queue.push(CoordinateType(xi_root, yi_root))             # <<<<<<<<<<<<<<
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)
 *                 downhill_drain = 0
 */
        __pyx_t_29.xi = __pyx_v_xi_root;
        __pyx_t_29.yi = __pyx_v_yi_root;
        __pyx_v_search_queue.push(__pyx_t_29);

        /* "pygeoprocessing/routing/routing.pyx":728
 *                 # if it's a pit or plateau
 *                 search_queue.push(CoordinateType(xi_root, yi_root))
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)             # <<<<<<<<<<<<<<
 *                 downhill_drain = 0
 *                 nodata_drain = 0
 */
        __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 1.0);

        /* "pygeoprocessing/routing/routing.pyx":729
 *                 search_queue.push(CoordinateType(xi_root, yi_root))
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)
 *                 downhill_drain = 0             # <<<<<<<<<<<<<<
 *                 nodata_drain = 0
 * 
 */
        __pyx_v_downhill_drain = 0;

        /* "pygeoprocessing/routing/routing.pyx":730
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)
 *                 downhill_drain = 0
 *                 nodata_drain = 0             # <<<<<<<<<<<<<<
 * 
 *                 # this loop does a BFS starting at this pixel to all pixels
 */
        __pyx_v_nodata_drain = 0;

        /* "pygeoprocessing/routing/routing.pyx":738
 *                 # it can be entirely marked as processed and not re-accessed
 *                 # on later iterations
 *                 while not search_queue.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = search_queue.front().xi
 *                     yi_q = search_queue.front().yi
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_search_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":739
 *                 # on later iterations
 *                 while not search_queue.empty():
 *                     xi_q = search_queue.front().xi             # <<<<<<<<<<<<<<
 *                     yi_q = search_queue.front().yi
 *                     search_queue.pop()
 */
          __pyx_t_28 = __pyx_v_search_queue.front().xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":740
 *                 while not search_queue.empty():
 *                     xi_q = search_queue.front().xi
 *                     yi_q = search_queue.front().yi             # <<<<<<<<<<<<<<
 *                     search_queue.pop()
 * 
 */
          __pyx_t_28 = __pyx_v_search_queue.front().yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":741
 *                     xi_q = search_queue.front().xi
 *                     yi_q = search_queue.front().yi
 *                     search_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                     for i_n in range(8):
 */
          __pyx_v_search_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":743
 *                     search_queue.pop()
 * 
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":744
 * 
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":745
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":746
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             nodata_drain = 1
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L43_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L43_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":747
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             nodata_drain = 1
 *                             continue
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L43_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L43_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":746
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             nodata_drain = 1
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":748
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             nodata_drain = 1             # <<<<<<<<<<<<<<
 *                             continue
 *                         n_height = filled_dem_managed_raster.get(
 */
              __pyx_v_nodata_drain = 1;

              /* "pygeoprocessing/routing/routing.pyx":749
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             nodata_drain = 1
 *                             continue             # <<<<<<<<<<<<<<
 *                         n_height = filled_dem_managed_raster.get(
 *                             xi_n, yi_n)
 */
              goto __pyx_L40_continue;

              /* "pygeoprocessing/routing/routing.pyx":746
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             nodata_drain = 1
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":750
 *                             nodata_drain = 1
 *                             continue
 *                         n_height = filled_dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                             xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):
 */
            __pyx_v_n_height = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);

            /* "pygeoprocessing/routing/routing.pyx":752
 *                         n_height = filled_dem_managed_raster.get(
 *                             xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                             nodata_drain = 1
 *                             continue
 */
            __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_dem_nodata) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":753
 *                             xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):
 *                             nodata_drain = 1             # <<<<<<<<<<<<<<
 *                             continue
 *                         if n_height < center_val:
 */
              __pyx_v_nodata_drain = 1;

              /* "pygeoprocessing/routing/routing.pyx":754
 *                         if is_close(n_height, dem_nodata):
 *                             nodata_drain = 1
 *                             continue             # <<<<<<<<<<<<<<
 *                         if n_height < center_val:
 *                             downhill_drain = 1
 */
              goto __pyx_L40_continue;

              /* "pygeoprocessing/routing/routing.pyx":752
 *                         n_height = filled_dem_managed_raster.get(
 *                             xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                             nodata_drain = 1
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":755
 *                             nodata_drain = 1
 *                             continue
 *                         if n_height < center_val:             # <<<<<<<<<<<<<<
 *                             downhill_drain = 1
 *                             continue
 */
            __pyx_t_6 = ((__pyx_v_n_height < __pyx_v_center_val) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":756
 *                             continue
 *                         if n_height < center_val:
 *                             downhill_drain = 1             # <<<<<<<<<<<<<<
 *                             continue
 *                         if is_close(n_height, center_val) and (
 */
              __pyx_v_downhill_drain = 1;

              /* "pygeoprocessing/routing/routing.pyx":757
 *                         if n_height < center_val:
 *                             downhill_drain = 1
 *                             continue             # <<<<<<<<<<<<<<
 *                         if is_close(n_height, center_val) and (
 *                                 flat_region_mask_managed_raster.get(
 */
              goto __pyx_L40_continue;

              /* "pygeoprocessing/routing/routing.pyx":755
 *                             nodata_drain = 1
 *                             continue
 *                         if n_height < center_val:             # <<<<<<<<<<<<<<
 *                             downhill_drain = 1
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":758
 *                             downhill_drain = 1
 *                             continue
 *                         if is_close(n_height, center_val) and (             # <<<<<<<<<<<<<<
 *                                 flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata):
 */
            __pyx_t_7 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_center_val) != 0);
            if (__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L50_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":760
 *                         if is_close(n_height, center_val) and (
 *                                 flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata):             # <<<<<<<<<<<<<<
 *                             # only grow if it's at the same level and not
 *                             # previously visited
 */
            __pyx_t_7 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == __pyx_v_mask_nodata) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L50_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":758
 *                             downhill_drain = 1
 *                             continue
 *                         if is_close(n_height, center_val) and (             # <<<<<<<<<<<<<<
 *                                 flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata):
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":764
 *                             # previously visited
 *                             search_queue.push(
 *                                 CoordinateType(xi_n, yi_n))             # <<<<<<<<<<<<<<
 *                             flat_region_mask_managed_raster.set(
 *                                 xi_n, yi_n, 1)
 */
              __pyx_t_29.xi = __pyx_v_xi_n;
              __pyx_t_29.yi = __pyx_v_yi_n;

              /* "pygeoprocessing/routing/routing.pyx":763
 *                             # only grow if it's at the same level and not
 *                             # previously visited
 *                             search_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_n, yi_n))
 *                             flat_region_mask_managed_raster.set(
 */
              __pyx_v_search_queue.push(__pyx_t_29);

              /* "pygeoprocessing/routing/routing.pyx":765
 *                             search_queue.push(
 *                                 CoordinateType(xi_n, yi_n))
 *                             flat_region_mask_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n, 1)
 * 
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0);

              /* "pygeoprocessing/routing/routing.pyx":758
 *                             downhill_drain = 1
 *                             continue
 *                         if is_close(n_height, center_val) and (             # <<<<<<<<<<<<<<
 *                                 flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata):
 */
            }
            __pyx_L40_continue:;
          }
        }

        /* "pygeoprocessing/routing/routing.pyx":768
 *                                 xi_n, yi_n, 1)
 * 
 *                 if not downhill_drain and not nodata_drain:             # <<<<<<<<<<<<<<
 *                     # entire region was searched with no drain, do a fill
 *                     pixel = PixelType(
 */
        __pyx_t_7 = ((!(__pyx_v_downhill_drain != 0)) != 0);
        if (__pyx_t_7) {
        } else {
          __pyx_t_6 = __pyx_t_7;
          goto __pyx_L53_bool_binop_done;
        }
        __pyx_t_7 = ((!(__pyx_v_nodata_drain != 0)) != 0);
        __pyx_t_6 = __pyx_t_7;
        __pyx_L53_bool_binop_done:;
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":771
 *                     # entire region was searched with no drain, do a fill
 *                     pixel = PixelType(
 *                         center_val, xi_root, yi_root, (             # <<<<<<<<<<<<<<
 *                             n_x_blocks * (yi_root >> BLOCK_BITS) +
 *                             xi_root >> BLOCK_BITS))
 */
          __pyx_t_30.value = __pyx_v_center_val;
          __pyx_t_30.xi = __pyx_v_xi_root;
          __pyx_t_30.yi = __pyx_v_yi_root;

          /* "pygeoprocessing/routing/routing.pyx":773
 *                         center_val, xi_root, yi_root, (
 *                             n_x_blocks * (yi_root >> BLOCK_BITS) +
 *                             xi_root >> BLOCK_BITS))             # <<<<<<<<<<<<<<
 *                     feature_id += 1
 *                     pit_mask_managed_raster.set(
 */
          __pyx_t_30.priority = (((__pyx_v_n_x_blocks * (__pyx_v_yi_root >> __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)) + __pyx_v_xi_root) >> __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS);
          __pyx_v_pixel = __pyx_t_30;

          /* "pygeoprocessing/routing/routing.pyx":774
 *                             n_x_blocks * (yi_root >> BLOCK_BITS) +
 *                             xi_root >> BLOCK_BITS))
 *                     feature_id += 1             # <<<<<<<<<<<<<<
 *                     pit_mask_managed_raster.set(
 *                         xi_root, yi_root, feature_id)
 */
          __pyx_v_feature_id = (__pyx_v_feature_id + 1);

          /* "pygeoprocessing/routing/routing.pyx":775
 *                             xi_root >> BLOCK_BITS))
 *                     feature_id += 1
 *                     pit_mask_managed_raster.set(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root, feature_id)
 *                     pit_queue.push(pixel)
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_pit_mask_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, __pyx_v_feature_id);

          /* "pygeoprocessing/routing/routing.pyx":777
 *                     pit_mask_managed_raster.set(
 *                         xi_root, yi_root, feature_id)
 *                     pit_queue.push(pixel)             # <<<<<<<<<<<<<<
 * 
 *                 # this loop visits pixels in increasing height order, so the
 */
          __pyx_v_pit_queue.push(__pyx_v_pixel);

          /* "pygeoprocessing/routing/routing.pyx":768
 *                                 xi_n, yi_n, 1)
 * 
 *                 if not downhill_drain and not nodata_drain:             # <<<<<<<<<<<<<<
 *                     # entire region was searched with no drain, do a fill
 *                     pixel = PixelType(
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":782
 *                 # first non-processed pixel that's < pixel.height or nodata
 *                 # will be the lowest pour point
 *                 pour_point = 0             # <<<<<<<<<<<<<<
 *                 fill_height = dem_nodata
 *                 while not pit_queue.empty():
 */
        __pyx_v_pour_point = 0;

        /* "pygeoprocessing/routing/routing.pyx":783
 *                 # will be the lowest pour point
 *                 pour_point = 0
 *                 fill_height = dem_nodata             # <<<<<<<<<<<<<<
 *                 while not pit_queue.empty():
 *                     pixel = pit_queue.top()
 */
        __pyx_v_fill_height = __pyx_v_dem_nodata;

        /* "pygeoprocessing/routing/routing.pyx":784
 *                 pour_point = 0
 *                 fill_height = dem_nodata
 *                 while not pit_queue.empty():             # <<<<<<<<<<<<<<
 *                     pixel = pit_queue.top()
 *                     pit_queue.pop()
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_pit_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":785
 *                 fill_height = dem_nodata
 *                 while not pit_queue.empty():
 *                     pixel = pit_queue.top()             # <<<<<<<<<<<<<<
 *                     pit_queue.pop()
 *                     xi_q = pixel.xi
 */
          __pyx_v_pixel = __pyx_v_pit_queue.top();

          /* "pygeoprocessing/routing/routing.pyx":786
 *                 while not pit_queue.empty():
 *                     pixel = pit_queue.top()
 *                     pit_queue.pop()             # <<<<<<<<<<<<<<
 *                     xi_q = pixel.xi
 *                     yi_q = pixel.yi
 */
          __pyx_v_pit_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":787
 *                     pixel = pit_queue.top()
 *                     pit_queue.pop()
 *                     xi_q = pixel.xi             # <<<<<<<<<<<<<<
 *                     yi_q = pixel.yi
 *                     # this is the potential fill height if pixel is pour point
 */
          __pyx_t_28 = __pyx_v_pixel.xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":788
 *                     pit_queue.pop()
 *                     xi_q = pixel.xi
 *                     yi_q = pixel.yi             # <<<<<<<<<<<<<<
 *                     # this is the potential fill height if pixel is pour point
 *                     fill_height = pixel.value
 */
          __pyx_t_28 = __pyx_v_pixel.yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":790
 *                     yi_q = pixel.yi
 *                     # this is the potential fill height if pixel is pour point
 *                     fill_height = pixel.value             # <<<<<<<<<<<<<<
 * 
 *                     for i_n in range(8):
 */
          __pyx_t_8 = __pyx_v_pixel.value;
          __pyx_v_fill_height = __pyx_t_8;

          /* "pygeoprocessing/routing/routing.pyx":792
 *                     fill_height = pixel.value
 * 
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":793
 * 
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":794
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":795
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # drain off the edge of the raster
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L60_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L60_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":796
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             # drain off the edge of the raster
 *                             pour_point = 1
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L60_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L60_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":795
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # drain off the edge of the raster
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":798
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # drain off the edge of the raster
 *                             pour_point = 1             # <<<<<<<<<<<<<<
 *                             break
 * 
 */
              __pyx_v_pour_point = 1;

              /* "pygeoprocessing/routing/routing.pyx":799
 *                             # drain off the edge of the raster
 *                             pour_point = 1
 *                             break             # <<<<<<<<<<<<<<
 * 
 *                         if pit_mask_managed_raster.get(
 */
              goto __pyx_L58_break;

              /* "pygeoprocessing/routing/routing.pyx":795
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # drain off the edge of the raster
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":802
 * 
 *                         if pit_mask_managed_raster.get(
 *                                 xi_n, yi_n) == feature_id:             # <<<<<<<<<<<<<<
 *                             # this cell has already been processed
 *                             continue
 */
            __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_pit_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == __pyx_v_feature_id) != 0);

            /* "pygeoprocessing/routing/routing.pyx":801
 *                             break
 * 
 *                         if pit_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n) == feature_id:
 *                             # this cell has already been processed
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":804
 *                                 xi_n, yi_n) == feature_id:
 *                             # this cell has already been processed
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         # mark as visited in the search for pour point
 */
              goto __pyx_L57_continue;

              /* "pygeoprocessing/routing/routing.pyx":801
 *                             break
 * 
 *                         if pit_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n) == feature_id:
 *                             # this cell has already been processed
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":807
 * 
 *                         # mark as visited in the search for pour point
 *                         pit_mask_managed_raster.set(             # <<<<<<<<<<<<<<
 *                             xi_n, yi_n, feature_id)
 * 
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_pit_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, __pyx_v_feature_id);

            /* "pygeoprocessing/routing/routing.pyx":810
 *                             xi_n, yi_n, feature_id)
 * 
 *                         n_height = filled_dem_managed_raster.get(xi_n, yi_n)             # <<<<<<<<<<<<<<
 *                         if is_close(n_height, dem_nodata) or (
 *                                 n_height < fill_height):
 */
            __pyx_v_n_height = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);

            /* "pygeoprocessing/routing/routing.pyx":811
 * 
 *                         n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata) or (             # <<<<<<<<<<<<<<
 *                                 n_height < fill_height):
 *                             # we encounter a neighbor not processed that is
 */
            __pyx_t_7 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_dem_nodata) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L66_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":812
 *                         n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata) or (
 *                                 n_height < fill_height):             # <<<<<<<<<<<<<<
 *                             # we encounter a neighbor not processed that is
 *                             # lower than the current pixel or nodata
 */
            __pyx_t_7 = ((__pyx_v_n_height < __pyx_v_fill_height) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L66_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":811
 * 
 *                         n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata) or (             # <<<<<<<<<<<<<<
 *                                 n_height < fill_height):
 *                             # we encounter a neighbor not processed that is
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":815
 *                             # we encounter a neighbor not processed that is
 *                             # lower than the current pixel or nodata
 *                             pour_point = 1             # <<<<<<<<<<<<<<
 *                             break
 * 
 */
              __pyx_v_pour_point = 1;

              /* "pygeoprocessing/routing/routing.pyx":816
 *                             # lower than the current pixel or nodata
 *                             pour_point = 1
 *                             break             # <<<<<<<<<<<<<<
 * 
 *                         # push onto queue, set the priority to be the block
 */
              goto __pyx_L58_break;

              /* "pygeoprocessing/routing/routing.pyx":811
 * 
 *                         n_height = filled_dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata) or (             # <<<<<<<<<<<<<<
 *                                 n_height < fill_height):
 *                             # we encounter a neighbor not processed that is
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":821
 *                         # index
 *                         pixel = PixelType(
 *                             n_height, xi_n, yi_n, (             # <<<<<<<<<<<<<<
 *                                 n_x_blocks * (yi_n >> BLOCK_BITS) +
 *                                 xi_n >> BLOCK_BITS))
 */
            __pyx_t_30.value = __pyx_v_n_height;
            __pyx_t_30.xi = __pyx_v_xi_n;
            __pyx_t_30.yi = __pyx_v_yi_n;

            /* "pygeoprocessing/routing/routing.pyx":823
 *                             n_height, xi_n, yi_n, (
 *                                 n_x_blocks * (yi_n >> BLOCK_BITS) +
 *                                 xi_n >> BLOCK_BITS))             # <<<<<<<<<<<<<<
 *                         pit_queue.push(pixel)
 * 
 */
            __pyx_t_30.priority = (((__pyx_v_n_x_blocks * (__pyx_v_yi_n >> __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)) + __pyx_v_xi_n) >> __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS);
            __pyx_v_pixel = __pyx_t_30;

            /* "pygeoprocessing/routing/routing.pyx":824
 *                                 n_x_blocks * (yi_n >> BLOCK_BITS) +
 *                                 xi_n >> BLOCK_BITS))
 *                         pit_queue.push(pixel)             # <<<<<<<<<<<<<<
 * 
 *                     if pour_point:
 */
            __pyx_v_pit_queue.push(__pyx_v_pixel);
            __pyx_L57_continue:;
          }
          __pyx_L58_break:;

          /* "pygeoprocessing/routing/routing.pyx":826
 *                         pit_queue.push(pixel)
 * 
 *                     if pour_point:             # <<<<<<<<<<<<<<
 *                         # found a pour point, clear the queue
 *                         pit_queue = PitPriorityQueueType()
 */
          __pyx_t_6 = (__pyx_v_pour_point != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":828
 *                     if pour_point:
 *                         # found a pour point, clear the queue
 *                         pit_queue = PitPriorityQueueType()             # <<<<<<<<<<<<<<
 * 
 *                         # start from original pit seed rather than pour point
 */
            try {
              __pyx_t_31 = __pyx_t_15pygeoprocessing_7routing_7routing_PitPriorityQueueType();
            } catch(...) {
              __Pyx_CppExn2PyErr();
              __PYX_ERR(0, 828, __pyx_L1_error)
            }
            __pyx_v_pit_queue = __pyx_t_31;

            /* "pygeoprocessing/routing/routing.pyx":836
 *                         # differentiate the pixels on the inside of the pit
 *                         # and the outside.
 *                         fill_queue.push(CoordinateType(xi_root, yi_root))             # <<<<<<<<<<<<<<
 *                         filled_dem_managed_raster.set(
 *                             xi_root, yi_root, fill_height)
 */
            __pyx_t_29.xi = __pyx_v_xi_root;
            __pyx_t_29.yi = __pyx_v_yi_root;
            __pyx_v_fill_queue.push(__pyx_t_29);

            /* "pygeoprocessing/routing/routing.pyx":837
 *                         # and the outside.
 *                         fill_queue.push(CoordinateType(xi_root, yi_root))
 *                         filled_dem_managed_raster.set(             # <<<<<<<<<<<<<<
 *                             xi_root, yi_root, fill_height)
 * 
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, __pyx_v_fill_height);

            /* "pygeoprocessing/routing/routing.pyx":826
 *                         pit_queue.push(pixel)
 * 
 *                     if pour_point:             # <<<<<<<<<<<<<<
 *                         # found a pour point, clear the queue
 *                         pit_queue = PitPriorityQueueType()
 */
          }
        }

        /* "pygeoprocessing/routing/routing.pyx":841
 * 
 *                 # this loop does a BFS to set all DEM pixels to `fill_height`
 *                 while not fill_queue.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = fill_queue.front().xi
 *                     yi_q = fill_queue.front().yi
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_fill_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":842
 *                 # this loop does a BFS to set all DEM pixels to `fill_height`
 *                 while not fill_queue.empty():
 *                     xi_q = fill_queue.front().xi             # <<<<<<<<<<<<<<
 *                     yi_q = fill_queue.front().yi
 *                     fill_queue.pop()
 */
          __pyx_t_28 = __pyx_v_fill_queue.front().xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":843
 *                 while not fill_queue.empty():
 *                     xi_q = fill_queue.front().xi
 *                     yi_q = fill_queue.front().yi             # <<<<<<<<<<<<<<
 *                     fill_queue.pop()
 * 
 */
          __pyx_t_28 = __pyx_v_fill_queue.front().yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":844
 *                     xi_q = fill_queue.front().xi
 *                     yi_q = fill_queue.front().yi
 *                     fill_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                     for i_n in range(8):
 */
          __pyx_v_fill_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":846
 *                     fill_queue.pop()
 * 
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":847
 * 
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":848
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":849
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L74_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L74_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":850
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L74_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L74_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":849
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":851
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         if filled_dem_managed_raster.get(
 */
              goto __pyx_L71_continue;

              /* "pygeoprocessing/routing/routing.pyx":849
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":854
 * 
 *                         if filled_dem_managed_raster.get(
 *                                 xi_n, yi_n) < fill_height:             # <<<<<<<<<<<<<<
 *                             filled_dem_managed_raster.set(
 *                                 xi_n, yi_n, fill_height)
 */
            __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) < __pyx_v_fill_height) != 0);

            /* "pygeoprocessing/routing/routing.pyx":853
 *                             continue
 * 
 *                         if filled_dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n) < fill_height:
 *                             filled_dem_managed_raster.set(
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":855
 *                         if filled_dem_managed_raster.get(
 *                                 xi_n, yi_n) < fill_height:
 *                             filled_dem_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n, fill_height)
 *                             fill_queue.push(CoordinateType(xi_n, yi_n))
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_filled_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, __pyx_v_fill_height);

              /* "pygeoprocessing/routing/routing.pyx":857
 *                             filled_dem_managed_raster.set(
 *                                 xi_n, yi_n, fill_height)
 *                             fill_queue.push(CoordinateType(xi_n, yi_n))             # <<<<<<<<<<<<<<
 * 
 *     pit_mask_managed_raster.close()
 */
              __pyx_t_29.xi = __pyx_v_xi_n;
              __pyx_t_29.yi = __pyx_v_yi_n;
              __pyx_v_fill_queue.push(__pyx_t_29);

              /* "pygeoprocessing/routing/routing.pyx":853
 *                             continue
 * 
 *                         if filled_dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n) < fill_height:
 *                             filled_dem_managed_raster.set(
 */
            }
            __pyx_L71_continue:;
          }
        }
        __pyx_L22_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":656
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":859
 *                             fill_queue.push(CoordinateType(xi_n, yi_n))
 * 
 *     pit_mask_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flat_region_mask_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_pit_mask_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":860
 * 
 *     pit_mask_managed_raster.close()
 *     flat_region_mask_managed_raster.close()             # <<<<<<<<<<<<<<
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flat_region_mask_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 860, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 860, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 860, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":861
 *     pit_mask_managed_raster.close()
 *     flat_region_mask_managed_raster.close()
 *     shutil.rmtree(working_dir_path)             # <<<<<<<<<<<<<<
 *     LOGGER.info('%.1f%% complete', 100.0)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_shutil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_16);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_16, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_v_working_dir_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_16)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_working_dir_path};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_working_dir_path};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(__pyx_v_working_dir_path);
      __Pyx_GIVEREF(__pyx_v_working_dir_path);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_working_dir_path);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":862
 *     flat_region_mask_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_info); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":503
 * 
 * 
 * def fill_pits(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_filled_dem_raster_path,
 *         working_dir=None,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.fill_pits", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dem_buffer_array);
  __Pyx_XDECREF(__pyx_v_dem_raster_info);
  __Pyx_XDECREF(__pyx_v_base_nodata);
  __Pyx_XDECREF(__pyx_v_working_dir_path);
  __Pyx_XDECREF(__pyx_v_flat_region_mask_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_flat_region_mask_managed_raster);
  __Pyx_XDECREF(__pyx_v_pit_mask_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_pit_mask_managed_raster);
  __Pyx_XDECREF(__pyx_v_geotiff_driver);
  __Pyx_XDECREF(__pyx_v_base_dem_raster);
  __Pyx_XDECREF(__pyx_v_target_dem_raster);
  __Pyx_XDECREF(__pyx_v_target_dem_band);
  __Pyx_XDECREF((PyObject *)__pyx_v_filled_dem_managed_raster);
  __Pyx_XDECREF(__pyx_v_offset_dict);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_modified_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":865
 * 
 * 
 * def flow_dir_d8(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path,
 *         working_dir=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_5flow_dir_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_4flow_dir_d8[] = "D8 flow direction.\n\n    Parameters:\n        dem_raster_path_band (tuple): a path, band number tuple indicating the\n            DEM calculate flow direction. This DEM must not have hydrological\n            pits or else the target flow direction is undefined.\n        target_flow_dir_path (string): path to a byte raster created by this\n            call of same dimensions as `dem_raster_path_band` that has a value\n            indicating the direction of downhill flow. Values are defined as\n            pointing to one of the eight neighbors with the following\n            convention:\n\n                321\n                4x0\n                567\n\n        working_dir (string): If not None, indicates where temporary files\n            should be created during this run. If this directory doesn't exist\n            it is created by this call.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_5flow_dir_d8 = {"flow_dir_d8", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_5flow_dir_d8, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_4flow_dir_d8};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_5flow_dir_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dem_raster_path_band = 0;
  PyObject *__pyx_v_target_flow_dir_path = 0;
  PyObject *__pyx_v_working_dir = 0;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("flow_dir_d8 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dem_raster_path_band,&__pyx_n_s_target_flow_dir_path,&__pyx_n_s_working_dir,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pygeoprocessing/routing/routing.pyx":867
 * def flow_dir_d8(
 *         dem_raster_path_band, target_flow_dir_path,
 *         working_dir=None,             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 *     """D8 flow direction.
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = __pyx_k__7;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dem_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_flow_dir_path)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("flow_dir_d8", 0, 2, 4, 1); __PYX_ERR(0, 865, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_working_dir);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "flow_dir_d8") < 0)) __PYX_ERR(0, 865, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_dem_raster_path_band = values[0];
    __pyx_v_target_flow_dir_path = values[1];
    __pyx_v_working_dir = values[2];
    __pyx_v_gtiff_creation_options = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("flow_dir_d8", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 865, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_dir_d8", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_4flow_dir_d8(__pyx_self, __pyx_v_dem_raster_path_band, __pyx_v_target_flow_dir_path, __pyx_v_working_dir, __pyx_v_gtiff_creation_options);

  /* "pygeoprocessing/routing/routing.pyx":865
 * 
 * 
 * def flow_dir_d8(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path,
 *         working_dir=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_4flow_dir_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_flow_dir_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_gtiff_creation_options) {
  PyArrayObject *__pyx_v_dem_buffer_array = 0;
  int __pyx_v_win_ysize;
  int __pyx_v_win_xsize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_xi_root;
  int __pyx_v_yi_root;
  int __pyx_v_i_n;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_q;
  int __pyx_v_yi_q;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  double __pyx_v_root_height;
  double __pyx_v_n_height;
  double __pyx_v_dem_nodata;
  double __pyx_v_drain_distance;
  double __pyx_v_n_drain_distance;
  int __pyx_v_diagonal_nodata;
  std::queue<struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType>  __pyx_v_search_queue;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_v_drain_queue;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_v_nodata_drain_queue;
  std::queue<int>  __pyx_v_nodata_flow_dir_queue;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  time_t __pyx_v_last_log_time;
  PyObject *__pyx_v_dem_raster_info = NULL;
  PyObject *__pyx_v_base_nodata = NULL;
  long __pyx_v_mask_nodata;
  PyObject *__pyx_v_working_dir_path = NULL;
  PyObject *__pyx_v_flat_region_mask_path = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flat_region_mask_managed_raster = NULL;
  long __pyx_v_flow_dir_nodata;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL;
  PyObject *__pyx_v_plateau_distance_path = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_plateau_distance_managed_raster = NULL;
  PyObject *__pyx_v_compatable_dem_raster_path_band = NULL;
  PyObject *__pyx_v_dem_block_xsize = NULL;
  PyObject *__pyx_v_dem_block_ysize = NULL;
  PyObject *__pyx_v_geotiff_driver = NULL;
  PyObject *__pyx_v_dem_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_dem_managed_raster = NULL;
  PyObject *__pyx_v_dem_band = NULL;
  PyObject *__pyx_v_offset_dict = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_modified_offset_dict = NULL;
  long __pyx_v_largest_slope_dir;
  double __pyx_v_largest_slope;
  double __pyx_v_n_slope;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_dem_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_dem_buffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  double __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  Py_ssize_t __pyx_t_17;
  PyObject *(*__pyx_t_18)(PyObject *);
  PyArrayObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  long __pyx_t_22;
  long __pyx_t_23;
  long __pyx_t_24;
  long __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  int __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  int __pyx_t_31;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_32;
  __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType __pyx_t_33;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_t_34;
  __Pyx_RefNannySetupContext("flow_dir_d8", 0);
  __pyx_pybuffer_dem_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_dem_buffer_array.refcount = 0;
  __pyx_pybuffernd_dem_buffer_array.data = NULL;
  __pyx_pybuffernd_dem_buffer_array.rcbuffer = &__pyx_pybuffer_dem_buffer_array;

  /* "pygeoprocessing/routing/routing.pyx":940
 *     # used for time-delayed logging
 *     cdef time_t last_log_time
 *     last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     # determine dem nodata in the working type, or set an improbable value
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":944
 *     # determine dem nodata in the working type, or set an improbable value
 *     # if one can't be determined
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 944, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 944, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 944, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 944, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 944, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_dem_raster_info = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":945
 *     # if one can't be determined
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *     if base_nodata is not None:
 *         # cast to a float64 since that's our operating array type
 */
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 945, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 945, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 945, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 945, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_base_nodata = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":946
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:             # <<<<<<<<<<<<<<
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)
 */
  __pyx_t_6 = (__pyx_v_base_nodata != Py_None);
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {

    /* "pygeoprocessing/routing/routing.pyx":948
 *     if base_nodata is not None:
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)             # <<<<<<<<<<<<<<
 *     else:
 *         # pick some very improbable value since it's hard to deal with NaNs
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 948, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 948, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_base_nodata};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 948, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_base_nodata};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 948, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 948, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL;
        __Pyx_INCREF(__pyx_v_base_nodata);
        __Pyx_GIVEREF(__pyx_v_base_nodata);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_base_nodata);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 948, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 948, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_dem_nodata = __pyx_t_8;

    /* "pygeoprocessing/routing/routing.pyx":946
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:             # <<<<<<<<<<<<<<
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)
 */
    goto __pyx_L3;
  }

  /* "pygeoprocessing/routing/routing.pyx":951
 *     else:
 *         # pick some very improbable value since it's hard to deal with NaNs
 *         dem_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 * 
 *     # these are used to determine if a sample is within the raster
 */
  /*else*/ {
    __pyx_v_dem_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;
  }
  __pyx_L3:;

  /* "pygeoprocessing/routing/routing.pyx":954
 * 
 *     # these are used to determine if a sample is within the raster
 *     raster_x_size, raster_y_size = dem_raster_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     # this is the nodata value for all the flat region and pit masks
 */
  __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 954, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 954, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_2);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 954, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 954, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 954, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_5), 2) < 0) __PYX_ERR(0, 954, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 954, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 954, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 954, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_raster_x_size = __pyx_t_10;
  __pyx_v_raster_y_size = __pyx_t_11;

  /* "pygeoprocessing/routing/routing.pyx":957
 * 
 *     # this is the nodata value for all the flat region and pit masks
 *     mask_nodata = 0             # <<<<<<<<<<<<<<
 * 
 *     # set up the working dir for the mask rasters
 */
  __pyx_v_mask_nodata = 0;

  /* "pygeoprocessing/routing/routing.pyx":960
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
    __Pyx_XGOTREF(__pyx_t_12);
    __Pyx_XGOTREF(__pyx_t_13);
    __Pyx_XGOTREF(__pyx_t_14);
    /*try:*/ {

      /* "pygeoprocessing/routing/routing.pyx":961
 *     # set up the working dir for the mask rasters
 *     try:
 *         if working_dir is not None:             # <<<<<<<<<<<<<<
 *             os.makedirs(working_dir)
 *     except OSError:
 */
      __pyx_t_7 = (__pyx_v_working_dir != Py_None);
      __pyx_t_6 = (__pyx_t_7 != 0);
      if (__pyx_t_6) {

        /* "pygeoprocessing/routing/routing.pyx":962
 *     try:
 *         if working_dir is not None:
 *             os.makedirs(working_dir)             # <<<<<<<<<<<<<<
 *     except OSError:
 *         pass
 */
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 962, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 962, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
          }
        }
        if (!__pyx_t_2) {
          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 962, __pyx_L6_error)
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_working_dir};
            __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 962, __pyx_L6_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_3);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_working_dir};
            __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 962, __pyx_L6_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_3);
          } else
          #endif
          {
            __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 962, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
            __Pyx_INCREF(__pyx_v_working_dir);
            __Pyx_GIVEREF(__pyx_v_working_dir);
            PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_working_dir);
            __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 962, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pygeoprocessing/routing/routing.pyx":961
 *     # set up the working dir for the mask rasters
 *     try:
 *         if working_dir is not None:             # <<<<<<<<<<<<<<
 *             os.makedirs(working_dir)
 *     except OSError:
 */
      }

      /* "pygeoprocessing/routing/routing.pyx":960
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
    }
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    goto __pyx_L11_try_end;
    __pyx_L6_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":963
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 *     except OSError:             # <<<<<<<<<<<<<<
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 */
    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError);
    if (__pyx_t_11) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L7_exception_handled;
    }
    goto __pyx_L8_except_error;
    __pyx_L8_except_error:;

    /* "pygeoprocessing/routing/routing.pyx":960
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_13);
    __Pyx_XGIVEREF(__pyx_t_14);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
    goto __pyx_L1_error;
    __pyx_L7_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_13);
    __Pyx_XGIVEREF(__pyx_t_14);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
    __pyx_L11_try_end:;
  }

  /* "pygeoprocessing/routing/routing.pyx":965
 *     except OSError:
 *         pass
 *     working_dir_path = tempfile.mkdtemp(             # <<<<<<<<<<<<<<
 *         dir=working_dir, prefix='flow_dir_d8_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 965, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 965, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":966
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir, prefix='flow_dir_d8_%s_' % time.strftime(             # <<<<<<<<<<<<<<
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 * 
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 966, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dir, __pyx_v_working_dir) < 0) __PYX_ERR(0, 966, __pyx_L1_error)
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 966, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_strftime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 966, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":967
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir, prefix='flow_dir_d8_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))             # <<<<<<<<<<<<<<
 * 
 *     # this raster is used to keep track of what pixels have been searched for
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_gmtime); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_16);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_16, function);
    }
  }
  if (__pyx_t_15) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 967, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 967, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_s_Y_m_d__H__M__S, __pyx_t_2};
    __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 966, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_s_Y_m_d__H__M__S, __pyx_t_2};
    __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 966, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_15 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 966, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (__pyx_t_16) {
      __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_16); __pyx_t_16 = NULL;
    }
    __Pyx_INCREF(__pyx_kp_s_Y_m_d__H__M__S);
    __Pyx_GIVEREF(__pyx_kp_s_Y_m_d__H__M__S);
    PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, __pyx_kp_s_Y_m_d__H__M__S);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_15, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 966, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":966
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir, prefix='flow_dir_d8_%s_' % time.strftime(             # <<<<<<<<<<<<<<
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 * 
 */
  __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_flow_dir_d8__s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 966, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_4) < 0) __PYX_ERR(0, 966, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":965
 *     except OSError:
 *         pass
 *     working_dir_path = tempfile.mkdtemp(             # <<<<<<<<<<<<<<
 *         dir=working_dir, prefix='flow_dir_d8_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 965, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_working_dir_path = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":972
 *     # a plateau. if a pixel is set, it means it is part of a locally
 *     # undrained area
 *     flat_region_mask_path = os.path.join(             # <<<<<<<<<<<<<<
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 972, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 972, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 972, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":973
 *     # undrained area
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 */
  __pyx_t_1 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_flat_region_mask_tif};
    __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 972, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_flat_region_mask_tif};
    __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 972, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 972, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(__pyx_v_working_dir_path);
    __Pyx_GIVEREF(__pyx_v_working_dir_path);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_v_working_dir_path);
    __Pyx_INCREF(__pyx_kp_s_flat_region_mask_tif);
    __Pyx_GIVEREF(__pyx_kp_s_flat_region_mask_tif);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_kp_s_flat_region_mask_tif);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 972, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_flat_region_mask_path = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":974
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 974, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 974, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":975
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,             # <<<<<<<<<<<<<<
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 975, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 975, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 975, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":976
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":974
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 974, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __Pyx_INCREF(__pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_v_flat_region_mask_path);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_15);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":976
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_15 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_fill_value_list, __pyx_t_4) < 0) __PYX_ERR(0, 976, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":977
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     flat_region_mask_managed_raster = _ManagedRaster(
 *         flat_region_mask_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 976, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":974
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 974, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":978
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flat_region_mask_path, 1, 1)
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 978, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_v_flat_region_mask_path);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_flat_region_mask_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_1);
  __pyx_t_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_4, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 978, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_flat_region_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":981
 *         flat_region_mask_path, 1, 1)
 * 
 *     flow_dir_nodata = 128             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,
 */
  __pyx_v_flow_dir_nodata = 0x80;

  /* "pygeoprocessing/routing/routing.pyx":982
 * 
 *     flow_dir_nodata = 128
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":983
 *     flow_dir_nodata = 128
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,             # <<<<<<<<<<<<<<
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":984
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)
 */
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":982
 * 
 *     flow_dir_nodata = 128
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 */
  __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_15);
  __Pyx_INCREF(__pyx_v_target_flow_dir_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_dir_path);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_target_flow_dir_path);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_1);
  __pyx_t_15 = 0;
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":984
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 984, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_fill_value_list, __pyx_t_15) < 0) __PYX_ERR(0, 984, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":985
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 984, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":982
 * 
 *     flow_dir_nodata = 128
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Byte,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 */
  __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 982, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":986
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)             # <<<<<<<<<<<<<<
 * 
 *     # this creates a raster that's used for a dynamic programming solution to
 */
  __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 986, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_INCREF(__pyx_v_target_flow_dir_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_dir_path);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_target_flow_dir_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_int_1);
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 986, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":992
 *     # raster_x_size * raster_y_size as a distance that's greater than the
 *     # longest plateau drain distance possible for this raster.
 *     plateau_distance_path = os.path.join(             # <<<<<<<<<<<<<<
 *         working_dir_path, 'plateau_distance.tif')
 *     pygeoprocessing.new_raster_from_base(
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_join); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":993
 *     # longest plateau drain distance possible for this raster.
 *     plateau_distance_path = os.path.join(
 *         working_dir_path, 'plateau_distance.tif')             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 */
  __pyx_t_5 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_15)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_working_dir_path, __pyx_kp_s_plateau_distance_tif};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_working_dir_path, __pyx_kp_s_plateau_distance_tif};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(__pyx_v_working_dir_path);
    __Pyx_GIVEREF(__pyx_v_working_dir_path);
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_11, __pyx_v_working_dir_path);
    __Pyx_INCREF(__pyx_kp_s_plateau_distance_tif);
    __Pyx_GIVEREF(__pyx_kp_s_plateau_distance_tif);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_11, __pyx_kp_s_plateau_distance_tif);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_v_plateau_distance_path = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":994
 *     plateau_distance_path = os.path.join(
 *         working_dir_path, 'plateau_distance.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 994, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 994, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":995
 *         working_dir_path, 'plateau_distance.tif')
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,             # <<<<<<<<<<<<<<
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":996
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_distance_managed_raster = _ManagedRaster(
 */
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_int_neg_1);
  __Pyx_GIVEREF(__pyx_int_neg_1);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_int_neg_1);

  /* "pygeoprocessing/routing/routing.pyx":994
 *     plateau_distance_path = os.path.join(
 *         working_dir_path, 'plateau_distance.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 994, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_v_plateau_distance_path);
  __Pyx_GIVEREF(__pyx_v_plateau_distance_path);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_plateau_distance_path);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_4);
  __pyx_t_1 = 0;
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":996
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_distance_managed_raster = _ManagedRaster(
 */
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_fill_value_list, __pyx_t_1) < 0) __PYX_ERR(0, 996, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":997
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     plateau_distance_managed_raster = _ManagedRaster(
 *         plateau_distance_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 996, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":994
 *     plateau_distance_path = os.path.join(
 *         working_dir_path, 'plateau_distance.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 994, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":998
 *         [-1], fill_value_list=[raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_distance_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         plateau_distance_path, 1, 1)
 * 
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 998, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_plateau_distance_path);
  __Pyx_GIVEREF(__pyx_v_plateau_distance_path);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_plateau_distance_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_1);
  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 998, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_plateau_distance_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1003
 *     # this raster is for random access of the DEM
 * 
 *     compatable_dem_raster_path_band = None             # <<<<<<<<<<<<<<
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_compatable_dem_raster_path_band = Py_None;

  /* "pygeoprocessing/routing/routing.pyx":1004
 * 
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']             # <<<<<<<<<<<<<<
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 */
  __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_block_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
    PyObject* sequence = __pyx_t_4;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1004, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_3);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1004, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1004, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_15 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1004, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_15)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_15); if (unlikely(!__pyx_t_1)) goto __pyx_L13_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_3 = __pyx_t_9(__pyx_t_15); if (unlikely(!__pyx_t_3)) goto __pyx_L13_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_15), 2) < 0) __PYX_ERR(0, 1004, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    goto __pyx_L14_unpacking_done;
    __pyx_L13_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1004, __pyx_L1_error)
    __pyx_L14_unpacking_done:;
  }
  __pyx_v_dem_block_xsize = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_dem_block_ysize = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1005
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 */
  __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_xsize, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyNumber_And(__pyx_v_dem_block_xsize, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1005, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1005, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_6 = __pyx_t_7;
    goto __pyx_L16_bool_binop_done;
  }

  /* "pygeoprocessing/routing/routing.pyx":1006
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):             # <<<<<<<<<<<<<<
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 *         compatable_dem_raster_path_band = (
 */
  __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_ysize, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyNumber_And(__pyx_v_dem_block_ysize, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1006, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1006, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __pyx_t_7;
  __pyx_L16_bool_binop_done:;

  /* "pygeoprocessing/routing/routing.pyx":1005
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 */
  if (__pyx_t_6) {

    /* "pygeoprocessing/routing/routing.pyx":1007
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1007, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_warning); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1007, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1007, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1009
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_compatable_dem_tif};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1009, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_compatable_dem_tif};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1009, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    {
      __pyx_t_15 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1009, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(__pyx_v_working_dir_path);
      __Pyx_GIVEREF(__pyx_v_working_dir_path);
      PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, __pyx_v_working_dir_path);
      __Pyx_INCREF(__pyx_kp_s_compatable_dem_tif);
      __Pyx_GIVEREF(__pyx_kp_s_compatable_dem_tif);
      PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_kp_s_compatable_dem_tif);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1009, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1010
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 *             dem_raster_path_band[1])             # <<<<<<<<<<<<<<
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1010, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "pygeoprocessing/routing/routing.pyx":1009
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 */
    __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_3);
    __pyx_t_4 = 0;
    __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_t_15);
    __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1011
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')             # <<<<<<<<<<<<<<
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(
 */
    __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1011, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1011, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1011, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_geotiff_driver = __pyx_t_15;
    __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1012
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *         geotiff_driver.CreateCopy(
 *             compatable_dem_raster_path_band[0], dem_raster,
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_3, __pyx_t_5};
      __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_3, __pyx_t_5};
      __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_5);
      __pyx_t_3 = 0;
      __pyx_t_5 = 0;
      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_dem_raster = __pyx_t_15;
    __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1013
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 */
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_geotiff_driver, __pyx_n_s_CreateCopy); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1013, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);

    /* "pygeoprocessing/routing/routing.pyx":1014
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(
 *             compatable_dem_raster_path_band[0], dem_raster,             # <<<<<<<<<<<<<<
 *             options=gtiff_creation_options)
 *         dem_raster = None
 */
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1014, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "pygeoprocessing/routing/routing.pyx":1013
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 */
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1013, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __Pyx_INCREF(__pyx_v_dem_raster);
    __Pyx_GIVEREF(__pyx_v_dem_raster);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_dem_raster);
    __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1015
 *         geotiff_driver.CreateCopy(
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *         dem_raster = None
 *         LOGGER.info("compatible dem complete")
 */
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1015, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 1015, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":1013
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 */
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1013, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1016
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 *         dem_raster = None             # <<<<<<<<<<<<<<
 *         LOGGER.info("compatible dem complete")
 *     else:
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_dem_raster, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":1017
 *             options=gtiff_creation_options)
 *         dem_raster = None
 *         LOGGER.info("compatible dem complete")             # <<<<<<<<<<<<<<
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1017, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1017, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1017, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1005
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 */
    goto __pyx_L15;
  }

  /* "pygeoprocessing/routing/routing.pyx":1019
 *         LOGGER.info("compatible dem complete")
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band             # <<<<<<<<<<<<<<
 *     dem_managed_raster = _ManagedRaster(
 *         compatable_dem_raster_path_band[0],
 */
  /*else*/ {
    __Pyx_INCREF(__pyx_v_dem_raster_path_band);
    __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_v_dem_raster_path_band);
  }
  __pyx_L15:;

  /* "pygeoprocessing/routing/routing.pyx":1021
 *         compatable_dem_raster_path_band = dem_raster_path_band
 *     dem_managed_raster = _ManagedRaster(
 *         compatable_dem_raster_path_band[0],             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band[1], 0)
 * 
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":1022
 *     dem_managed_raster = _ManagedRaster(
 *         compatable_dem_raster_path_band[0],
 *         compatable_dem_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 * 
 *     # and this raster is for efficient block-by-block reading of the dem
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1022, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pygeoprocessing/routing/routing.pyx":1020
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band
 *     dem_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band[0],
 *         compatable_dem_raster_path_band[1], 0)
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1020, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1020, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1025
 * 
 *     # and this raster is for efficient block-by-block reading of the dem
 *     dem_raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band[0], gdal.OF_RASTER)
 *     dem_band = dem_raster.GetRasterBand(compatable_dem_raster_path_band[1])
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1026
 *     # and this raster is for efficient block-by-block reading of the dem
 *     dem_raster = gdal.OpenEx(
 *         compatable_dem_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     dem_band = dem_raster.GetRasterBand(compatable_dem_raster_path_band[1])
 * 
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_2, __pyx_t_3};
    __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1025, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_2, __pyx_t_3};
    __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1025, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1025, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (__pyx_t_15) {
      __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_15); __pyx_t_15 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1025, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_XDECREF_SET(__pyx_v_dem_raster, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1027
 *     dem_raster = gdal.OpenEx(
 *         compatable_dem_raster_path_band[0], gdal.OF_RASTER)
 *     dem_band = dem_raster.GetRasterBand(compatable_dem_raster_path_band[1])             # <<<<<<<<<<<<<<
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1027, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_1};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1027, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_1};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1027, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1027, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_dem_band = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1030
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1031
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             compatable_dem_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pygeoprocessing/routing/routing.pyx":1030
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1031
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             compatable_dem_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 1031, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1031, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1030
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_17 = 0;
    __pyx_t_18 = NULL;
  } else {
    __pyx_t_17 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1030, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_18 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 1030, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_18)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1030, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_17); __Pyx_INCREF(__pyx_t_1); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1030, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_18(__pyx_t_4);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1030, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1033
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 */
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1033, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1033, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_win_xsize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1034
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']             # <<<<<<<<<<<<<<
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']
 */
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1034, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1034, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_win_ysize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1035
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']             # <<<<<<<<<<<<<<
 *         yoff = offset_dict['yoff']
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1035, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1035, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_xoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1036
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']             # <<<<<<<<<<<<<<
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1036, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1036, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_yoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1038
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    __pyx_t_6 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
    if (__pyx_t_6) {

      /* "pygeoprocessing/routing/routing.pyx":1039
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
      __pyx_v_last_log_time = time(NULL);

      /* "pygeoprocessing/routing/routing.pyx":1040
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))
 */
      __pyx_t_1 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1040, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pygeoprocessing/routing/routing.pyx":1041
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);

      /* "pygeoprocessing/routing/routing.pyx":1042
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 */
      __pyx_t_3 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);

      /* "pygeoprocessing/routing/routing.pyx":1041
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_15 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_11 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_15};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1041, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_15};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1041, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1041, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_t_15);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_15);
        __pyx_t_15 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1041, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pygeoprocessing/routing/routing.pyx":1038
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":1045
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1046
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata
 */
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_15 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_15);
    __pyx_t_2 = 0;
    __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1045
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1047
 *         dem_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)             # <<<<<<<<<<<<<<
 *         dem_buffer_array[:] = dem_nodata
 * 
 */
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1047, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1047, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1047, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1047, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1045
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_15, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1045, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1045, __pyx_L1_error)
    __pyx_t_19 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
      __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_11 < 0)) {
        PyErr_Fetch(&__pyx_t_14, &__pyx_t_13, &__pyx_t_12);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dem_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_14, __pyx_t_13, __pyx_t_12);
        }
        __pyx_t_14 = __pyx_t_13 = __pyx_t_12 = 0;
      }
      __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1045, __pyx_L1_error)
    }
    __pyx_t_19 = 0;
    __Pyx_XDECREF_SET(__pyx_v_dem_buffer_array, ((PyArrayObject *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1048
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata             # <<<<<<<<<<<<<<
 * 
 *         # attempt to expand read block by a pixel boundary
 */
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_dem_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1048, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_slice__11, __pyx_t_3) < 0)) __PYX_ERR(0, 1048, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1051
 * 
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1051, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "pygeoprocessing/routing/routing.pyx":1052
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)             # <<<<<<<<<<<<<<
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)
 */
    __pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1052, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1052, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_15, __pyx_t_5};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_15, __pyx_t_5};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_16 = PyTuple_New(3+__pyx_t_11); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_v_offset_dict);
      PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_11, __pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_11, __pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_16, 2+__pyx_t_11, __pyx_t_5);
      __pyx_t_15 = 0;
      __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_16, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1051, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_16 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_16);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_16 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_16)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_16);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_5), 2) < 0) __PYX_ERR(0, 1051, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L22_unpacking_done;
      __pyx_L21_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1051, __pyx_L1_error)
      __pyx_L22_unpacking_done:;
    }

    /* "pygeoprocessing/routing/routing.pyx":1051
 * 
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 */
    if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
      PyObject* sequence = __pyx_t_1;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1051, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_20 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_15 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_20 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_20);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_15,&__pyx_t_2,&__pyx_t_20};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1051, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_15,&__pyx_t_2,&__pyx_t_20};
      __pyx_t_21 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1051, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_21);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_21)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_9(__pyx_t_21); if (unlikely(!item)) goto __pyx_L23_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_21), 4) < 0) __PYX_ERR(0, 1051, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      goto __pyx_L24_unpacking_done;
      __pyx_L23_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1051, __pyx_L1_error)
      __pyx_L24_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_15);
    __pyx_t_15 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_20);
    __pyx_t_20 = 0;
    __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_16);
    __pyx_t_16 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1053
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);

    /* "pygeoprocessing/routing/routing.pyx":1054
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 1054, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_1 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1054, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_1 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1053, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    }

    /* "pygeoprocessing/routing/routing.pyx":1053
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1054
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_astype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1054, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1054, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1054, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_20)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_20);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_20) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1054, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_16};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1054, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_16};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1054, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1054, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_20); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_20); __pyx_t_20 = NULL;
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_16);
        __pyx_t_16 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1054, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1053
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_1 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_2);
    __pyx_t_1 = 0;
    __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_t_16, __pyx_t_3) < 0)) __PYX_ERR(0, 1053, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1057
 * 
 *         # ensure these are set for the complier
 *         xi_n = -1             # <<<<<<<<<<<<<<
 *         yi_n = -1
 * 
 */
    __pyx_v_xi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":1058
 *         # ensure these are set for the complier
 *         xi_n = -1
 *         yi_n = -1             # <<<<<<<<<<<<<<
 * 
 *         # search block for to set flow direction
 */
    __pyx_v_yi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":1061
 * 
 *         # search block for to set flow direction
 *         for yi in range(1, win_ysize+1):             # <<<<<<<<<<<<<<
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]
 */
    __pyx_t_22 = (__pyx_v_win_ysize + 1);
    __pyx_t_23 = __pyx_t_22;
    for (__pyx_t_11 = 1; __pyx_t_11 < __pyx_t_23; __pyx_t_11+=1) {
      __pyx_v_yi = __pyx_t_11;

      /* "pygeoprocessing/routing/routing.pyx":1062
 *         # search block for to set flow direction
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):             # <<<<<<<<<<<<<<
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):
 */
      __pyx_t_24 = (__pyx_v_win_xsize + 1);
      __pyx_t_25 = __pyx_t_24;
      for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_25; __pyx_t_10+=1) {
        __pyx_v_xi = __pyx_t_10;

        /* "pygeoprocessing/routing/routing.pyx":1063
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]             # <<<<<<<<<<<<<<
 *                 if is_close(root_height, dem_nodata):
 *                     continue
 */
        __pyx_t_26 = __pyx_v_yi;
        __pyx_t_27 = __pyx_v_xi;
        __pyx_t_28 = -1;
        if (__pyx_t_26 < 0) {
          __pyx_t_26 += __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_26 < 0)) __pyx_t_28 = 0;
        } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_28 = 0;
        if (__pyx_t_27 < 0) {
          __pyx_t_27 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_27 < 0)) __pyx_t_28 = 1;
        } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_28 = 1;
        if (unlikely(__pyx_t_28 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_28);
          __PYX_ERR(0, 1063, __pyx_L1_error)
        }
        __pyx_v_root_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides));

        /* "pygeoprocessing/routing/routing.pyx":1064
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_root_height, __pyx_v_dem_nodata) != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1065
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # this value is set in case it turns out to be the root of a
 */
          goto __pyx_L27_continue;

          /* "pygeoprocessing/routing/routing.pyx":1064
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1070
 *                 # pit, we'll start the fill from this pixel in the last phase
 *                 # of the algorithm
 *                 xi_root = xi-1+xoff             # <<<<<<<<<<<<<<
 *                 yi_root = yi-1+yoff
 * 
 */
        __pyx_v_xi_root = ((__pyx_v_xi - 1) + __pyx_v_xoff);

        /* "pygeoprocessing/routing/routing.pyx":1071
 *                 # of the algorithm
 *                 xi_root = xi-1+xoff
 *                 yi_root = yi-1+yoff             # <<<<<<<<<<<<<<
 * 
 *                 if flow_dir_managed_raster.get(
 */
        __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff);

        /* "pygeoprocessing/routing/routing.pyx":1074
 * 
 *                 if flow_dir_managed_raster.get(
 *                         xi_root, yi_root) != flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                     # already been defined
 *                     continue
 */
        __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root) != __pyx_v_flow_dir_nodata) != 0);

        /* "pygeoprocessing/routing/routing.pyx":1073
 *                 yi_root = yi-1+yoff
 * 
 *                 if flow_dir_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root) != flow_dir_nodata:
 *                     # already been defined
 */
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1076
 *                         xi_root, yi_root) != flow_dir_nodata:
 *                     # already been defined
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # initialize variables to indicate the largest slope_dir is
 */
          goto __pyx_L27_continue;

          /* "pygeoprocessing/routing/routing.pyx":1073
 *                 yi_root = yi-1+yoff
 * 
 *                 if flow_dir_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root) != flow_dir_nodata:
 *                     # already been defined
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1081
 *                 # undefined, the largest slope seen so far is flat, and the
 *                 # largest nodata is at least a diagonal away
 *                 largest_slope_dir = -1             # <<<<<<<<<<<<<<
 *                 largest_slope = 0.0
 * 
 */
        __pyx_v_largest_slope_dir = -1L;

        /* "pygeoprocessing/routing/routing.pyx":1082
 *                 # largest nodata is at least a diagonal away
 *                 largest_slope_dir = -1
 *                 largest_slope = 0.0             # <<<<<<<<<<<<<<
 * 
 *                 for i_n in range(8):
 */
        __pyx_v_largest_slope = 0.0;

        /* "pygeoprocessing/routing/routing.pyx":1084
 *                 largest_slope = 0.0
 * 
 *                 for i_n in range(8):             # <<<<<<<<<<<<<<
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
        for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
          __pyx_v_i_n = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1085
 * 
 *                 for i_n in range(8):
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 */
          __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

          /* "pygeoprocessing/routing/routing.pyx":1086
 *                 for i_n in range(8):
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):
 */
          __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

          /* "pygeoprocessing/routing/routing.pyx":1087
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]             # <<<<<<<<<<<<<<
 *                     if is_close(n_height, dem_nodata):
 *                         continue
 */
          __pyx_t_29 = __pyx_v_yi_n;
          __pyx_t_30 = __pyx_v_xi_n;
          __pyx_t_31 = -1;
          if (__pyx_t_29 < 0) {
            __pyx_t_29 += __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape;
            if (unlikely(__pyx_t_29 < 0)) __pyx_t_31 = 0;
          } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_31 = 0;
          if (__pyx_t_30 < 0) {
            __pyx_t_30 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape;
            if (unlikely(__pyx_t_30 < 0)) __pyx_t_31 = 1;
          } else if (unlikely(__pyx_t_30 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_31 = 1;
          if (unlikely(__pyx_t_31 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_31);
            __PYX_ERR(0, 1087, __pyx_L1_error)
          }
          __pyx_v_n_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides));

          /* "pygeoprocessing/routing/routing.pyx":1088
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                         continue
 *                     n_slope = root_height - n_height
 */
          __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_dem_nodata) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1089
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):
 *                         continue             # <<<<<<<<<<<<<<
 *                     n_slope = root_height - n_height
 *                     if i_n & 1:
 */
            goto __pyx_L31_continue;

            /* "pygeoprocessing/routing/routing.pyx":1088
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                         continue
 *                     n_slope = root_height - n_height
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":1090
 *                     if is_close(n_height, dem_nodata):
 *                         continue
 *                     n_slope = root_height - n_height             # <<<<<<<<<<<<<<
 *                     if i_n & 1:
 *                         # if diagonal, adjust the slope
 */
          __pyx_v_n_slope = (__pyx_v_root_height - __pyx_v_n_height);

          /* "pygeoprocessing/routing/routing.pyx":1091
 *                         continue
 *                     n_slope = root_height - n_height
 *                     if i_n & 1:             # <<<<<<<<<<<<<<
 *                         # if diagonal, adjust the slope
 *                         n_slope *= SQRT2_INV
 */
          __pyx_t_6 = ((__pyx_v_i_n & 1) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1093
 *                     if i_n & 1:
 *                         # if diagonal, adjust the slope
 *                         n_slope *= SQRT2_INV             # <<<<<<<<<<<<<<
 *                     if n_slope > largest_slope:
 *                         largest_slope_dir = i_n
 */
            __pyx_v_n_slope = (__pyx_v_n_slope * __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV);

            /* "pygeoprocessing/routing/routing.pyx":1091
 *                         continue
 *                     n_slope = root_height - n_height
 *                     if i_n & 1:             # <<<<<<<<<<<<<<
 *                         # if diagonal, adjust the slope
 *                         n_slope *= SQRT2_INV
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":1094
 *                         # if diagonal, adjust the slope
 *                         n_slope *= SQRT2_INV
 *                     if n_slope > largest_slope:             # <<<<<<<<<<<<<<
 *                         largest_slope_dir = i_n
 *                         largest_slope = n_slope
 */
          __pyx_t_6 = ((__pyx_v_n_slope > __pyx_v_largest_slope) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1095
 *                         n_slope *= SQRT2_INV
 *                     if n_slope > largest_slope:
 *                         largest_slope_dir = i_n             # <<<<<<<<<<<<<<
 *                         largest_slope = n_slope
 * 
 */
            __pyx_v_largest_slope_dir = __pyx_v_i_n;

            /* "pygeoprocessing/routing/routing.pyx":1096
 *                     if n_slope > largest_slope:
 *                         largest_slope_dir = i_n
 *                         largest_slope = n_slope             # <<<<<<<<<<<<<<
 * 
 *                 if largest_slope_dir >= 0:
 */
            __pyx_v_largest_slope = __pyx_v_n_slope;

            /* "pygeoprocessing/routing/routing.pyx":1094
 *                         # if diagonal, adjust the slope
 *                         n_slope *= SQRT2_INV
 *                     if n_slope > largest_slope:             # <<<<<<<<<<<<<<
 *                         largest_slope_dir = i_n
 *                         largest_slope = n_slope
 */
          }
          __pyx_L31_continue:;
        }

        /* "pygeoprocessing/routing/routing.pyx":1098
 *                         largest_slope = n_slope
 * 
 *                 if largest_slope_dir >= 0:             # <<<<<<<<<<<<<<
 *                     # define flow dir and move on
 *                     flow_dir_managed_raster.set(
 */
        __pyx_t_6 = ((__pyx_v_largest_slope_dir >= 0) != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1100
 *                 if largest_slope_dir >= 0:
 *                     # define flow dir and move on
 *                     flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root, largest_slope_dir)
 *                     continue
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, __pyx_v_largest_slope_dir);

          /* "pygeoprocessing/routing/routing.pyx":1102
 *                     flow_dir_managed_raster.set(
 *                         xi_root, yi_root, largest_slope_dir)
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # otherwise, this pixel doesn't drain locally, so it must
 */
          goto __pyx_L27_continue;

          /* "pygeoprocessing/routing/routing.pyx":1098
 *                         largest_slope = n_slope
 * 
 *                 if largest_slope_dir >= 0:             # <<<<<<<<<<<<<<
 *                     # define flow dir and move on
 *                     flow_dir_managed_raster.set(
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1106
 *                 # otherwise, this pixel doesn't drain locally, so it must
 *                 # be a plateau, search for the drains of the plateau
 *                 search_queue.push(CoordinateType(xi_root, yi_root))             # <<<<<<<<<<<<<<
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)
 * 
 */
        __pyx_t_32.xi = __pyx_v_xi_root;
        __pyx_t_32.yi = __pyx_v_yi_root;
        __pyx_v_search_queue.push(__pyx_t_32);

        /* "pygeoprocessing/routing/routing.pyx":1107
 *                 # be a plateau, search for the drains of the plateau
 *                 search_queue.push(CoordinateType(xi_root, yi_root))
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)             # <<<<<<<<<<<<<<
 * 
 *                 # this loop does a BFS starting at this pixel to all pixels
 */
        __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 1.0);

        /* "pygeoprocessing/routing/routing.pyx":1113
 *                 # on a queue for later processing.
 * 
 *                 while not search_queue.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = search_queue.front().xi
 *                     yi_q = search_queue.front().yi
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_search_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":1114
 * 
 *                 while not search_queue.empty():
 *                     xi_q = search_queue.front().xi             # <<<<<<<<<<<<<<
 *                     yi_q = search_queue.front().yi
 *                     search_queue.pop()
 */
          __pyx_t_28 = __pyx_v_search_queue.front().xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1115
 *                 while not search_queue.empty():
 *                     xi_q = search_queue.front().xi
 *                     yi_q = search_queue.front().yi             # <<<<<<<<<<<<<<
 *                     search_queue.pop()
 * 
 */
          __pyx_t_28 = __pyx_v_search_queue.front().yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1116
 *                     xi_q = search_queue.front().xi
 *                     yi_q = search_queue.front().yi
 *                     search_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                     largest_slope_dir = -1
 */
          __pyx_v_search_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":1118
 *                     search_queue.pop()
 * 
 *                     largest_slope_dir = -1             # <<<<<<<<<<<<<<
 *                     largest_slope = 0.0
 *                     diagonal_nodata = 1
 */
          __pyx_v_largest_slope_dir = -1L;

          /* "pygeoprocessing/routing/routing.pyx":1119
 * 
 *                     largest_slope_dir = -1
 *                     largest_slope = 0.0             # <<<<<<<<<<<<<<
 *                     diagonal_nodata = 1
 *                     for i_n in range(8):
 */
          __pyx_v_largest_slope = 0.0;

          /* "pygeoprocessing/routing/routing.pyx":1120
 *                     largest_slope_dir = -1
 *                     largest_slope = 0.0
 *                     diagonal_nodata = 1             # <<<<<<<<<<<<<<
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 */
          __pyx_v_diagonal_nodata = 1;

          /* "pygeoprocessing/routing/routing.pyx":1121
 *                     largest_slope = 0.0
 *                     diagonal_nodata = 1
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1122
 *                     diagonal_nodata = 1
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":1123
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":1125
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L42_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L42_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1126
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             n_height = dem_nodata
 *                         else:
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L42_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L42_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1125
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1127
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata             # <<<<<<<<<<<<<<
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 */
              __pyx_v_n_height = __pyx_v_dem_nodata;

              /* "pygeoprocessing/routing/routing.pyx":1125
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata
 */
              goto __pyx_L41;
            }

            /* "pygeoprocessing/routing/routing.pyx":1129
 *                             n_height = dem_nodata
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)             # <<<<<<<<<<<<<<
 *                         if is_close(n_height, dem_nodata):
 *                             if diagonal_nodata and largest_slope == 0.0:
 */
            /*else*/ {
              __pyx_v_n_height = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);
            }
            __pyx_L41:;

            /* "pygeoprocessing/routing/routing.pyx":1130
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                             if diagonal_nodata and largest_slope == 0.0:
 *                                 largest_slope_dir = i_n
 */
            __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_dem_nodata) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1131
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):
 *                             if diagonal_nodata and largest_slope == 0.0:             # <<<<<<<<<<<<<<
 *                                 largest_slope_dir = i_n
 *                                 diagonal_nodata = i_n & 1
 */
              __pyx_t_7 = (__pyx_v_diagonal_nodata != 0);
              if (__pyx_t_7) {
              } else {
                __pyx_t_6 = __pyx_t_7;
                goto __pyx_L48_bool_binop_done;
              }
              __pyx_t_7 = ((__pyx_v_largest_slope == 0.0) != 0);
              __pyx_t_6 = __pyx_t_7;
              __pyx_L48_bool_binop_done:;
              if (__pyx_t_6) {

                /* "pygeoprocessing/routing/routing.pyx":1132
 *                         if is_close(n_height, dem_nodata):
 *                             if diagonal_nodata and largest_slope == 0.0:
 *                                 largest_slope_dir = i_n             # <<<<<<<<<<<<<<
 *                                 diagonal_nodata = i_n & 1
 *                             continue
 */
                __pyx_v_largest_slope_dir = __pyx_v_i_n;

                /* "pygeoprocessing/routing/routing.pyx":1133
 *                             if diagonal_nodata and largest_slope == 0.0:
 *                                 largest_slope_dir = i_n
 *                                 diagonal_nodata = i_n & 1             # <<<<<<<<<<<<<<
 *                             continue
 *                         n_slope = root_height - n_height
 */
                __pyx_v_diagonal_nodata = (__pyx_v_i_n & 1);

                /* "pygeoprocessing/routing/routing.pyx":1131
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):
 *                             if diagonal_nodata and largest_slope == 0.0:             # <<<<<<<<<<<<<<
 *                                 largest_slope_dir = i_n
 *                                 diagonal_nodata = i_n & 1
 */
              }

              /* "pygeoprocessing/routing/routing.pyx":1134
 *                                 largest_slope_dir = i_n
 *                                 diagonal_nodata = i_n & 1
 *                             continue             # <<<<<<<<<<<<<<
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:
 */
              goto __pyx_L39_continue;

              /* "pygeoprocessing/routing/routing.pyx":1130
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                             if diagonal_nodata and largest_slope == 0.0:
 *                                 largest_slope_dir = i_n
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1135
 *                                 diagonal_nodata = i_n & 1
 *                             continue
 *                         n_slope = root_height - n_height             # <<<<<<<<<<<<<<
 *                         if n_slope < 0:
 *                             continue
 */
            __pyx_v_n_slope = (__pyx_v_root_height - __pyx_v_n_height);

            /* "pygeoprocessing/routing/routing.pyx":1136
 *                             continue
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if n_slope == 0.0:
 */
            __pyx_t_6 = ((__pyx_v_n_slope < 0.0) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1137
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:
 *                             continue             # <<<<<<<<<<<<<<
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(
 */
              goto __pyx_L39_continue;

              /* "pygeoprocessing/routing/routing.pyx":1136
 *                             continue
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if n_slope == 0.0:
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1138
 *                         if n_slope < 0:
 *                             continue
 *                         if n_slope == 0.0:             # <<<<<<<<<<<<<<
 *                             if flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata:
 */
            __pyx_t_6 = ((__pyx_v_n_slope == 0.0) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1140
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata:             # <<<<<<<<<<<<<<
 *                                 # only grow if it's at the same level and not
 *                                 # previously visited
 */
              __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == __pyx_v_mask_nodata) != 0);

              /* "pygeoprocessing/routing/routing.pyx":1139
 *                             continue
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n) == mask_nodata:
 *                                 # only grow if it's at the same level and not
 */
              if (__pyx_t_6) {

                /* "pygeoprocessing/routing/routing.pyx":1143
 *                                 # only grow if it's at the same level and not
 *                                 # previously visited
 *                                 search_queue.push(CoordinateType(xi_n, yi_n))             # <<<<<<<<<<<<<<
 *                                 flat_region_mask_managed_raster.set(
 *                                     xi_n, yi_n, 1)
 */
                __pyx_t_32.xi = __pyx_v_xi_n;
                __pyx_t_32.yi = __pyx_v_yi_n;
                __pyx_v_search_queue.push(__pyx_t_32);

                /* "pygeoprocessing/routing/routing.pyx":1144
 *                                 # previously visited
 *                                 search_queue.push(CoordinateType(xi_n, yi_n))
 *                                 flat_region_mask_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n, 1)
 *                             continue
 */
                __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0);

                /* "pygeoprocessing/routing/routing.pyx":1139
 *                             continue
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n) == mask_nodata:
 *                                 # only grow if it's at the same level and not
 */
              }

              /* "pygeoprocessing/routing/routing.pyx":1146
 *                                 flat_region_mask_managed_raster.set(
 *                                     xi_n, yi_n, 1)
 *                             continue             # <<<<<<<<<<<<<<
 *                         if i_n & 1:
 *                             n_slope *= SQRT2_INV
 */
              goto __pyx_L39_continue;

              /* "pygeoprocessing/routing/routing.pyx":1138
 *                         if n_slope < 0:
 *                             continue
 *                         if n_slope == 0.0:             # <<<<<<<<<<<<<<
 *                             if flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata:
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1147
 *                                     xi_n, yi_n, 1)
 *                             continue
 *                         if i_n & 1:             # <<<<<<<<<<<<<<
 *                             n_slope *= SQRT2_INV
 *                         if n_slope > largest_slope:
 */
            __pyx_t_6 = ((__pyx_v_i_n & 1) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1148
 *                             continue
 *                         if i_n & 1:
 *                             n_slope *= SQRT2_INV             # <<<<<<<<<<<<<<
 *                         if n_slope > largest_slope:
 *                             largest_slope = n_slope
 */
              __pyx_v_n_slope = (__pyx_v_n_slope * __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV);

              /* "pygeoprocessing/routing/routing.pyx":1147
 *                                     xi_n, yi_n, 1)
 *                             continue
 *                         if i_n & 1:             # <<<<<<<<<<<<<<
 *                             n_slope *= SQRT2_INV
 *                         if n_slope > largest_slope:
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1149
 *                         if i_n & 1:
 *                             n_slope *= SQRT2_INV
 *                         if n_slope > largest_slope:             # <<<<<<<<<<<<<<
 *                             largest_slope = n_slope
 *                             largest_slope_dir = i_n
 */
            __pyx_t_6 = ((__pyx_v_n_slope > __pyx_v_largest_slope) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1150
 *                             n_slope *= SQRT2_INV
 *                         if n_slope > largest_slope:
 *                             largest_slope = n_slope             # <<<<<<<<<<<<<<
 *                             largest_slope_dir = i_n
 * 
 */
              __pyx_v_largest_slope = __pyx_v_n_slope;

              /* "pygeoprocessing/routing/routing.pyx":1151
 *                         if n_slope > largest_slope:
 *                             largest_slope = n_slope
 *                             largest_slope_dir = i_n             # <<<<<<<<<<<<<<
 * 
 *                     if largest_slope_dir >= 0:
 */
              __pyx_v_largest_slope_dir = __pyx_v_i_n;

              /* "pygeoprocessing/routing/routing.pyx":1149
 *                         if i_n & 1:
 *                             n_slope *= SQRT2_INV
 *                         if n_slope > largest_slope:             # <<<<<<<<<<<<<<
 *                             largest_slope = n_slope
 *                             largest_slope_dir = i_n
 */
            }
            __pyx_L39_continue:;
          }

          /* "pygeoprocessing/routing/routing.pyx":1153
 *                             largest_slope_dir = i_n
 * 
 *                     if largest_slope_dir >= 0:             # <<<<<<<<<<<<<<
 *                         if largest_slope > 0.0:
 *                             # regular downhill pixel
 */
          __pyx_t_6 = ((__pyx_v_largest_slope_dir >= 0) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1154
 * 
 *                     if largest_slope_dir >= 0:
 *                         if largest_slope > 0.0:             # <<<<<<<<<<<<<<
 *                             # regular downhill pixel
 *                             flow_dir_managed_raster.set(
 */
            __pyx_t_6 = ((__pyx_v_largest_slope > 0.0) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1156
 *                         if largest_slope > 0.0:
 *                             # regular downhill pixel
 *                             flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_q, yi_q, largest_slope_dir)
 *                             plateau_distance_managed_raster.set(
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, __pyx_v_largest_slope_dir);

              /* "pygeoprocessing/routing/routing.pyx":1158
 *                             flow_dir_managed_raster.set(
 *                                 xi_q, yi_q, largest_slope_dir)
 *                             plateau_distance_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_q, yi_q, 0.0)
 *                             drain_queue.push(CoordinateType(xi_q, yi_q))
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, 0.0);

              /* "pygeoprocessing/routing/routing.pyx":1160
 *                             plateau_distance_managed_raster.set(
 *                                 xi_q, yi_q, 0.0)
 *                             drain_queue.push(CoordinateType(xi_q, yi_q))             # <<<<<<<<<<<<<<
 *                         else:
 *                             # must be a nodata drain, save on queue for later
 */
              __pyx_t_32.xi = __pyx_v_xi_q;
              __pyx_t_32.yi = __pyx_v_yi_q;
              __pyx_v_drain_queue.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1154
 * 
 *                     if largest_slope_dir >= 0:
 *                         if largest_slope > 0.0:             # <<<<<<<<<<<<<<
 *                             # regular downhill pixel
 *                             flow_dir_managed_raster.set(
 */
              goto __pyx_L56;
            }

            /* "pygeoprocessing/routing/routing.pyx":1163
 *                         else:
 *                             # must be a nodata drain, save on queue for later
 *                             nodata_drain_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_q, yi_q))
 *                             nodata_flow_dir_queue.push(largest_slope_dir)
 */
            /*else*/ {

              /* "pygeoprocessing/routing/routing.pyx":1164
 *                             # must be a nodata drain, save on queue for later
 *                             nodata_drain_queue.push(
 *                                 CoordinateType(xi_q, yi_q))             # <<<<<<<<<<<<<<
 *                             nodata_flow_dir_queue.push(largest_slope_dir)
 * 
 */
              __pyx_t_32.xi = __pyx_v_xi_q;
              __pyx_t_32.yi = __pyx_v_yi_q;

              /* "pygeoprocessing/routing/routing.pyx":1163
 *                         else:
 *                             # must be a nodata drain, save on queue for later
 *                             nodata_drain_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_q, yi_q))
 *                             nodata_flow_dir_queue.push(largest_slope_dir)
 */
              __pyx_v_nodata_drain_queue.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1165
 *                             nodata_drain_queue.push(
 *                                 CoordinateType(xi_q, yi_q))
 *                             nodata_flow_dir_queue.push(largest_slope_dir)             # <<<<<<<<<<<<<<
 * 
 *                 # if there's no downhill drains, try the nodata drains
 */
              __pyx_v_nodata_flow_dir_queue.push(__pyx_v_largest_slope_dir);
            }
            __pyx_L56:;

            /* "pygeoprocessing/routing/routing.pyx":1153
 *                             largest_slope_dir = i_n
 * 
 *                     if largest_slope_dir >= 0:             # <<<<<<<<<<<<<<
 *                         if largest_slope > 0.0:
 *                             # regular downhill pixel
 */
          }
        }

        /* "pygeoprocessing/routing/routing.pyx":1168
 * 
 *                 # if there's no downhill drains, try the nodata drains
 *                 if drain_queue.empty():             # <<<<<<<<<<<<<<
 *                     # push the nodata drain queue over to the drain queue
 *                     # and set all the flow directions on the nodata drain
 */
        __pyx_t_6 = (__pyx_v_drain_queue.empty() != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1172
 *                     # and set all the flow directions on the nodata drain
 *                     # pixels
 *                     while not nodata_drain_queue.empty():             # <<<<<<<<<<<<<<
 *                         xi_q = nodata_drain_queue.front().xi
 *                         yi_q = nodata_drain_queue.front().yi
 */
          while (1) {
            __pyx_t_6 = ((!(__pyx_v_nodata_drain_queue.empty() != 0)) != 0);
            if (!__pyx_t_6) break;

            /* "pygeoprocessing/routing/routing.pyx":1173
 *                     # pixels
 *                     while not nodata_drain_queue.empty():
 *                         xi_q = nodata_drain_queue.front().xi             # <<<<<<<<<<<<<<
 *                         yi_q = nodata_drain_queue.front().yi
 *                         flow_dir_managed_raster.set(
 */
            __pyx_t_28 = __pyx_v_nodata_drain_queue.front().xi;
            __pyx_v_xi_q = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1174
 *                     while not nodata_drain_queue.empty():
 *                         xi_q = nodata_drain_queue.front().xi
 *                         yi_q = nodata_drain_queue.front().yi             # <<<<<<<<<<<<<<
 *                         flow_dir_managed_raster.set(
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 */
            __pyx_t_28 = __pyx_v_nodata_drain_queue.front().yi;
            __pyx_v_yi_q = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1175
 *                         xi_q = nodata_drain_queue.front().xi
 *                         yi_q = nodata_drain_queue.front().yi
 *                         flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, __pyx_v_nodata_flow_dir_queue.front());

            /* "pygeoprocessing/routing/routing.pyx":1177
 *                         flow_dir_managed_raster.set(
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)             # <<<<<<<<<<<<<<
 *                         drain_queue.push(nodata_drain_queue.front())
 *                         nodata_flow_dir_queue.pop()
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, 0.0);

            /* "pygeoprocessing/routing/routing.pyx":1178
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)
 *                         drain_queue.push(nodata_drain_queue.front())             # <<<<<<<<<<<<<<
 *                         nodata_flow_dir_queue.pop()
 *                         nodata_drain_queue.pop()
 */
            __pyx_v_drain_queue.push(__pyx_v_nodata_drain_queue.front());

            /* "pygeoprocessing/routing/routing.pyx":1179
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)
 *                         drain_queue.push(nodata_drain_queue.front())
 *                         nodata_flow_dir_queue.pop()             # <<<<<<<<<<<<<<
 *                         nodata_drain_queue.pop()
 *                 else:
 */
            __pyx_v_nodata_flow_dir_queue.pop();

            /* "pygeoprocessing/routing/routing.pyx":1180
 *                         drain_queue.push(nodata_drain_queue.front())
 *                         nodata_flow_dir_queue.pop()
 *                         nodata_drain_queue.pop()             # <<<<<<<<<<<<<<
 *                 else:
 *                     # clear the nodata drain queues
 */
            __pyx_v_nodata_drain_queue.pop();
          }

          /* "pygeoprocessing/routing/routing.pyx":1168
 * 
 *                 # if there's no downhill drains, try the nodata drains
 *                 if drain_queue.empty():             # <<<<<<<<<<<<<<
 *                     # push the nodata drain queue over to the drain queue
 *                     # and set all the flow directions on the nodata drain
 */
          goto __pyx_L57;
        }

        /* "pygeoprocessing/routing/routing.pyx":1183
 *                 else:
 *                     # clear the nodata drain queues
 *                     nodata_flow_dir_queue = IntQueueType()             # <<<<<<<<<<<<<<
 *                     nodata_drain_queue = CoordinateQueueType()
 * 
 */
        /*else*/ {
          try {
            __pyx_t_33 = __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType();
          } catch(...) {
            __Pyx_CppExn2PyErr();
            __PYX_ERR(0, 1183, __pyx_L1_error)
          }
          __pyx_v_nodata_flow_dir_queue = __pyx_t_33;

          /* "pygeoprocessing/routing/routing.pyx":1184
 *                     # clear the nodata drain queues
 *                     nodata_flow_dir_queue = IntQueueType()
 *                     nodata_drain_queue = CoordinateQueueType()             # <<<<<<<<<<<<<<
 * 
 *                 # this loop does a BFS from the plateau drain to any other
 */
          try {
            __pyx_t_34 = __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType();
          } catch(...) {
            __Pyx_CppExn2PyErr();
            __PYX_ERR(0, 1184, __pyx_L1_error)
          }
          __pyx_v_nodata_drain_queue = __pyx_t_34;
        }
        __pyx_L57:;

        /* "pygeoprocessing/routing/routing.pyx":1188
 *                 # this loop does a BFS from the plateau drain to any other
 *                 # neighboring undefined pixels
 *                 while not drain_queue.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = drain_queue.front().xi
 *                     yi_q = drain_queue.front().yi
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_drain_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":1189
 *                 # neighboring undefined pixels
 *                 while not drain_queue.empty():
 *                     xi_q = drain_queue.front().xi             # <<<<<<<<<<<<<<
 *                     yi_q = drain_queue.front().yi
 *                     drain_queue.pop()
 */
          __pyx_t_28 = __pyx_v_drain_queue.front().xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1190
 *                 while not drain_queue.empty():
 *                     xi_q = drain_queue.front().xi
 *                     yi_q = drain_queue.front().yi             # <<<<<<<<<<<<<<
 *                     drain_queue.pop()
 * 
 */
          __pyx_t_28 = __pyx_v_drain_queue.front().yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1191
 *                     xi_q = drain_queue.front().xi
 *                     yi_q = drain_queue.front().yi
 *                     drain_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                     drain_distance = plateau_distance_managed_raster.get(
 */
          __pyx_v_drain_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":1193
 *                     drain_queue.pop()
 * 
 *                     drain_distance = plateau_distance_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_q, yi_q)
 * 
 */
          __pyx_v_drain_distance = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q);

          /* "pygeoprocessing/routing/routing.pyx":1196
 *                         xi_q, yi_q)
 * 
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1197
 * 
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":1198
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":1199
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L65_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L65_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1200
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L65_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L65_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1199
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1201
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         n_drain_distance = drain_distance + (
 */
              goto __pyx_L62_continue;

              /* "pygeoprocessing/routing/routing.pyx":1199
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1204
 * 
 *                         n_drain_distance = drain_distance + (
 *                             SQRT2 if i_n & 1 else 1.0)             # <<<<<<<<<<<<<<
 * 
 *                         if dem_managed_raster.get(
 */
            if (((__pyx_v_i_n & 1) != 0)) {
              __pyx_t_8 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2;
            } else {
              __pyx_t_8 = 1.0;
            }

            /* "pygeoprocessing/routing/routing.pyx":1203
 *                             continue
 * 
 *                         n_drain_distance = drain_distance + (             # <<<<<<<<<<<<<<
 *                             SQRT2 if i_n & 1 else 1.0)
 * 
 */
            __pyx_v_n_drain_distance = (__pyx_v_drain_distance + __pyx_t_8);

            /* "pygeoprocessing/routing/routing.pyx":1207
 * 
 *                         if dem_managed_raster.get(
 *                                 xi_n, yi_n) == root_height and (             # <<<<<<<<<<<<<<
 *                                 plateau_distance_managed_raster.get(
 *                                     xi_n, yi_n) > n_drain_distance):
 */
            __pyx_t_7 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == __pyx_v_root_height) != 0);
            if (__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L70_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1209
 *                                 xi_n, yi_n) == root_height and (
 *                                 plateau_distance_managed_raster.get(
 *                                     xi_n, yi_n) > n_drain_distance):             # <<<<<<<<<<<<<<
 *                             # neighbor is at same level and has longer drain
 *                             # flow path than current
 */
            __pyx_t_7 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) > __pyx_v_n_drain_distance) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L70_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1206
 *                             SQRT2 if i_n & 1 else 1.0)
 * 
 *                         if dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n) == root_height and (
 *                                 plateau_distance_managed_raster.get(
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1212
 *                             # neighbor is at same level and has longer drain
 *                             # flow path than current
 *                             flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n, D8_REVERSE_DIRECTION[i_n])
 *                             plateau_distance_managed_raster.set(
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, (__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_i_n]));

              /* "pygeoprocessing/routing/routing.pyx":1214
 *                             flow_dir_managed_raster.set(
 *                                 xi_n, yi_n, D8_REVERSE_DIRECTION[i_n])
 *                             plateau_distance_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n, n_drain_distance)
 *                             drain_queue.push(CoordinateType(xi_n, yi_n))
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, __pyx_v_n_drain_distance);

              /* "pygeoprocessing/routing/routing.pyx":1216
 *                             plateau_distance_managed_raster.set(
 *                                 xi_n, yi_n, n_drain_distance)
 *                             drain_queue.push(CoordinateType(xi_n, yi_n))             # <<<<<<<<<<<<<<
 *     dem_band = None
 *     dem_raster = None
 */
              __pyx_t_32.xi = __pyx_v_xi_n;
              __pyx_t_32.yi = __pyx_v_yi_n;
              __pyx_v_drain_queue.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1206
 *                             SQRT2 if i_n & 1 else 1.0)
 * 
 *                         if dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n) == root_height and (
 *                                 plateau_distance_managed_raster.get(
 */
            }
            __pyx_L62_continue:;
          }
        }
        __pyx_L27_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":1030
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1217
 *                                 xi_n, yi_n, n_drain_distance)
 *                             drain_queue.push(CoordinateType(xi_n, yi_n))
 *     dem_band = None             # <<<<<<<<<<<<<<
 *     dem_raster = None
 *     flow_dir_managed_raster.close()
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_dem_band, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":1218
 *                             drain_queue.push(CoordinateType(xi_n, yi_n))
 *     dem_band = None
 *     dem_raster = None             # <<<<<<<<<<<<<<
 *     flow_dir_managed_raster.close()
 *     flat_region_mask_managed_raster.close()
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_dem_raster, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":1219
 *     dem_band = None
 *     dem_raster = None
 *     flow_dir_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flat_region_mask_managed_raster.close()
 *     dem_managed_raster.close()
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1219, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1219, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1220
 *     dem_raster = None
 *     flow_dir_managed_raster.close()
 *     flat_region_mask_managed_raster.close()             # <<<<<<<<<<<<<<
 *     dem_managed_raster.close()
 *     plateau_distance_managed_raster.close()
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flat_region_mask_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1220, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1220, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1221
 *     flow_dir_managed_raster.close()
 *     flat_region_mask_managed_raster.close()
 *     dem_managed_raster.close()             # <<<<<<<<<<<<<<
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dem_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1221, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1221, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1222
 *     flat_region_mask_managed_raster.close()
 *     dem_managed_raster.close()
 *     plateau_distance_managed_raster.close()             # <<<<<<<<<<<<<<
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_plateau_distance_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1222, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1222, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1222, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1223
 *     dem_managed_raster.close()
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)             # <<<<<<<<<<<<<<
 *     LOGGER.info('%.1f%% complete', 100.0)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_shutil); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1223, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1223, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_16);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_16, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_v_working_dir_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_16)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_working_dir_path};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1223, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_working_dir_path};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1223, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1223, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_working_dir_path);
      __Pyx_GIVEREF(__pyx_v_working_dir_path);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_working_dir_path);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1223, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1224
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":865
 * 
 * 
 * def flow_dir_d8(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path,
 *         working_dir=None,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_dir_d8", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dem_buffer_array);
  __Pyx_XDECREF(__pyx_v_dem_raster_info);
  __Pyx_XDECREF(__pyx_v_base_nodata);
  __Pyx_XDECREF(__pyx_v_working_dir_path);
  __Pyx_XDECREF(__pyx_v_flat_region_mask_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_flat_region_mask_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster);
  __Pyx_XDECREF(__pyx_v_plateau_distance_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_plateau_distance_managed_raster);
  __Pyx_XDECREF(__pyx_v_compatable_dem_raster_path_band);
  __Pyx_XDECREF(__pyx_v_dem_block_xsize);
  __Pyx_XDECREF(__pyx_v_dem_block_ysize);
  __Pyx_XDECREF(__pyx_v_geotiff_driver);
  __Pyx_XDECREF(__pyx_v_dem_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_dem_managed_raster);
  __Pyx_XDECREF(__pyx_v_dem_band);
  __Pyx_XDECREF(__pyx_v_offset_dict);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_modified_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":1227
 * 
 * 
 * def flow_accumulation_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_6flow_accumulation_d8[] = "D8 flow accumulation.\n\n    Parameters:\n        flow_dir_raster_path_band (tuple): a path, band number tuple\n            for a flow accumulation raster whose pixels indicate the flow\n            out of a pixel in one of 8 directions in the following\n            configuration:\n                321\n                4x0\n                567\n        target_flow_accum_raster_path (string): path to flow\n            accumulation raster created by this call. After this call, the\n            value of each pixel will be 1 plus the number of upstream pixels\n            that drain to that pixel. Note the target type of this raster\n            is a 64 bit float so there is minimal risk of overflow and the\n            possibility of handling a float dtype in\n            `weight_raster_path_band`.\n        weight_raster_path_band (tuple): optional path and band number to a\n            raster that will be used as the per-pixel flow accumulation\n            weight. If `None`, 1 is the default flow accumulation weight.\n            This raster must be the same dimensions as\n            `flow_dir_mfd_raster_path_band`.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8 = {"flow_accumulation_d8", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_6flow_accumulation_d8};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_flow_dir_raster_path_band = 0;
  PyObject *__pyx_v_target_flow_accum_raster_path = 0;
  PyObject *__pyx_v_weight_raster_path_band = 0;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("flow_accumulation_d8 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_raster_path_band,&__pyx_n_s_target_flow_accum_raster_path,&__pyx_n_s_weight_raster_path_band,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pygeoprocessing/routing/routing.pyx":1229
 * def flow_accumulation_d8(
 *         flow_dir_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 *     """D8 flow accumulation.
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = __pyx_k__13;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_flow_accum_raster_path)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("flow_accumulation_d8", 0, 2, 4, 1); __PYX_ERR(0, 1227, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_weight_raster_path_band);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "flow_accumulation_d8") < 0)) __PYX_ERR(0, 1227, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_flow_dir_raster_path_band = values[0];
    __pyx_v_target_flow_accum_raster_path = values[1];
    __pyx_v_weight_raster_path_band = values[2];
    __pyx_v_gtiff_creation_options = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("flow_accumulation_d8", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1227, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_accumulation_d8", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_6flow_accumulation_d8(__pyx_self, __pyx_v_flow_dir_raster_path_band, __pyx_v_target_flow_accum_raster_path, __pyx_v_weight_raster_path_band, __pyx_v_gtiff_creation_options);

  /* "pygeoprocessing/routing/routing.pyx":1227
 * 
 * 
 * def flow_accumulation_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_6flow_accumulation_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_raster_path_band, PyObject *__pyx_v_target_flow_accum_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options) {
  PyArrayObject *__pyx_v_flow_dir_buffer_array = 0;
  int __pyx_v_win_ysize;
  int __pyx_v_win_xsize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_xi_root;
  int __pyx_v_yi_root;
  int __pyx_v_i_n;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  int __pyx_v_flow_dir;
  int __pyx_v_upstream_flow_dir;
  int __pyx_v_flow_dir_nodata;
  double __pyx_v_upstream_flow_accum;
  double __pyx_v_weight_val;
  double __pyx_v_weight_nodata;
  std::stack<struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType>  __pyx_v_search_stack;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_v_flow_pixel;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  time_t __pyx_v_last_log_time;
  double __pyx_v_flow_accum_nodata;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_accum_managed_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL;
  PyObject *__pyx_v_flow_dir_raster = NULL;
  PyObject *__pyx_v_flow_dir_band = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_weight_raster = 0;
  PyObject *__pyx_v_raw_weight_nodata = NULL;
  PyObject *__pyx_v_flow_dir_raster_info = NULL;
  PyObject *__pyx_v_tmp_flow_dir_nodata = NULL;
  PyObject *__pyx_v_offset_dict = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_modified_offset_dict = NULL;
  long __pyx_v_preempted;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_flow_dir_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_flow_dir_buffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  double __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  long __pyx_t_23;
  long __pyx_t_24;
  long __pyx_t_25;
  long __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  int __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  Py_ssize_t __pyx_t_31;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_32;
  __Pyx_RefNannySetupContext("flow_accumulation_d8", 0);
  __pyx_pybuffer_flow_dir_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_flow_dir_buffer_array.refcount = 0;
  __pyx_pybuffernd_flow_dir_buffer_array.data = NULL;
  __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer = &__pyx_pybuffer_flow_dir_buffer_array;

  /* "pygeoprocessing/routing/routing.pyx":1285
 *     # come from a predefined flow accumulation weight raster
 *     cdef double weight_val
 *     cdef double weight_nodata = IMPROBABLE_FLOAT_NODATA  # set to something             # <<<<<<<<<<<<<<
 * 
 *     # `search_stack` is used to walk upstream to calculate flow accumulation
 */
  __pyx_v_weight_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;

  /* "pygeoprocessing/routing/routing.pyx":1297
 *     # used for time-delayed logging
 *     cdef time_t last_log_time
 *     last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_raster_path_band):
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":1299
 *     last_log_time = ctime(NULL)
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_raster_path_band):             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_flow_dir_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1299, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_flow_dir_raster_path_band};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1299, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_flow_dir_raster_path_band};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1299, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1299, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_flow_dir_raster_path_band);
      __Pyx_GIVEREF(__pyx_v_flow_dir_raster_path_band);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_flow_dir_raster_path_band);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1299, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1299, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "pygeoprocessing/routing/routing.pyx":1301
 *     if not _is_raster_path_band_formatted(flow_dir_raster_path_band):
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (             # <<<<<<<<<<<<<<
 *                 flow_dir_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_is_supposed_to_be_a_raster_ba, __pyx_v_flow_dir_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1301, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "pygeoprocessing/routing/routing.pyx":1300
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_raster_path_band):
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_raster_path_band))
 */
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1300, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1300, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":1299
 *     last_log_time = ctime(NULL)
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_raster_path_band):             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":1303
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         raise ValueError(
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1303, __pyx_L1_error)
  if (__pyx_t_5) {
  } else {
    __pyx_t_6 = __pyx_t_5;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1303, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":1304
 *                 flow_dir_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(
 *             weight_raster_path_band):             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (
 */
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_weight_raster_path_band};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_weight_raster_path_band};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_INCREF(__pyx_v_weight_raster_path_band);
      __Pyx_GIVEREF(__pyx_v_weight_raster_path_band);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_weight_raster_path_band);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1303
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         raise ValueError(
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1303, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = ((!__pyx_t_5) != 0);
  __pyx_t_6 = __pyx_t_7;
  __pyx_L5_bool_binop_done:;
  if (unlikely(__pyx_t_6)) {

    /* "pygeoprocessing/routing/routing.pyx":1306
 *             weight_raster_path_band):
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band))
 * 
 */
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_is_supposed_to_be_a_raster_ba, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1306, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "pygeoprocessing/routing/routing.pyx":1305
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(
 *             weight_raster_path_band):
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 weight_raster_path_band))
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1305, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":1303
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         raise ValueError(
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":1309
 *                 weight_raster_path_band))
 * 
 *     flow_accum_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_raster_path_band[0], target_flow_accum_raster_path,
 */
  __pyx_v_flow_accum_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;

  /* "pygeoprocessing/routing/routing.pyx":1310
 * 
 *     flow_accum_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1311
 *     flow_accum_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_raster_path_band[0], target_flow_accum_raster_path,             # <<<<<<<<<<<<<<
 *         gdal.GDT_Float64, [flow_accum_nodata],
 *         fill_value_list=[flow_accum_nodata],
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":1312
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],             # <<<<<<<<<<<<<<
 *         fill_value_list=[flow_accum_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_flow_accum_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1312, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1310
 * 
 *     flow_accum_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_target_flow_accum_raster_path);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_8);
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1313
 *         flow_dir_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 *         fill_value_list=[flow_accum_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_accum_managed_raster = _ManagedRaster(
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1313, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_flow_accum_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1313, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1313, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_fill_value_list, __pyx_t_1) < 0) __PYX_ERR(0, 1313, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1314
 *         gdal.GDT_Float64, [flow_accum_nodata],
 *         fill_value_list=[flow_accum_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     flow_accum_managed_raster = _ManagedRaster(
 *         target_flow_accum_raster_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 1313, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1310
 * 
 *     flow_accum_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1315
 *         fill_value_list=[flow_accum_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_accum_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         target_flow_accum_raster_path, 1, 1)
 * 
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_target_flow_accum_raster_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_1);
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1315, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_flow_accum_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1319
 * 
 *     flow_dir_managed_raster = _ManagedRaster(
 *         flow_dir_raster_path_band[0], flow_dir_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *     flow_dir_raster = gdal.OpenEx(
 *         flow_dir_raster_path_band[0], gdal.OF_RASTER)
 */
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1319, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1319, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":1318
 *         target_flow_accum_raster_path, 1, 1)
 * 
 *     flow_dir_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[0], flow_dir_raster_path_band[1], 0)
 *     flow_dir_raster = gdal.OpenEx(
 */
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1318, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_0);
  __pyx_t_8 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1318, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1320
 *     flow_dir_managed_raster = _ManagedRaster(
 *         flow_dir_raster_path_band[0], flow_dir_raster_path_band[1], 0)
 *     flow_dir_raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_band = flow_dir_raster.GetRasterBand(
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1320, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1321
 *         flow_dir_raster_path_band[0], flow_dir_raster_path_band[1], 0)
 *     flow_dir_raster = gdal.OpenEx(
 *         flow_dir_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     flow_dir_band = flow_dir_raster.GetRasterBand(
 *         flow_dir_raster_path_band[1])
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_9 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
      __pyx_t_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_3, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1320, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_3, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1320, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  {
    __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1320, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_flow_dir_raster = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1322
 *     flow_dir_raster = gdal.OpenEx(
 *         flow_dir_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_band = flow_dir_raster.GetRasterBand(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[1])
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1322, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":1323
 *         flow_dir_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_band = flow_dir_raster.GetRasterBand(
 *         flow_dir_raster_path_band[1])             # <<<<<<<<<<<<<<
 * 
 *     cdef _ManagedRaster weight_raster = None
 */
  __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1323, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1322, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1322, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1322, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1322, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1322, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_flow_dir_band = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1325
 *         flow_dir_raster_path_band[1])
 * 
 *     cdef _ManagedRaster weight_raster = None             # <<<<<<<<<<<<<<
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_weight_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)Py_None);

  /* "pygeoprocessing/routing/routing.pyx":1326
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1326, __pyx_L1_error)
  if (__pyx_t_6) {

    /* "pygeoprocessing/routing/routing.pyx":1328
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1328, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "pygeoprocessing/routing/routing.pyx":1327
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 */
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1327, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_0);
    __pyx_t_1 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1327, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8));
    __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1329
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1330
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_10) {
      __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1329, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_8);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_3};
        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1329, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_3};
        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1329, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else
      #endif
      {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1329, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); __pyx_t_10 = NULL;
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1329, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_8, __pyx_n_s_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1331
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata
 */
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1331, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_t_8, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1331, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1330
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_raw_weight_nodata = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1332
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 * 
 */
    __pyx_t_6 = (__pyx_v_raw_weight_nodata != Py_None);
    __pyx_t_7 = (__pyx_t_6 != 0);
    if (__pyx_t_7) {

      /* "pygeoprocessing/routing/routing.pyx":1333
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata             # <<<<<<<<<<<<<<
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 */
      __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_v_raw_weight_nodata); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1333, __pyx_L1_error)
      __pyx_v_weight_nodata = __pyx_t_11;

      /* "pygeoprocessing/routing/routing.pyx":1332
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 * 
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":1326
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":1335
 *             weight_nodata = raw_weight_nodata
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1336
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 * 
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1335, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_8);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1335, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1335, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1335, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1335, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_flow_dir_raster_info = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1337
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     tmp_flow_dir_nodata = flow_dir_raster_info['nodata'][
 */
  __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
    PyObject* sequence = __pyx_t_8;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1337, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_10);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1337, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1337, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    #endif
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1337, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_12 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_12(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L9_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_4); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_10);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_4), 2) < 0) __PYX_ERR(0, 1337, __pyx_L1_error)
    __pyx_t_12 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L10_unpacking_done;
    __pyx_L9_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_12 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1337, __pyx_L1_error)
    __pyx_L10_unpacking_done:;
  }
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1337, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1337, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_v_raster_x_size = __pyx_t_9;
  __pyx_v_raster_y_size = __pyx_t_13;

  /* "pygeoprocessing/routing/routing.pyx":1339
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 * 
 *     tmp_flow_dir_nodata = flow_dir_raster_info['nodata'][             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[1]-1]
 *     if tmp_flow_dir_nodata is None:
 */
  __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_s_nodata); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":1340
 * 
 *     tmp_flow_dir_nodata = flow_dir_raster_info['nodata'][
 *         flow_dir_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *     if tmp_flow_dir_nodata is None:
 *         flow_dir_nodata = 128
 */
  __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_10, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1339
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 * 
 *     tmp_flow_dir_nodata = flow_dir_raster_info['nodata'][             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band[1]-1]
 *     if tmp_flow_dir_nodata is None:
 */
  __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_tmp_flow_dir_nodata = __pyx_t_10;
  __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1341
 *     tmp_flow_dir_nodata = flow_dir_raster_info['nodata'][
 *         flow_dir_raster_path_band[1]-1]
 *     if tmp_flow_dir_nodata is None:             # <<<<<<<<<<<<<<
 *         flow_dir_nodata = 128
 *     else:
 */
  __pyx_t_7 = (__pyx_v_tmp_flow_dir_nodata == Py_None);
  __pyx_t_6 = (__pyx_t_7 != 0);
  if (__pyx_t_6) {

    /* "pygeoprocessing/routing/routing.pyx":1342
 *         flow_dir_raster_path_band[1]-1]
 *     if tmp_flow_dir_nodata is None:
 *         flow_dir_nodata = 128             # <<<<<<<<<<<<<<
 *     else:
 *         flow_dir_nodata = tmp_flow_dir_nodata
 */
    __pyx_v_flow_dir_nodata = 0x80;

    /* "pygeoprocessing/routing/routing.pyx":1341
 *     tmp_flow_dir_nodata = flow_dir_raster_info['nodata'][
 *         flow_dir_raster_path_band[1]-1]
 *     if tmp_flow_dir_nodata is None:             # <<<<<<<<<<<<<<
 *         flow_dir_nodata = 128
 *     else:
 */
    goto __pyx_L11;
  }

  /* "pygeoprocessing/routing/routing.pyx":1344
 *         flow_dir_nodata = 128
 *     else:
 *         flow_dir_nodata = tmp_flow_dir_nodata             # <<<<<<<<<<<<<<
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 */
  /*else*/ {
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_v_tmp_flow_dir_nodata); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1344, __pyx_L1_error)
    __pyx_v_flow_dir_nodata = __pyx_t_13;
  }
  __pyx_L11:;

  /* "pygeoprocessing/routing/routing.pyx":1347
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1348
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):             # <<<<<<<<<<<<<<
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 */
  __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_flow_dir_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);

  /* "pygeoprocessing/routing/routing.pyx":1347
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_10);
  __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1348
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):             # <<<<<<<<<<<<<<
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 */
  __pyx_t_10 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 1348, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1348, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1347
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, __pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_10 = __pyx_t_4; __Pyx_INCREF(__pyx_t_10); __pyx_t_14 = 0;
    __pyx_t_15 = NULL;
  } else {
    __pyx_t_14 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_15 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1347, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_15)) {
      if (likely(PyList_CheckExact(__pyx_t_10))) {
        if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_10)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_14); __Pyx_INCREF(__pyx_t_4); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1347, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_10, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_14); __Pyx_INCREF(__pyx_t_4); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 1347, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_10, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1347, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_15(__pyx_t_10);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1347, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1349
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1349, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1349, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_win_xsize = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":1350
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']             # <<<<<<<<<<<<<<
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1350, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1350, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_win_ysize = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":1351
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']             # <<<<<<<<<<<<<<
 *         yoff = offset_dict['yoff']
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1351, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1351, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_xoff = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":1352
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']             # <<<<<<<<<<<<<<
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1352, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1352, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_yoff = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":1354
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    __pyx_t_6 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
    if (__pyx_t_6) {

      /* "pygeoprocessing/routing/routing.pyx":1355
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
      __pyx_v_last_log_time = time(NULL);

      /* "pygeoprocessing/routing/routing.pyx":1356
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))
 */
      __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1356, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pygeoprocessing/routing/routing.pyx":1357
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1357, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1357, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1357, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);

      /* "pygeoprocessing/routing/routing.pyx":1358
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 */
      __pyx_t_3 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1357, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);

      /* "pygeoprocessing/routing/routing.pyx":1357
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1357, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_13 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
          __pyx_t_13 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_2};
        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1357, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_2};
        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1357, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      {
        __pyx_t_8 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1357, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
        PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_13, __pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_13, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1357, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "pygeoprocessing/routing/routing.pyx":1354
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":1361
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1362
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array[:] = flow_dir_nodata
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
    __pyx_t_8 = 0;
    __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1361
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1363
 *         flow_dir_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)             # <<<<<<<<<<<<<<
 *         flow_dir_buffer_array[:] = flow_dir_nodata
 * 
 */
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_uint8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1363, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 1363, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1361
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1361, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer);
      __pyx_t_13 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_13 < 0)) {
        PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_flow_dir_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
        }
        __pyx_t_17 = __pyx_t_18 = __pyx_t_19 = 0;
      }
      __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1361, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __Pyx_XDECREF_SET(__pyx_v_flow_dir_buffer_array, ((PyArrayObject *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1364
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array[:] = flow_dir_nodata             # <<<<<<<<<<<<<<
 * 
 *         # attempt to expand read block by a pixel boundary
 */
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1364, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_slice__14, __pyx_t_3) < 0)) __PYX_ERR(0, 1364, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1367
 * 
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1367, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "pygeoprocessing/routing/routing.pyx":1368
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)             # <<<<<<<<<<<<<<
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.uint8)
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1368, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1368, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = NULL;
    __pyx_t_13 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_13 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_1};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_1};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else
    #endif
    {
      __pyx_t_20 = PyTuple_New(3+__pyx_t_13); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      if (__pyx_t_8) {
        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_8); __pyx_t_8 = NULL;
      }
      __Pyx_INCREF(__pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_v_offset_dict);
      PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_13, __pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_13, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_13, __pyx_t_1);
      __pyx_t_2 = 0;
      __pyx_t_1 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1367, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_20);
      #else
      __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_12 = Py_TYPE(__pyx_t_1)->tp_iternext;
      index = 0; __pyx_t_4 = __pyx_t_12(__pyx_t_1); if (unlikely(!__pyx_t_4)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      index = 1; __pyx_t_20 = __pyx_t_12(__pyx_t_1); if (unlikely(!__pyx_t_20)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_20);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1367, __pyx_L1_error)
      __pyx_t_12 = NULL;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L16_unpacking_done;
      __pyx_L15_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1367, __pyx_L1_error)
      __pyx_L16_unpacking_done:;
    }

    /* "pygeoprocessing/routing/routing.pyx":1367
 * 
 *         # attempt to expand read block by a pixel boundary
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 */
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1367, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_8 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_21 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_21);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_8,&__pyx_t_21};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1367, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_8,&__pyx_t_21};
      __pyx_t_22 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 1367, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_12 = Py_TYPE(__pyx_t_22)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_12(__pyx_t_22); if (unlikely(!item)) goto __pyx_L17_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_22), 4) < 0) __PYX_ERR(0, 1367, __pyx_L1_error)
      __pyx_t_12 = NULL;
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      goto __pyx_L18_unpacking_done;
      __pyx_L17_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      __pyx_t_12 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1367, __pyx_L1_error)
      __pyx_L18_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_21);
    __pyx_t_21 = 0;
    __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_20);
    __pyx_t_20 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1369
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.uint8)
 * 
 */
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1369, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);

    /* "pygeoprocessing/routing/routing.pyx":1370
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.uint8)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 1370, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_4 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1370, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_4 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1369, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    }

    /* "pygeoprocessing/routing/routing.pyx":1369
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.uint8)
 * 
 */
    __pyx_t_21 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1369, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1370
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.uint8)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_t_21 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_uint8); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1370, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_t_21 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_21)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_21);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_21) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_20); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1370, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_t_20};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1370, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_t_20};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1370, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      } else
      #endif
      {
        __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1370, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_21); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_21); __pyx_t_21 = NULL;
        __Pyx_GIVEREF(__pyx_t_20);
        PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_20);
        __pyx_t_20 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1370, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1369
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.uint8)
 * 
 */
    __pyx_t_4 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1369, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1369, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_20 = PyTuple_New(2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1369, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_8);
    __pyx_t_4 = 0;
    __pyx_t_8 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_t_20, __pyx_t_3) < 0)) __PYX_ERR(0, 1369, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1373
 * 
 *         # ensure these are set for the complier
 *         xi_n = -1             # <<<<<<<<<<<<<<
 *         yi_n = -1
 * 
 */
    __pyx_v_xi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":1374
 *         # ensure these are set for the complier
 *         xi_n = -1
 *         yi_n = -1             # <<<<<<<<<<<<<<
 * 
 *         # search block for to set flow direction
 */
    __pyx_v_yi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":1377
 * 
 *         # search block for to set flow direction
 *         for yi in range(1, win_ysize+1):             # <<<<<<<<<<<<<<
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir = flow_dir_buffer_array[yi, xi]
 */
    __pyx_t_23 = (__pyx_v_win_ysize + 1);
    __pyx_t_24 = __pyx_t_23;
    for (__pyx_t_13 = 1; __pyx_t_13 < __pyx_t_24; __pyx_t_13+=1) {
      __pyx_v_yi = __pyx_t_13;

      /* "pygeoprocessing/routing/routing.pyx":1378
 *         # search block for to set flow direction
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):             # <<<<<<<<<<<<<<
 *                 flow_dir = flow_dir_buffer_array[yi, xi]
 *                 if flow_dir == flow_dir_nodata:
 */
      __pyx_t_25 = (__pyx_v_win_xsize + 1);
      __pyx_t_26 = __pyx_t_25;
      for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_26; __pyx_t_9+=1) {
        __pyx_v_xi = __pyx_t_9;

        /* "pygeoprocessing/routing/routing.pyx":1379
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir = flow_dir_buffer_array[yi, xi]             # <<<<<<<<<<<<<<
 *                 if flow_dir == flow_dir_nodata:
 *                     continue
 */
        __pyx_t_27 = __pyx_v_yi;
        __pyx_t_28 = __pyx_v_xi;
        __pyx_t_29 = -1;
        if (__pyx_t_27 < 0) {
          __pyx_t_27 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_27 < 0)) __pyx_t_29 = 0;
        } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0;
        if (__pyx_t_28 < 0) {
          __pyx_t_28 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_28 < 0)) __pyx_t_29 = 1;
        } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape)) __pyx_t_29 = 1;
        if (unlikely(__pyx_t_29 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_29);
          __PYX_ERR(0, 1379, __pyx_L1_error)
        }
        __pyx_v_flow_dir = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides));

        /* "pygeoprocessing/routing/routing.pyx":1380
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir = flow_dir_buffer_array[yi, xi]
 *                 if flow_dir == flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        __pyx_t_6 = ((__pyx_v_flow_dir == __pyx_v_flow_dir_nodata) != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1381
 *                 flow_dir = flow_dir_buffer_array[yi, xi]
 *                 if flow_dir == flow_dir_nodata:
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*flow_dir]
 */
          goto __pyx_L21_continue;

          /* "pygeoprocessing/routing/routing.pyx":1380
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir = flow_dir_buffer_array[yi, xi]
 *                 if flow_dir == flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1383
 *                     continue
 * 
 *                 xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*flow_dir]             # <<<<<<<<<<<<<<
 *                 yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*flow_dir+1]
 * 
 */
        __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_flow_dir)]));

        /* "pygeoprocessing/routing/routing.pyx":1384
 * 
 *                 xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*flow_dir]
 *                 yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*flow_dir+1]             # <<<<<<<<<<<<<<
 * 
 *                 if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata:
 */
        __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_flow_dir) + 1)]));

        /* "pygeoprocessing/routing/routing.pyx":1386
 *                 yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*flow_dir+1]
 * 
 *                 if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                     xi_root = xi-1+xoff
 *                     yi_root = yi-1+yoff
 */
        __pyx_t_30 = __pyx_v_yi_n;
        __pyx_t_31 = __pyx_v_xi_n;
        __pyx_t_29 = -1;
        if (__pyx_t_30 < 0) {
          __pyx_t_30 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_30 < 0)) __pyx_t_29 = 0;
        } else if (unlikely(__pyx_t_30 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0;
        if (__pyx_t_31 < 0) {
          __pyx_t_31 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_31 < 0)) __pyx_t_29 = 1;
        } else if (unlikely(__pyx_t_31 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape)) __pyx_t_29 = 1;
        if (unlikely(__pyx_t_29 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_29);
          __PYX_ERR(0, 1386, __pyx_L1_error)
        }
        __pyx_t_6 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides, __pyx_t_31, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides)) == __pyx_v_flow_dir_nodata) != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1387
 * 
 *                 if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata:
 *                     xi_root = xi-1+xoff             # <<<<<<<<<<<<<<
 *                     yi_root = yi-1+yoff
 * 
 */
          __pyx_v_xi_root = ((__pyx_v_xi - 1) + __pyx_v_xoff);

          /* "pygeoprocessing/routing/routing.pyx":1388
 *                 if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata:
 *                     xi_root = xi-1+xoff
 *                     yi_root = yi-1+yoff             # <<<<<<<<<<<<<<
 * 
 *                     if weight_raster is not None:
 */
          __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff);

          /* "pygeoprocessing/routing/routing.pyx":1390
 *                     yi_root = yi-1+yoff
 * 
 *                     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                         weight_val = <double>weight_raster.get(
 *                             xi_root, yi_root)
 */
          __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
          __pyx_t_7 = (__pyx_t_6 != 0);
          if (__pyx_t_7) {

            /* "pygeoprocessing/routing/routing.pyx":1391
 * 
 *                     if weight_raster is not None:
 *                         weight_val = <double>weight_raster.get(             # <<<<<<<<<<<<<<
 *                             xi_root, yi_root)
 *                         if is_close(weight_val, weight_nodata):
 */
            __pyx_v_weight_val = ((double)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_weight_raster, __pyx_v_xi_root, __pyx_v_yi_root));

            /* "pygeoprocessing/routing/routing.pyx":1393
 *                         weight_val = <double>weight_raster.get(
 *                             xi_root, yi_root)
 *                         if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                             weight_val = 0.0
 *                     else:
 */
            __pyx_t_7 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_weight_val, __pyx_v_weight_nodata) != 0);
            if (__pyx_t_7) {

              /* "pygeoprocessing/routing/routing.pyx":1394
 *                             xi_root, yi_root)
 *                         if is_close(weight_val, weight_nodata):
 *                             weight_val = 0.0             # <<<<<<<<<<<<<<
 *                     else:
 *                         weight_val = 1.0
 */
              __pyx_v_weight_val = 0.0;

              /* "pygeoprocessing/routing/routing.pyx":1393
 *                         weight_val = <double>weight_raster.get(
 *                             xi_root, yi_root)
 *                         if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                             weight_val = 0.0
 *                     else:
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1390
 *                     yi_root = yi-1+yoff
 * 
 *                     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                         weight_val = <double>weight_raster.get(
 *                             xi_root, yi_root)
 */
            goto __pyx_L25;
          }

          /* "pygeoprocessing/routing/routing.pyx":1396
 *                             weight_val = 0.0
 *                     else:
 *                         weight_val = 1.0             # <<<<<<<<<<<<<<
 *                     search_stack.push(
 *                         FlowPixelType(xi_root, yi_root, 0, weight_val))
 */
          /*else*/ {
            __pyx_v_weight_val = 1.0;
          }
          __pyx_L25:;

          /* "pygeoprocessing/routing/routing.pyx":1398
 *                         weight_val = 1.0
 *                     search_stack.push(
 *                         FlowPixelType(xi_root, yi_root, 0, weight_val))             # <<<<<<<<<<<<<<
 * 
 *                 while not search_stack.empty():
 */
          __pyx_t_32.xi = __pyx_v_xi_root;
          __pyx_t_32.yi = __pyx_v_yi_root;
          __pyx_t_32.last_flow_dir = 0;
          __pyx_t_32.value = __pyx_v_weight_val;

          /* "pygeoprocessing/routing/routing.pyx":1397
 *                     else:
 *                         weight_val = 1.0
 *                     search_stack.push(             # <<<<<<<<<<<<<<
 *                         FlowPixelType(xi_root, yi_root, 0, weight_val))
 * 
 */
          __pyx_v_search_stack.push(__pyx_t_32);

          /* "pygeoprocessing/routing/routing.pyx":1386
 *                 yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*flow_dir+1]
 * 
 *                 if flow_dir_buffer_array[yi_n, xi_n] == flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                     xi_root = xi-1+xoff
 *                     yi_root = yi-1+yoff
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1400
 *                         FlowPixelType(xi_root, yi_root, 0, weight_val))
 * 
 *                 while not search_stack.empty():             # <<<<<<<<<<<<<<
 *                     flow_pixel = search_stack.top()
 *                     search_stack.pop()
 */
        while (1) {
          __pyx_t_7 = ((!(__pyx_v_search_stack.empty() != 0)) != 0);
          if (!__pyx_t_7) break;

          /* "pygeoprocessing/routing/routing.pyx":1401
 * 
 *                 while not search_stack.empty():
 *                     flow_pixel = search_stack.top()             # <<<<<<<<<<<<<<
 *                     search_stack.pop()
 * 
 */
          __pyx_v_flow_pixel = __pyx_v_search_stack.top();

          /* "pygeoprocessing/routing/routing.pyx":1402
 *                 while not search_stack.empty():
 *                     flow_pixel = search_stack.top()
 *                     search_stack.pop()             # <<<<<<<<<<<<<<
 * 
 *                     preempted = 0
 */
          __pyx_v_search_stack.pop();

          /* "pygeoprocessing/routing/routing.pyx":1404
 *                     search_stack.pop()
 * 
 *                     preempted = 0             # <<<<<<<<<<<<<<
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 */
          __pyx_v_preempted = 0;

          /* "pygeoprocessing/routing/routing.pyx":1405
 * 
 *                     preempted = 0
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):             # <<<<<<<<<<<<<<
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_29 = __pyx_v_flow_pixel.last_flow_dir; __pyx_t_29 < 8; __pyx_t_29+=1) {
            __pyx_v_i_n = __pyx_t_29;

            /* "pygeoprocessing/routing/routing.pyx":1406
 *                     preempted = 0
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_xi_n = (__pyx_v_flow_pixel.xi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":1407
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 */
            __pyx_v_yi_n = (__pyx_v_flow_pixel.yi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":1408
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 */
            __pyx_t_6 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_6) {
            } else {
              __pyx_t_7 = __pyx_t_6;
              goto __pyx_L32_bool_binop_done;
            }
            __pyx_t_6 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_6) {
            } else {
              __pyx_t_7 = __pyx_t_6;
              goto __pyx_L32_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1409
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             # no upstream here
 *                             continue
 */
            __pyx_t_6 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_6) {
            } else {
              __pyx_t_7 = __pyx_t_6;
              goto __pyx_L32_bool_binop_done;
            }
            __pyx_t_6 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_7 = __pyx_t_6;
            __pyx_L32_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1408
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 */
            if (__pyx_t_7) {

              /* "pygeoprocessing/routing/routing.pyx":1411
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 *                             continue             # <<<<<<<<<<<<<<
 *                         upstream_flow_dir = <int>flow_dir_managed_raster.get(
 *                             xi_n, yi_n)
 */
              goto __pyx_L29_continue;

              /* "pygeoprocessing/routing/routing.pyx":1408
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1412
 *                             # no upstream here
 *                             continue
 *                         upstream_flow_dir = <int>flow_dir_managed_raster.get(             # <<<<<<<<<<<<<<
 *                             xi_n, yi_n)
 *                         if upstream_flow_dir == flow_dir_nodata or (
 */
            __pyx_v_upstream_flow_dir = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n));

            /* "pygeoprocessing/routing/routing.pyx":1414
 *                         upstream_flow_dir = <int>flow_dir_managed_raster.get(
 *                             xi_n, yi_n)
 *                         if upstream_flow_dir == flow_dir_nodata or (             # <<<<<<<<<<<<<<
 *                                 upstream_flow_dir !=
 *                                 D8_REVERSE_DIRECTION[i_n]):
 */
            __pyx_t_6 = ((__pyx_v_upstream_flow_dir == __pyx_v_flow_dir_nodata) != 0);
            if (!__pyx_t_6) {
            } else {
              __pyx_t_7 = __pyx_t_6;
              goto __pyx_L37_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1415
 *                             xi_n, yi_n)
 *                         if upstream_flow_dir == flow_dir_nodata or (
 *                                 upstream_flow_dir !=             # <<<<<<<<<<<<<<
 *                                 D8_REVERSE_DIRECTION[i_n]):
 *                             # no upstream here
 */
            __pyx_t_6 = ((__pyx_v_upstream_flow_dir != (__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_i_n])) != 0);
            __pyx_t_7 = __pyx_t_6;
            __pyx_L37_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1414
 *                         upstream_flow_dir = <int>flow_dir_managed_raster.get(
 *                             xi_n, yi_n)
 *                         if upstream_flow_dir == flow_dir_nodata or (             # <<<<<<<<<<<<<<
 *                                 upstream_flow_dir !=
 *                                 D8_REVERSE_DIRECTION[i_n]):
 */
            if (__pyx_t_7) {

              /* "pygeoprocessing/routing/routing.pyx":1418
 *                                 D8_REVERSE_DIRECTION[i_n]):
 *                             # no upstream here
 *                             continue             # <<<<<<<<<<<<<<
 *                         upstream_flow_accum = <double>(
 *                             flow_accum_managed_raster.get(xi_n, yi_n))
 */
              goto __pyx_L29_continue;

              /* "pygeoprocessing/routing/routing.pyx":1414
 *                         upstream_flow_dir = <int>flow_dir_managed_raster.get(
 *                             xi_n, yi_n)
 *                         if upstream_flow_dir == flow_dir_nodata or (             # <<<<<<<<<<<<<<
 *                                 upstream_flow_dir !=
 *                                 D8_REVERSE_DIRECTION[i_n]):
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1419
 *                             # no upstream here
 *                             continue
 *                         upstream_flow_accum = <double>(             # <<<<<<<<<<<<<<
 *                             flow_accum_managed_raster.get(xi_n, yi_n))
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):
 */
            __pyx_v_upstream_flow_accum = ((double)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n));

            /* "pygeoprocessing/routing/routing.pyx":1421
 *                         upstream_flow_accum = <double>(
 *                             flow_accum_managed_raster.get(xi_n, yi_n))
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):             # <<<<<<<<<<<<<<
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n
 */
            __pyx_t_7 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_upstream_flow_accum, __pyx_v_flow_accum_nodata) != 0);
            if (__pyx_t_7) {

              /* "pygeoprocessing/routing/routing.pyx":1423
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n             # <<<<<<<<<<<<<<
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:
 */
              __pyx_v_flow_pixel.last_flow_dir = __pyx_v_i_n;

              /* "pygeoprocessing/routing/routing.pyx":1424
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n
 *                             search_stack.push(flow_pixel)             # <<<<<<<<<<<<<<
 *                             if weight_raster is not None:
 *                                 weight_val = <double>weight_raster.get(
 */
              __pyx_v_search_stack.push(__pyx_v_flow_pixel);

              /* "pygeoprocessing/routing/routing.pyx":1425
 *                             flow_pixel.last_flow_dir = i_n
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 */
              __pyx_t_7 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
              __pyx_t_6 = (__pyx_t_7 != 0);
              if (__pyx_t_6) {

                /* "pygeoprocessing/routing/routing.pyx":1426
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:
 *                                 weight_val = <double>weight_raster.get(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):
 */
                __pyx_v_weight_val = ((double)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_weight_raster, __pyx_v_xi_n, __pyx_v_yi_n));

                /* "pygeoprocessing/routing/routing.pyx":1428
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                     weight_val = 0.0
 *                             else:
 */
                __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_weight_val, __pyx_v_weight_nodata) != 0);
                if (__pyx_t_6) {

                  /* "pygeoprocessing/routing/routing.pyx":1429
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):
 *                                     weight_val = 0.0             # <<<<<<<<<<<<<<
 *                             else:
 *                                 weight_val = 1.0
 */
                  __pyx_v_weight_val = 0.0;

                  /* "pygeoprocessing/routing/routing.pyx":1428
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                     weight_val = 0.0
 *                             else:
 */
                }

                /* "pygeoprocessing/routing/routing.pyx":1425
 *                             flow_pixel.last_flow_dir = i_n
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 */
                goto __pyx_L40;
              }

              /* "pygeoprocessing/routing/routing.pyx":1431
 *                                     weight_val = 0.0
 *                             else:
 *                                 weight_val = 1.0             # <<<<<<<<<<<<<<
 *                             search_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 */
              /*else*/ {
                __pyx_v_weight_val = 1.0;
              }
              __pyx_L40:;

              /* "pygeoprocessing/routing/routing.pyx":1433
 *                                 weight_val = 1.0
 *                             search_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))             # <<<<<<<<<<<<<<
 *                             preempted = 1
 *                             break
 */
              __pyx_t_32.xi = __pyx_v_xi_n;
              __pyx_t_32.yi = __pyx_v_yi_n;
              __pyx_t_32.last_flow_dir = 0;
              __pyx_t_32.value = __pyx_v_weight_val;

              /* "pygeoprocessing/routing/routing.pyx":1432
 *                             else:
 *                                 weight_val = 1.0
 *                             search_stack.push(             # <<<<<<<<<<<<<<
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 *                             preempted = 1
 */
              __pyx_v_search_stack.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1434
 *                             search_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 *                             preempted = 1             # <<<<<<<<<<<<<<
 *                             break
 *                         flow_pixel.value += upstream_flow_accum
 */
              __pyx_v_preempted = 1;

              /* "pygeoprocessing/routing/routing.pyx":1435
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 *                             preempted = 1
 *                             break             # <<<<<<<<<<<<<<
 *                         flow_pixel.value += upstream_flow_accum
 *                     if not preempted:
 */
              goto __pyx_L30_break;

              /* "pygeoprocessing/routing/routing.pyx":1421
 *                         upstream_flow_accum = <double>(
 *                             flow_accum_managed_raster.get(xi_n, yi_n))
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):             # <<<<<<<<<<<<<<
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1436
 *                             preempted = 1
 *                             break
 *                         flow_pixel.value += upstream_flow_accum             # <<<<<<<<<<<<<<
 *                     if not preempted:
 *                         flow_accum_managed_raster.set(
 */
            __pyx_v_flow_pixel.value = (__pyx_v_flow_pixel.value + __pyx_v_upstream_flow_accum);
            __pyx_L29_continue:;
          }
          __pyx_L30_break:;

          /* "pygeoprocessing/routing/routing.pyx":1437
 *                             break
 *                         flow_pixel.value += upstream_flow_accum
 *                     if not preempted:             # <<<<<<<<<<<<<<
 *                         flow_accum_managed_raster.set(
 *                             flow_pixel.xi, flow_pixel.yi,
 */
          __pyx_t_6 = ((!(__pyx_v_preempted != 0)) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1438
 *                         flow_pixel.value += upstream_flow_accum
 *                     if not preempted:
 *                         flow_accum_managed_raster.set(             # <<<<<<<<<<<<<<
 *                             flow_pixel.xi, flow_pixel.yi,
 *                             flow_pixel.value)
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_accum_managed_raster, __pyx_v_flow_pixel.xi, __pyx_v_flow_pixel.yi, __pyx_v_flow_pixel.value);

            /* "pygeoprocessing/routing/routing.pyx":1437
 *                             break
 *                         flow_pixel.value += upstream_flow_accum
 *                     if not preempted:             # <<<<<<<<<<<<<<
 *                         flow_accum_managed_raster.set(
 *                             flow_pixel.xi, flow_pixel.yi,
 */
          }
        }
        __pyx_L21_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":1347
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_raster_path_band[0], offset_only=True, largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1441
 *                             flow_pixel.xi, flow_pixel.yi,
 *                             flow_pixel.value)
 *     flow_accum_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_accum_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1441, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_20 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_20)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_20) {
    __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_20); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1441, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1441, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1442
 *                             flow_pixel.value)
 *     flow_accum_managed_raster.close()
 *     flow_dir_managed_raster.close()             # <<<<<<<<<<<<<<
 *     if weight_raster is not None:
 *         weight_raster.close()
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1442, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_20 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_20)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_20) {
    __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_20); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1442, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1442, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1443
 *     flow_accum_managed_raster.close()
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {

    /* "pygeoprocessing/routing/routing.pyx":1444
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:
 *         weight_raster.close()             # <<<<<<<<<<<<<<
 *     LOGGER.info('%.1f%% complete', 100.0)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1444, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_20 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_20)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_20);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (__pyx_t_20) {
      __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_20); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1444, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    } else {
      __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1444, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1443
 *     flow_accum_managed_raster.close()
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":1445
 *     if weight_raster is not None:
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1227
 * 
 * 
 * def flow_accumulation_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_accumulation_d8", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_buffer_array);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_accum_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster);
  __Pyx_XDECREF(__pyx_v_flow_dir_raster);
  __Pyx_XDECREF(__pyx_v_flow_dir_band);
  __Pyx_XDECREF((PyObject *)__pyx_v_weight_raster);
  __Pyx_XDECREF(__pyx_v_raw_weight_nodata);
  __Pyx_XDECREF(__pyx_v_flow_dir_raster_info);
  __Pyx_XDECREF(__pyx_v_tmp_flow_dir_nodata);
  __Pyx_XDECREF(__pyx_v_offset_dict);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_modified_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":1448
 * 
 * 
 * def flow_dir_mfd(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path, working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_9flow_dir_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_8flow_dir_mfd[] = "Multiple flow direction.\n\n    Parameters:\n        dem_raster_path_band (tuple): a path, band number tuple indicating the\n            DEM calculate flow direction. This DEM must not have hydrological\n            pits or else the target flow direction will be undefined.\n        target_flow_dir_path (string): path to a raster created by this call\n            of a 32 bit int raster of the same dimensions and projections as\n            `dem_raster_path_band[0]`. The value of the pixel indicates the\n            proportion of flow from that pixel to its neighbors given these\n            indexes:\n\n                321\n                4x0\n                567\n\n            The pixel value is formatted as 8 separate 4 bit integers\n            compressed into a 32 bit int. To extract the proportion of flow\n            from a particular direction given the pixel value 'x' one can\n            shift and mask as follows 0xF & (x >> (4*dir)), where `dir` is\n            one of the 8 directions indicated above.\n\n        working_dir (string): If not None, indicates where temporary files\n            should be created during this run. If this directory doesn't exist\n            it is created by this call.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_9flow_dir_mfd = {"flow_dir_mfd", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_9flow_dir_mfd, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_8flow_dir_mfd};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_9flow_dir_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dem_raster_path_band = 0;
  PyObject *__pyx_v_target_flow_dir_path = 0;
  PyObject *__pyx_v_working_dir = 0;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("flow_dir_mfd (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dem_raster_path_band,&__pyx_n_s_target_flow_dir_path,&__pyx_n_s_working_dir,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pygeoprocessing/routing/routing.pyx":1449
 * 
 * def flow_dir_mfd(
 *         dem_raster_path_band, target_flow_dir_path, working_dir=None,             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 *     """Multiple flow direction.
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = __pyx_k__16;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dem_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_flow_dir_path)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("flow_dir_mfd", 0, 2, 4, 1); __PYX_ERR(0, 1448, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_working_dir);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "flow_dir_mfd") < 0)) __PYX_ERR(0, 1448, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_dem_raster_path_band = values[0];
    __pyx_v_target_flow_dir_path = values[1];
    __pyx_v_working_dir = values[2];
    __pyx_v_gtiff_creation_options = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("flow_dir_mfd", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1448, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_dir_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_8flow_dir_mfd(__pyx_self, __pyx_v_dem_raster_path_band, __pyx_v_target_flow_dir_path, __pyx_v_working_dir, __pyx_v_gtiff_creation_options);

  /* "pygeoprocessing/routing/routing.pyx":1448
 * 
 * 
 * def flow_dir_mfd(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path, working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_8flow_dir_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dem_raster_path_band, PyObject *__pyx_v_target_flow_dir_path, PyObject *__pyx_v_working_dir, PyObject *__pyx_v_gtiff_creation_options) {
  PyArrayObject *__pyx_v_dem_buffer_array = 0;
  int __pyx_v_win_ysize;
  int __pyx_v_win_xsize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_xi_root;
  int __pyx_v_yi_root;
  int __pyx_v_i_n;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_q;
  int __pyx_v_yi_q;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  double __pyx_v_root_height;
  double __pyx_v_n_height;
  double __pyx_v_dem_nodata;
  double __pyx_v_n_slope;
  double __pyx_v_drain_distance;
  double __pyx_v_n_drain_distance;
  std::queue<struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType>  __pyx_v_drain_search_queue;
  double __pyx_v_downhill_slope_array[8];
  double __pyx_v_nodata_downhill_slope_array[8];
  double *__pyx_v_working_downhill_slope_array;
  double __pyx_v_sum_of_slope_weights;
  double __pyx_v_sum_of_nodata_slope_weights;
  int __pyx_v_compressed_integer_slopes;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_v_distance_drain_queue;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_v_nodata_distance_drain_queue;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_v_direction_drain_queue;
  std::queue<int>  __pyx_v_nodata_flow_dir_queue;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  time_t __pyx_v_last_log_time;
  PyObject *__pyx_v_dem_raster_info = NULL;
  PyObject *__pyx_v_base_nodata = NULL;
  long __pyx_v_mask_nodata;
  PyObject *__pyx_v_working_dir_path = NULL;
  PyObject *__pyx_v_flat_region_mask_path = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flat_region_mask_managed_raster = NULL;
  long __pyx_v_flow_dir_nodata;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL;
  PyObject *__pyx_v_plateu_drain_mask_path = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_plateau_drain_mask_managed_raster = NULL;
  PyObject *__pyx_v_plateau_distance_path = NULL;
  int __pyx_v_plateau_distance_nodata;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_plateau_distance_managed_raster = NULL;
  PyObject *__pyx_v_compatable_dem_raster_path_band = NULL;
  PyObject *__pyx_v_dem_block_xsize = NULL;
  PyObject *__pyx_v_dem_block_ysize = NULL;
  PyObject *__pyx_v_geotiff_driver = NULL;
  PyObject *__pyx_v_dem_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_dem_managed_raster = NULL;
  PyObject *__pyx_v_dem_band = NULL;
  PyObject *__pyx_v_offset_dict = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_modified_offset_dict = NULL;
  double __pyx_v_sum_of_downhill_slopes;
  double __pyx_v_working_downhill_slope_sum;
  CYTHON_UNUSED size_t __pyx_v__;
  double __pyx_v_n_distance;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_dem_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_dem_buffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  double __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  Py_ssize_t __pyx_t_17;
  PyObject *(*__pyx_t_18)(PyObject *);
  PyArrayObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  long __pyx_t_22;
  long __pyx_t_23;
  long __pyx_t_24;
  long __pyx_t_25;
  Py_ssize_t __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  int __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  int __pyx_t_31;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_32;
  __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType __pyx_t_33;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_t_34;
  size_t __pyx_t_35;
  size_t __pyx_t_36;
  size_t __pyx_t_37;
  __Pyx_RefNannySetupContext("flow_dir_mfd", 0);
  __pyx_pybuffer_dem_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_dem_buffer_array.refcount = 0;
  __pyx_pybuffernd_dem_buffer_array.data = NULL;
  __pyx_pybuffernd_dem_buffer_array.rcbuffer = &__pyx_pybuffer_dem_buffer_array;

  /* "pygeoprocessing/routing/routing.pyx":1546
 *     # used for time-delayed logging
 *     cdef time_t last_log_time
 *     last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     # determine dem nodata in the working type, or set an improbable value
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":1550
 *     # determine dem nodata in the working type, or set an improbable value
 *     # if one can't be determined
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1550, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1550, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1550, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1550, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1550, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1550, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1550, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1550, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_dem_raster_info = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1551
 *     # if one can't be determined
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *     if base_nodata is not None:
 *         # cast to a float64 since that's our operating array type
 */
  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_base_nodata = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1552
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:             # <<<<<<<<<<<<<<
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)
 */
  __pyx_t_6 = (__pyx_v_base_nodata != Py_None);
  __pyx_t_7 = (__pyx_t_6 != 0);
  if (__pyx_t_7) {

    /* "pygeoprocessing/routing/routing.pyx":1554
 *     if base_nodata is not None:
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)             # <<<<<<<<<<<<<<
 *     else:
 *         # pick some very improbable value since it's hard to deal with NaNs
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1554, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1554, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_base_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1554, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_base_nodata};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1554, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_base_nodata};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1554, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1554, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL;
        __Pyx_INCREF(__pyx_v_base_nodata);
        __Pyx_GIVEREF(__pyx_v_base_nodata);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_base_nodata);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1554, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1554, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_dem_nodata = __pyx_t_8;

    /* "pygeoprocessing/routing/routing.pyx":1552
 *     dem_raster_info = pygeoprocessing.get_raster_info(dem_raster_path_band[0])
 *     base_nodata = dem_raster_info['nodata'][dem_raster_path_band[1]-1]
 *     if base_nodata is not None:             # <<<<<<<<<<<<<<
 *         # cast to a float64 since that's our operating array type
 *         dem_nodata = numpy.float64(base_nodata)
 */
    goto __pyx_L3;
  }

  /* "pygeoprocessing/routing/routing.pyx":1557
 *     else:
 *         # pick some very improbable value since it's hard to deal with NaNs
 *         dem_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 * 
 *     # these are used to determine if a sample is within the raster
 */
  /*else*/ {
    __pyx_v_dem_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;
  }
  __pyx_L3:;

  /* "pygeoprocessing/routing/routing.pyx":1560
 * 
 *     # these are used to determine if a sample is within the raster
 *     raster_x_size, raster_y_size = dem_raster_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     # this is the nodata value for all the flat region and pit masks
 */
  __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1560, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_2);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_5), 2) < 0) __PYX_ERR(0, 1560, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1560, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_raster_x_size = __pyx_t_10;
  __pyx_v_raster_y_size = __pyx_t_11;

  /* "pygeoprocessing/routing/routing.pyx":1563
 * 
 *     # this is the nodata value for all the flat region and pit masks
 *     mask_nodata = 0             # <<<<<<<<<<<<<<
 * 
 *     # set up the working dir for the mask rasters
 */
  __pyx_v_mask_nodata = 0;

  /* "pygeoprocessing/routing/routing.pyx":1566
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
    __Pyx_XGOTREF(__pyx_t_12);
    __Pyx_XGOTREF(__pyx_t_13);
    __Pyx_XGOTREF(__pyx_t_14);
    /*try:*/ {

      /* "pygeoprocessing/routing/routing.pyx":1567
 *     # set up the working dir for the mask rasters
 *     try:
 *         if working_dir is not None:             # <<<<<<<<<<<<<<
 *             os.makedirs(working_dir)
 *     except OSError:
 */
      __pyx_t_7 = (__pyx_v_working_dir != Py_None);
      __pyx_t_6 = (__pyx_t_7 != 0);
      if (__pyx_t_6) {

        /* "pygeoprocessing/routing/routing.pyx":1568
 *     try:
 *         if working_dir is not None:
 *             os.makedirs(working_dir)             # <<<<<<<<<<<<<<
 *     except OSError:
 *         pass
 */
        __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1568, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_makedirs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1568, __pyx_L6_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
          }
        }
        if (!__pyx_t_2) {
          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_working_dir); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1568, __pyx_L6_error)
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_working_dir};
            __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1568, __pyx_L6_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_3);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_working_dir};
            __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1568, __pyx_L6_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_3);
          } else
          #endif
          {
            __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1568, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
            __Pyx_INCREF(__pyx_v_working_dir);
            __Pyx_GIVEREF(__pyx_v_working_dir);
            PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_working_dir);
            __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1568, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pygeoprocessing/routing/routing.pyx":1567
 *     # set up the working dir for the mask rasters
 *     try:
 *         if working_dir is not None:             # <<<<<<<<<<<<<<
 *             os.makedirs(working_dir)
 *     except OSError:
 */
      }

      /* "pygeoprocessing/routing/routing.pyx":1566
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
    }
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    goto __pyx_L11_try_end;
    __pyx_L6_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1569
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 *     except OSError:             # <<<<<<<<<<<<<<
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 */
    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OSError);
    if (__pyx_t_11) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L7_exception_handled;
    }
    goto __pyx_L8_except_error;
    __pyx_L8_except_error:;

    /* "pygeoprocessing/routing/routing.pyx":1566
 * 
 *     # set up the working dir for the mask rasters
 *     try:             # <<<<<<<<<<<<<<
 *         if working_dir is not None:
 *             os.makedirs(working_dir)
 */
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_13);
    __Pyx_XGIVEREF(__pyx_t_14);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
    goto __pyx_L1_error;
    __pyx_L7_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_XGIVEREF(__pyx_t_13);
    __Pyx_XGIVEREF(__pyx_t_14);
    __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
    __pyx_L11_try_end:;
  }

  /* "pygeoprocessing/routing/routing.pyx":1571
 *     except OSError:
 *         pass
 *     working_dir_path = tempfile.mkdtemp(             # <<<<<<<<<<<<<<
 *         dir=working_dir,
 *         prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime(
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_mkdtemp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1572
 *         pass
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir,             # <<<<<<<<<<<<<<
 *         prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dir, __pyx_v_working_dir) < 0) __PYX_ERR(0, 1572, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1573
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir,
 *         prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime(             # <<<<<<<<<<<<<<
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 * 
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_strftime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1574
 *         dir=working_dir,
 *         prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime(
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))             # <<<<<<<<<<<<<<
 * 
 *     # this raster is used to keep track of what pixels have been searched for
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_gmtime); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1574, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_16);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_16, function);
    }
  }
  if (__pyx_t_15) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1574, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1574, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __pyx_t_16 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_s_Y_m_d__H__M__S, __pyx_t_2};
    __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1573, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_kp_s_Y_m_d__H__M__S, __pyx_t_2};
    __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1573, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_15 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (__pyx_t_16) {
      __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_16); __pyx_t_16 = NULL;
    }
    __Pyx_INCREF(__pyx_kp_s_Y_m_d__H__M__S);
    __Pyx_GIVEREF(__pyx_kp_s_Y_m_d__H__M__S);
    PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, __pyx_kp_s_Y_m_d__H__M__S);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_15, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1573
 *     working_dir_path = tempfile.mkdtemp(
 *         dir=working_dir,
 *         prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime(             # <<<<<<<<<<<<<<
 *             '%Y-%m-%d_%H_%M_%S', time.gmtime()))
 * 
 */
  __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_flow_dir_multiple_flow_dir__s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_prefix, __pyx_t_4) < 0) __PYX_ERR(0, 1572, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1571
 *     except OSError:
 *         pass
 *     working_dir_path = tempfile.mkdtemp(             # <<<<<<<<<<<<<<
 *         dir=working_dir,
 *         prefix='flow_dir_multiple_flow_dir_%s_' % time.strftime(
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_working_dir_path = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1579
 *     # a plateau. if a pixel is set, it means it is part of a locally
 *     # undrained area
 *     flat_region_mask_path = os.path.join(             # <<<<<<<<<<<<<<
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1580
 *     # undrained area
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 */
  __pyx_t_1 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_flat_region_mask_tif};
    __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1579, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_working_dir_path, __pyx_kp_s_flat_region_mask_tif};
    __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1579, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1579, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(__pyx_v_working_dir_path);
    __Pyx_GIVEREF(__pyx_v_working_dir_path);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_11, __pyx_v_working_dir_path);
    __Pyx_INCREF(__pyx_kp_s_flat_region_mask_tif);
    __Pyx_GIVEREF(__pyx_kp_s_flat_region_mask_tif);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_11, __pyx_kp_s_flat_region_mask_tif);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1579, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_flat_region_mask_path = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1581
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1582
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,             # <<<<<<<<<<<<<<
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1583
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1581
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __Pyx_INCREF(__pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_v_flat_region_mask_path);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_15);
  __pyx_t_4 = 0;
  __pyx_t_1 = 0;
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1583
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_15 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1583, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_fill_value_list, __pyx_t_4) < 0) __PYX_ERR(0, 1583, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1584
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     flat_region_mask_managed_raster = _ManagedRaster(
 *         flat_region_mask_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 1583, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1581
 *     flat_region_mask_path = os.path.join(
 *         working_dir_path, 'flat_region_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], flat_region_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, __pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1585
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     flat_region_mask_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flat_region_mask_path, 1, 1)
 * 
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_flat_region_mask_path);
  __Pyx_GIVEREF(__pyx_v_flat_region_mask_path);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_flat_region_mask_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_1);
  __pyx_t_15 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_4, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1585, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_flat_region_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_15);
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1588
 *         flat_region_mask_path, 1, 1)
 * 
 *     flow_dir_nodata = 0             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,
 */
  __pyx_v_flow_dir_nodata = 0;

  /* "pygeoprocessing/routing/routing.pyx":1589
 * 
 *     flow_dir_nodata = 0
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1589, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1589, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1590
 *     flow_dir_nodata = 0
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,             # <<<<<<<<<<<<<<
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GDT_Int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1591
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)
 */
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1589
 * 
 *     flow_dir_nodata = 0
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 */
  __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1589, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_15);
  __Pyx_INCREF(__pyx_v_target_flow_dir_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_dir_path);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_target_flow_dir_path);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_1);
  __pyx_t_15 = 0;
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1591
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_flow_dir_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_15 = PyList_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_15, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_fill_value_list, __pyx_t_15) < 0) __PYX_ERR(0, 1591, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1592
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 1591, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1589
 * 
 *     flow_dir_nodata = 0
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], target_flow_dir_path, gdal.GDT_Int32,
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 */
  __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1589, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1593
 *         [flow_dir_nodata], fill_value_list=[flow_dir_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)             # <<<<<<<<<<<<<<
 * 
 *     plateu_drain_mask_path = os.path.join(
 */
  __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_INCREF(__pyx_v_target_flow_dir_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_dir_path);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_target_flow_dir_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_int_1);
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1595
 *     flow_dir_managed_raster = _ManagedRaster(target_flow_dir_path, 1, 1)
 * 
 *     plateu_drain_mask_path = os.path.join(             # <<<<<<<<<<<<<<
 *         working_dir_path, 'plateu_drain_mask.tif')
 *     pygeoprocessing.new_raster_from_base(
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_join); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1596
 * 
 *     plateu_drain_mask_path = os.path.join(
 *         working_dir_path, 'plateu_drain_mask.tif')             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,
 */
  __pyx_t_5 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_15)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_working_dir_path, __pyx_kp_s_plateu_drain_mask_tif};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1595, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_working_dir_path, __pyx_kp_s_plateu_drain_mask_tif};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1595, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(__pyx_v_working_dir_path);
    __Pyx_GIVEREF(__pyx_v_working_dir_path);
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_11, __pyx_v_working_dir_path);
    __Pyx_INCREF(__pyx_kp_s_plateu_drain_mask_tif);
    __Pyx_GIVEREF(__pyx_kp_s_plateu_drain_mask_tif);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_11, __pyx_kp_s_plateu_drain_mask_tif);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1595, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_v_plateu_drain_mask_path = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1597
 *     plateu_drain_mask_path = os.path.join(
 *         working_dir_path, 'plateu_drain_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1598
 *         working_dir_path, 'plateu_drain_mask.tif')
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,             # <<<<<<<<<<<<<<
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1598, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1599
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_drain_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1597
 *     plateu_drain_mask_path = os.path.join(
 *         working_dir_path, 'plateu_drain_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_v_plateu_drain_mask_path);
  __Pyx_GIVEREF(__pyx_v_plateu_drain_mask_path);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_plateu_drain_mask_path);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_5 = 0;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1599
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_drain_mask_managed_raster = _ManagedRaster(
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_mask_nodata); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_fill_value_list, __pyx_t_1) < 0) __PYX_ERR(0, 1599, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1600
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     plateau_drain_mask_managed_raster = _ManagedRaster(
 *         plateu_drain_mask_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 1599, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1597
 *     plateu_drain_mask_path = os.path.join(
 *         working_dir_path, 'plateu_drain_mask.tif')
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateu_drain_mask_path, gdal.GDT_Byte,
 *         [mask_nodata], fill_value_list=[mask_nodata],
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1597, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1601
 *         [mask_nodata], fill_value_list=[mask_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_drain_mask_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         plateu_drain_mask_path, 1, 1)
 * 
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1601, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_plateu_drain_mask_path);
  __Pyx_GIVEREF(__pyx_v_plateu_drain_mask_path);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_plateu_drain_mask_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_1);
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1601, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_plateau_drain_mask_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1608
 *     # raster_x_size * raster_y_size as a distance that's greater than the
 *     # longest plateau drain distance possible for this raster.
 *     plateau_distance_path = os.path.join(             # <<<<<<<<<<<<<<
 *         working_dir_path, 'plateau_distance.tif')
 *     plateau_distance_nodata = raster_x_size * raster_y_size
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_join); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1609
 *     # longest plateau drain distance possible for this raster.
 *     plateau_distance_path = os.path.join(
 *         working_dir_path, 'plateau_distance.tif')             # <<<<<<<<<<<<<<
 *     plateau_distance_nodata = raster_x_size * raster_y_size
 *     pygeoprocessing.new_raster_from_base(
 */
  __pyx_t_4 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_working_dir_path, __pyx_kp_s_plateau_distance_tif};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1608, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_working_dir_path, __pyx_kp_s_plateau_distance_tif};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1608, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  {
    __pyx_t_15 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1608, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (__pyx_t_4) {
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_4); __pyx_t_4 = NULL;
    }
    __Pyx_INCREF(__pyx_v_working_dir_path);
    __Pyx_GIVEREF(__pyx_v_working_dir_path);
    PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, __pyx_v_working_dir_path);
    __Pyx_INCREF(__pyx_kp_s_plateau_distance_tif);
    __Pyx_GIVEREF(__pyx_kp_s_plateau_distance_tif);
    PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_kp_s_plateau_distance_tif);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1608, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_plateau_distance_path = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1610
 *     plateau_distance_path = os.path.join(
 *         working_dir_path, 'plateau_distance.tif')
 *     plateau_distance_nodata = raster_x_size * raster_y_size             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 */
  __pyx_v_plateau_distance_nodata = (__pyx_v_raster_x_size * __pyx_v_raster_y_size);

  /* "pygeoprocessing/routing/routing.pyx":1611
 *         working_dir_path, 'plateau_distance.tif')
 *     plateau_distance_nodata = raster_x_size * raster_y_size
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [plateau_distance_nodata], fill_value_list=[
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1612
 *     plateau_distance_nodata = raster_x_size * raster_y_size
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,             # <<<<<<<<<<<<<<
 *         [plateau_distance_nodata], fill_value_list=[
 *             raster_x_size * raster_y_size],
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1613
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [plateau_distance_nodata], fill_value_list=[             # <<<<<<<<<<<<<<
 *             raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v_plateau_distance_nodata); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_15);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_15);
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1611
 *         working_dir_path, 'plateau_distance.tif')
 *     plateau_distance_nodata = raster_x_size * raster_y_size
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [plateau_distance_nodata], fill_value_list=[
 */
  __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_3);
  __Pyx_INCREF(__pyx_v_plateau_distance_path);
  __Pyx_GIVEREF(__pyx_v_plateau_distance_path);
  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_plateau_distance_path);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1613
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [plateau_distance_nodata], fill_value_list=[             # <<<<<<<<<<<<<<
 *             raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":1614
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [plateau_distance_nodata], fill_value_list=[
 *             raster_x_size * raster_y_size],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_distance_managed_raster = _ManagedRaster(
 */
  __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_raster_x_size * __pyx_v_raster_y_size)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pygeoprocessing/routing/routing.pyx":1613
 *     pygeoprocessing.new_raster_from_base(
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [plateau_distance_nodata], fill_value_list=[             # <<<<<<<<<<<<<<
 *             raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_fill_value_list, __pyx_t_3) < 0) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1615
 *         [plateau_distance_nodata], fill_value_list=[
 *             raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     plateau_distance_managed_raster = _ManagedRaster(
 *         plateau_distance_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 1613, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1611
 *         working_dir_path, 'plateau_distance.tif')
 *     plateau_distance_nodata = raster_x_size * raster_y_size
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band[0], plateau_distance_path, gdal.GDT_Float64,
 *         [plateau_distance_nodata], fill_value_list=[
 */
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_15, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1616
 *             raster_x_size * raster_y_size],
 *         gtiff_creation_options=gtiff_creation_options)
 *     plateau_distance_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         plateau_distance_path, 1, 1)
 * 
 */
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_plateau_distance_path);
  __Pyx_GIVEREF(__pyx_v_plateau_distance_path);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_plateau_distance_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_1);
  __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_plateau_distance_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1620
 * 
 *     # this raster is for random access of the DEM
 *     compatable_dem_raster_path_band = None             # <<<<<<<<<<<<<<
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_compatable_dem_raster_path_band = Py_None;

  /* "pygeoprocessing/routing/routing.pyx":1621
 *     # this raster is for random access of the DEM
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']             # <<<<<<<<<<<<<<
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 */
  __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_dem_raster_info, __pyx_n_s_block_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
    PyObject* sequence = __pyx_t_5;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1621, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_15 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_15);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    #endif
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1621, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L13_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_15 = __pyx_t_9(__pyx_t_1); if (unlikely(!__pyx_t_15)) goto __pyx_L13_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_15);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1621, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L14_unpacking_done;
    __pyx_L13_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1621, __pyx_L1_error)
    __pyx_L14_unpacking_done:;
  }
  __pyx_v_dem_block_xsize = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_dem_block_ysize = __pyx_t_15;
  __pyx_t_15 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1622
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 */
  __pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_xsize, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyNumber_And(__pyx_v_dem_block_xsize, __pyx_t_5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_15, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_7) {
  } else {
    __pyx_t_6 = __pyx_t_7;
    goto __pyx_L16_bool_binop_done;
  }

  /* "pygeoprocessing/routing/routing.pyx":1623
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):             # <<<<<<<<<<<<<<
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 *         compatable_dem_raster_path_band = (
 */
  __pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_v_dem_block_ysize, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = PyNumber_And(__pyx_v_dem_block_ysize, __pyx_t_5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_15, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = __pyx_t_7;
  __pyx_L16_bool_binop_done:;

  /* "pygeoprocessing/routing/routing.pyx":1622
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 */
  if (__pyx_t_6) {

    /* "pygeoprocessing/routing/routing.pyx":1624
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1624, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_warning); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1624, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1624, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1626
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 */
    __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1626, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1626, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_join); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1626, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_15)) {
      PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_working_dir_path, __pyx_kp_s_compatable_dem_tif};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1626, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
      PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_working_dir_path, __pyx_kp_s_compatable_dem_tif};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1626, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1626, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_3) {
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = NULL;
      }
      __Pyx_INCREF(__pyx_v_working_dir_path);
      __Pyx_GIVEREF(__pyx_v_working_dir_path);
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_v_working_dir_path);
      __Pyx_INCREF(__pyx_kp_s_compatable_dem_tif);
      __Pyx_GIVEREF(__pyx_kp_s_compatable_dem_tif);
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_kp_s_compatable_dem_tif);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1626, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1627
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 *             dem_raster_path_band[1])             # <<<<<<<<<<<<<<
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 */
    __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1627, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);

    /* "pygeoprocessing/routing/routing.pyx":1626
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),             # <<<<<<<<<<<<<<
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1626, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_15);
    __pyx_t_5 = 0;
    __pyx_t_15 = 0;
    __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1628
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')             # <<<<<<<<<<<<<<
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1628, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GetDriverByName); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1628, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1628, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_v_geotiff_driver = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1629
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *         geotiff_driver.CreateCopy(
 *             compatable_dem_raster_path_band[0], dem_raster,
 */
    __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_15, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1629, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_15, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1629, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1629, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (__pyx_t_3) {
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_4);
      __pyx_t_15 = 0;
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1629, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_dem_raster = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1630
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_geotiff_driver, __pyx_n_s_CreateCopy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1630, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "pygeoprocessing/routing/routing.pyx":1631
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(
 *             compatable_dem_raster_path_band[0], dem_raster,             # <<<<<<<<<<<<<<
 *             options=gtiff_creation_options)
 *         dem_raster = None
 */
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1631, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "pygeoprocessing/routing/routing.pyx":1630
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 */
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1630, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
    __Pyx_INCREF(__pyx_v_dem_raster);
    __Pyx_GIVEREF(__pyx_v_dem_raster);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_dem_raster);
    __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1632
 *         geotiff_driver.CreateCopy(
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *         dem_raster = None
 *         LOGGER.info("compatible dem complete")
 */
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1632, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 1632, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":1630
 *         geotiff_driver = gdal.GetDriverByName('GTiff')
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1630, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1633
 *             compatable_dem_raster_path_band[0], dem_raster,
 *             options=gtiff_creation_options)
 *         dem_raster = None             # <<<<<<<<<<<<<<
 *         LOGGER.info("compatible dem complete")
 *     else:
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF_SET(__pyx_v_dem_raster, Py_None);

    /* "pygeoprocessing/routing/routing.pyx":1634
 *             options=gtiff_creation_options)
 *         dem_raster = None
 *         LOGGER.info("compatible dem complete")             # <<<<<<<<<<<<<<
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1634, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1634, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1634, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1622
 *     compatable_dem_raster_path_band = None
 *     dem_block_xsize, dem_block_ysize = dem_raster_info['block_size']
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (             # <<<<<<<<<<<<<<
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")
 */
    goto __pyx_L15;
  }

  /* "pygeoprocessing/routing/routing.pyx":1636
 *         LOGGER.info("compatible dem complete")
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band             # <<<<<<<<<<<<<<
 *     dem_managed_raster = _ManagedRaster(
 *         compatable_dem_raster_path_band[0],
 */
  /*else*/ {
    __Pyx_INCREF(__pyx_v_dem_raster_path_band);
    __Pyx_DECREF_SET(__pyx_v_compatable_dem_raster_path_band, __pyx_v_dem_raster_path_band);
  }
  __pyx_L15:;

  /* "pygeoprocessing/routing/routing.pyx":1638
 *         compatable_dem_raster_path_band = dem_raster_path_band
 *     dem_managed_raster = _ManagedRaster(
 *         compatable_dem_raster_path_band[0],             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band[1], 0)
 * 
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pygeoprocessing/routing/routing.pyx":1639
 *     dem_managed_raster = _ManagedRaster(
 *         compatable_dem_raster_path_band[0],
 *         compatable_dem_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 * 
 *     # and this raster is for efficient block-by-block reading of the dem
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":1637
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band
 *     dem_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band[0],
 *         compatable_dem_raster_path_band[1], 0)
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1637, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_dem_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1642
 * 
 *     # and this raster is for efficient block-by-block reading of the dem
 *     dem_raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band[0], gdal.OF_RASTER)
 *     dem_band = dem_raster.GetRasterBand(
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1642, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1643
 *     # and this raster is for efficient block-by-block reading of the dem
 *     dem_raster = gdal.OpenEx(
 *         compatable_dem_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     dem_band = dem_raster.GetRasterBand(
 *         compatable_dem_raster_path_band[1])
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_2, __pyx_t_15};
    __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1642, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_2, __pyx_t_15};
    __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1642, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  } else
  #endif
  {
    __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_15);
    __pyx_t_2 = 0;
    __pyx_t_15 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1642, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_XDECREF_SET(__pyx_v_dem_raster, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1644
 *     dem_raster = gdal.OpenEx(
 *         compatable_dem_raster_path_band[0], gdal.OF_RASTER)
 *     dem_band = dem_raster.GetRasterBand(             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band[1])
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1644, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pygeoprocessing/routing/routing.pyx":1645
 *         compatable_dem_raster_path_band[0], gdal.OF_RASTER)
 *     dem_band = dem_raster.GetRasterBand(
 *         compatable_dem_raster_path_band[1])             # <<<<<<<<<<<<<<
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_15) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1644, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_t_3};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1644, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_t_3};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1644, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1644, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_15); __pyx_t_15 = NULL;
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1644, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_dem_band = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1648
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1649
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             compatable_dem_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_compatable_dem_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":1648
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1649
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             compatable_dem_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 1649, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 1649, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1648
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5); __pyx_t_17 = 0;
    __pyx_t_18 = NULL;
  } else {
    __pyx_t_17 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1648, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_18 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 1648, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_18)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1648, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1648, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 1648, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1648, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_18(__pyx_t_5);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1648, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1651
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 */
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1651, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_win_xsize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1652
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']             # <<<<<<<<<<<<<<
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']
 */
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1652, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1652, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_win_ysize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1653
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']             # <<<<<<<<<<<<<<
 *         yoff = offset_dict['yoff']
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1653, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_xoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1654
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']             # <<<<<<<<<<<<<<
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1654, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_yoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":1656
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    __pyx_t_6 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
    if (__pyx_t_6) {

      /* "pygeoprocessing/routing/routing.pyx":1657
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
      __pyx_v_last_log_time = time(NULL);

      /* "pygeoprocessing/routing/routing.pyx":1658
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))
 */
      __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1658, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pygeoprocessing/routing/routing.pyx":1659
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1659, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1659, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1659, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);

      /* "pygeoprocessing/routing/routing.pyx":1660
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 */
      __pyx_t_15 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1659, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);

      /* "pygeoprocessing/routing/routing.pyx":1659
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1659, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_15 = NULL;
      __pyx_t_11 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_15)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_15);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_11 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_kp_s_1f_complete, __pyx_t_1};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_kp_s_1f_complete, __pyx_t_1};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_15) {
          __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_15); __pyx_t_15 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_11, __pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_11, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "pygeoprocessing/routing/routing.pyx":1656
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":1663
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1663, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1663, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1664
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata
 */
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1664, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1664, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1664, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1664, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1664, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1663
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1663, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1665
 *         dem_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)             # <<<<<<<<<<<<<<
 *         dem_buffer_array[:] = dem_nodata
 * 
 */
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float64); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_15) < 0) __PYX_ERR(0, 1665, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1663
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         dem_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 */
    __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1663, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1663, __pyx_L1_error)
    __pyx_t_19 = ((PyArrayObject *)__pyx_t_15);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
      __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_11 < 0)) {
        PyErr_Fetch(&__pyx_t_14, &__pyx_t_13, &__pyx_t_12);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_dem_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_14); Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_14, __pyx_t_13, __pyx_t_12);
        }
        __pyx_t_14 = __pyx_t_13 = __pyx_t_12 = 0;
      }
      __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape = __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1663, __pyx_L1_error)
    }
    __pyx_t_19 = 0;
    __Pyx_XDECREF_SET(__pyx_v_dem_buffer_array, ((PyArrayObject *)__pyx_t_15));
    __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1666
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
    __pyx_t_15 = PyFloat_FromDouble(__pyx_v_dem_nodata); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1666, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_slice__20, __pyx_t_15) < 0)) __PYX_ERR(0, 1666, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1670
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1670, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "pygeoprocessing/routing/routing.pyx":1671
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)             # <<<<<<<<<<<<<<
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)
 */
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1671, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1671, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_1, __pyx_t_4};
      __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_1, __pyx_t_4};
      __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 3+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_16 = PyTuple_New(3+__pyx_t_11); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_v_offset_dict);
      PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_11, __pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_11, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_16, 2+__pyx_t_11, __pyx_t_4);
      __pyx_t_1 = 0;
      __pyx_t_4 = 0;
      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_16, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) {
      PyObject* sequence = __pyx_t_15;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1670, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_16 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_16);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      #endif
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_4 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_16 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_16)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_16);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_4), 2) < 0) __PYX_ERR(0, 1670, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L22_unpacking_done;
      __pyx_L21_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1670, __pyx_L1_error)
      __pyx_L22_unpacking_done:;
    }

    /* "pygeoprocessing/routing/routing.pyx":1670
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 */
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1670, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_20 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_20 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_20);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_1,&__pyx_t_2,&__pyx_t_20};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1670, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_1,&__pyx_t_2,&__pyx_t_20};
      __pyx_t_21 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 1670, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_21);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_21)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_9(__pyx_t_21); if (unlikely(!item)) goto __pyx_L23_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_21), 4) < 0) __PYX_ERR(0, 1670, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      goto __pyx_L24_unpacking_done;
      __pyx_L23_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1670, __pyx_L1_error)
      __pyx_L24_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_20);
    __pyx_t_20 = 0;
    __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_16);
    __pyx_t_16 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1672
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_dem_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);

    /* "pygeoprocessing/routing/routing.pyx":1673
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 1673, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_3 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1673, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_3 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1672, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    }

    /* "pygeoprocessing/routing/routing.pyx":1672
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1673
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.float64)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_astype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1673, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1673, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_float64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1673, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_20)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_20);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (!__pyx_t_20) {
      __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_16); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1673, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_15);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_16};
        __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1673, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_16};
        __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1673, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1673, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_20); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_20); __pyx_t_20 = NULL;
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_16);
        __pyx_t_16 = 0;
        __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1673, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1672
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         dem_buffer_array[ya:yb, xa:xb] = dem_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.float64)
 * 
 */
    __pyx_t_3 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_dem_buffer_array), __pyx_t_16, __pyx_t_15) < 0)) __PYX_ERR(0, 1672, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":1676
 * 
 *         # ensure these are set for the complier
 *         xi_n = -1             # <<<<<<<<<<<<<<
 *         yi_n = -1
 * 
 */
    __pyx_v_xi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":1677
 *         # ensure these are set for the complier
 *         xi_n = -1
 *         yi_n = -1             # <<<<<<<<<<<<<<
 * 
 *         # search block for to set flow direction
 */
    __pyx_v_yi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":1680
 * 
 *         # search block for to set flow direction
 *         for yi in range(1, win_ysize+1):             # <<<<<<<<<<<<<<
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]
 */
    __pyx_t_22 = (__pyx_v_win_ysize + 1);
    __pyx_t_23 = __pyx_t_22;
    for (__pyx_t_11 = 1; __pyx_t_11 < __pyx_t_23; __pyx_t_11+=1) {
      __pyx_v_yi = __pyx_t_11;

      /* "pygeoprocessing/routing/routing.pyx":1681
 *         # search block for to set flow direction
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):             # <<<<<<<<<<<<<<
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):
 */
      __pyx_t_24 = (__pyx_v_win_xsize + 1);
      __pyx_t_25 = __pyx_t_24;
      for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_25; __pyx_t_10+=1) {
        __pyx_v_xi = __pyx_t_10;

        /* "pygeoprocessing/routing/routing.pyx":1682
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]             # <<<<<<<<<<<<<<
 *                 if is_close(root_height, dem_nodata):
 *                     continue
 */
        __pyx_t_26 = __pyx_v_yi;
        __pyx_t_27 = __pyx_v_xi;
        __pyx_t_28 = -1;
        if (__pyx_t_26 < 0) {
          __pyx_t_26 += __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_26 < 0)) __pyx_t_28 = 0;
        } else if (unlikely(__pyx_t_26 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_28 = 0;
        if (__pyx_t_27 < 0) {
          __pyx_t_27 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_27 < 0)) __pyx_t_28 = 1;
        } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_28 = 1;
        if (unlikely(__pyx_t_28 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_28);
          __PYX_ERR(0, 1682, __pyx_L1_error)
        }
        __pyx_v_root_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides));

        /* "pygeoprocessing/routing/routing.pyx":1683
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_root_height, __pyx_v_dem_nodata) != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1684
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # this value is set in case it turns out to be the root of a
 */
          goto __pyx_L27_continue;

          /* "pygeoprocessing/routing/routing.pyx":1683
 *             for xi in range(1, win_xsize+1):
 *                 root_height = dem_buffer_array[yi, xi]
 *                 if is_close(root_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1689
 *                 # pit, we'll start the fill from this pixel in the last phase
 *                 # of the algorithm
 *                 xi_root = xi-1+xoff             # <<<<<<<<<<<<<<
 *                 yi_root = yi-1+yoff
 * 
 */
        __pyx_v_xi_root = ((__pyx_v_xi - 1) + __pyx_v_xoff);

        /* "pygeoprocessing/routing/routing.pyx":1690
 *                 # of the algorithm
 *                 xi_root = xi-1+xoff
 *                 yi_root = yi-1+yoff             # <<<<<<<<<<<<<<
 * 
 *                 if flow_dir_managed_raster.get(
 */
        __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff);

        /* "pygeoprocessing/routing/routing.pyx":1693
 * 
 *                 if flow_dir_managed_raster.get(
 *                         xi_root, yi_root) != flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                     # already been defined
 *                     continue
 */
        __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root) != __pyx_v_flow_dir_nodata) != 0);

        /* "pygeoprocessing/routing/routing.pyx":1692
 *                 yi_root = yi-1+yoff
 * 
 *                 if flow_dir_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root) != flow_dir_nodata:
 *                     # already been defined
 */
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1695
 *                         xi_root, yi_root) != flow_dir_nodata:
 *                     # already been defined
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # PHASE 1 - try to set the direction based on local values
 */
          goto __pyx_L27_continue;

          /* "pygeoprocessing/routing/routing.pyx":1692
 *                 yi_root = yi-1+yoff
 * 
 *                 if flow_dir_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root) != flow_dir_nodata:
 *                     # already been defined
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1701
 *                 # undefined, the largest slope seen so far is flat, and the
 *                 # largest nodata is at least a diagonal away
 *                 sum_of_downhill_slopes = 0.0             # <<<<<<<<<<<<<<
 *                 for i_n in range(8):
 *                     # initialize downhill slopes to 0.0
 */
        __pyx_v_sum_of_downhill_slopes = 0.0;

        /* "pygeoprocessing/routing/routing.pyx":1702
 *                 # largest nodata is at least a diagonal away
 *                 sum_of_downhill_slopes = 0.0
 *                 for i_n in range(8):             # <<<<<<<<<<<<<<
 *                     # initialize downhill slopes to 0.0
 *                     downhill_slope_array[i_n] = 0.0
 */
        for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
          __pyx_v_i_n = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1704
 *                 for i_n in range(8):
 *                     # initialize downhill slopes to 0.0
 *                     downhill_slope_array[i_n] = 0.0             # <<<<<<<<<<<<<<
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = 0.0;

          /* "pygeoprocessing/routing/routing.pyx":1705
 *                     # initialize downhill slopes to 0.0
 *                     downhill_slope_array[i_n] = 0.0
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 */
          __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

          /* "pygeoprocessing/routing/routing.pyx":1706
 *                     downhill_slope_array[i_n] = 0.0
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):
 */
          __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

          /* "pygeoprocessing/routing/routing.pyx":1707
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]             # <<<<<<<<<<<<<<
 *                     if is_close(n_height, dem_nodata):
 *                         continue
 */
          __pyx_t_29 = __pyx_v_yi_n;
          __pyx_t_30 = __pyx_v_xi_n;
          __pyx_t_31 = -1;
          if (__pyx_t_29 < 0) {
            __pyx_t_29 += __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape;
            if (unlikely(__pyx_t_29 < 0)) __pyx_t_31 = 0;
          } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_dem_buffer_array.diminfo[0].shape)) __pyx_t_31 = 0;
          if (__pyx_t_30 < 0) {
            __pyx_t_30 += __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape;
            if (unlikely(__pyx_t_30 < 0)) __pyx_t_31 = 1;
          } else if (unlikely(__pyx_t_30 >= __pyx_pybuffernd_dem_buffer_array.diminfo[1].shape)) __pyx_t_31 = 1;
          if (unlikely(__pyx_t_31 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_31);
            __PYX_ERR(0, 1707, __pyx_L1_error)
          }
          __pyx_v_n_height = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_dem_buffer_array.diminfo[0].strides, __pyx_t_30, __pyx_pybuffernd_dem_buffer_array.diminfo[1].strides));

          /* "pygeoprocessing/routing/routing.pyx":1708
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                         continue
 *                     n_slope = root_height - n_height
 */
          __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_dem_nodata) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1709
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):
 *                         continue             # <<<<<<<<<<<<<<
 *                     n_slope = root_height - n_height
 *                     if n_slope > 0.0:
 */
            goto __pyx_L31_continue;

            /* "pygeoprocessing/routing/routing.pyx":1708
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     n_height = dem_buffer_array[yi_n, xi_n]
 *                     if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                         continue
 *                     n_slope = root_height - n_height
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":1710
 *                     if is_close(n_height, dem_nodata):
 *                         continue
 *                     n_slope = root_height - n_height             # <<<<<<<<<<<<<<
 *                     if n_slope > 0.0:
 *                         if i_n & 1:
 */
          __pyx_v_n_slope = (__pyx_v_root_height - __pyx_v_n_height);

          /* "pygeoprocessing/routing/routing.pyx":1711
 *                         continue
 *                     n_slope = root_height - n_height
 *                     if n_slope > 0.0:             # <<<<<<<<<<<<<<
 *                         if i_n & 1:
 *                             # if diagonal, adjust the slope
 */
          __pyx_t_6 = ((__pyx_v_n_slope > 0.0) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1712
 *                     n_slope = root_height - n_height
 *                     if n_slope > 0.0:
 *                         if i_n & 1:             # <<<<<<<<<<<<<<
 *                             # if diagonal, adjust the slope
 *                             n_slope *= SQRT2_INV
 */
            __pyx_t_6 = ((__pyx_v_i_n & 1) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1714
 *                         if i_n & 1:
 *                             # if diagonal, adjust the slope
 *                             n_slope *= SQRT2_INV             # <<<<<<<<<<<<<<
 *                         downhill_slope_array[i_n] = n_slope
 *                         sum_of_downhill_slopes += n_slope
 */
              __pyx_v_n_slope = (__pyx_v_n_slope * __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV);

              /* "pygeoprocessing/routing/routing.pyx":1712
 *                     n_slope = root_height - n_height
 *                     if n_slope > 0.0:
 *                         if i_n & 1:             # <<<<<<<<<<<<<<
 *                             # if diagonal, adjust the slope
 *                             n_slope *= SQRT2_INV
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1715
 *                             # if diagonal, adjust the slope
 *                             n_slope *= SQRT2_INV
 *                         downhill_slope_array[i_n] = n_slope             # <<<<<<<<<<<<<<
 *                         sum_of_downhill_slopes += n_slope
 * 
 */
            (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = __pyx_v_n_slope;

            /* "pygeoprocessing/routing/routing.pyx":1716
 *                             n_slope *= SQRT2_INV
 *                         downhill_slope_array[i_n] = n_slope
 *                         sum_of_downhill_slopes += n_slope             # <<<<<<<<<<<<<<
 * 
 *                 if sum_of_downhill_slopes > 0.0:
 */
            __pyx_v_sum_of_downhill_slopes = (__pyx_v_sum_of_downhill_slopes + __pyx_v_n_slope);

            /* "pygeoprocessing/routing/routing.pyx":1711
 *                         continue
 *                     n_slope = root_height - n_height
 *                     if n_slope > 0.0:             # <<<<<<<<<<<<<<
 *                         if i_n & 1:
 *                             # if diagonal, adjust the slope
 */
          }
          __pyx_L31_continue:;
        }

        /* "pygeoprocessing/routing/routing.pyx":1718
 *                         sum_of_downhill_slopes += n_slope
 * 
 *                 if sum_of_downhill_slopes > 0.0:             # <<<<<<<<<<<<<<
 *                     compressed_integer_slopes = 0
 *                     for i_n in range(8):
 */
        __pyx_t_6 = ((__pyx_v_sum_of_downhill_slopes > 0.0) != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1719
 * 
 *                 if sum_of_downhill_slopes > 0.0:
 *                     compressed_integer_slopes = 0             # <<<<<<<<<<<<<<
 *                     for i_n in range(8):
 *                         compressed_integer_slopes |= (<int>(
 */
          __pyx_v_compressed_integer_slopes = 0;

          /* "pygeoprocessing/routing/routing.pyx":1720
 *                 if sum_of_downhill_slopes > 0.0:
 *                     compressed_integer_slopes = 0
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         compressed_integer_slopes |= (<int>(
 *                             0.5 + downhill_slope_array[i_n] /
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1722
 *                     for i_n in range(8):
 *                         compressed_integer_slopes |= (<int>(
 *                             0.5 + downhill_slope_array[i_n] /             # <<<<<<<<<<<<<<
 *                             sum_of_downhill_slopes * 0xF)) << (i_n * 4)
 * 
 */
            if (unlikely(__pyx_v_sum_of_downhill_slopes == 0)) {
              PyErr_SetString(PyExc_ZeroDivisionError, "float division");
              __PYX_ERR(0, 1722, __pyx_L1_error)
            }

            /* "pygeoprocessing/routing/routing.pyx":1721
 *                     compressed_integer_slopes = 0
 *                     for i_n in range(8):
 *                         compressed_integer_slopes |= (<int>(             # <<<<<<<<<<<<<<
 *                             0.5 + downhill_slope_array[i_n] /
 *                             sum_of_downhill_slopes * 0xF)) << (i_n * 4)
 */
            __pyx_v_compressed_integer_slopes = (__pyx_v_compressed_integer_slopes | (((int)(0.5 + (((__pyx_v_downhill_slope_array[__pyx_v_i_n]) / __pyx_v_sum_of_downhill_slopes) * 15.0))) << (__pyx_v_i_n * 4)));
          }

          /* "pygeoprocessing/routing/routing.pyx":1725
 *                             sum_of_downhill_slopes * 0xF)) << (i_n * 4)
 * 
 *                     flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root, compressed_integer_slopes)
 *                     continue
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, __pyx_v_compressed_integer_slopes);

          /* "pygeoprocessing/routing/routing.pyx":1727
 *                     flow_dir_managed_raster.set(
 *                         xi_root, yi_root, compressed_integer_slopes)
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 # PHASE 2 - search for what drains the plateau, prefer
 */
          goto __pyx_L27_continue;

          /* "pygeoprocessing/routing/routing.pyx":1718
 *                         sum_of_downhill_slopes += n_slope
 * 
 *                 if sum_of_downhill_slopes > 0.0:             # <<<<<<<<<<<<<<
 *                     compressed_integer_slopes = 0
 *                     for i_n in range(8):
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":1735
 *                 # otherwise, this pixel doesn't drain locally, so it must
 *                 # be a plateau, search for the drains of the plateau
 *                 drain_search_queue.push(CoordinateType(xi_root, yi_root))             # <<<<<<<<<<<<<<
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)
 * 
 */
        __pyx_t_32.xi = __pyx_v_xi_root;
        __pyx_t_32.yi = __pyx_v_yi_root;
        __pyx_v_drain_search_queue.push(__pyx_t_32);

        /* "pygeoprocessing/routing/routing.pyx":1736
 *                 # be a plateau, search for the drains of the plateau
 *                 drain_search_queue.push(CoordinateType(xi_root, yi_root))
 *                 flat_region_mask_managed_raster.set(xi_root, yi_root, 1)             # <<<<<<<<<<<<<<
 * 
 *                 # this loop does a BFS starting at this pixel to all pixels
 */
        __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 1.0);

        /* "pygeoprocessing/routing/routing.pyx":1741
 *                 # of the same height. if a drain is encountered, it is pushed
 *                 # on a queue for later processing.
 *                 while not drain_search_queue.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = drain_search_queue.front().xi
 *                     yi_q = drain_search_queue.front().yi
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_drain_search_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":1742
 *                 # on a queue for later processing.
 *                 while not drain_search_queue.empty():
 *                     xi_q = drain_search_queue.front().xi             # <<<<<<<<<<<<<<
 *                     yi_q = drain_search_queue.front().yi
 *                     drain_search_queue.pop()
 */
          __pyx_t_28 = __pyx_v_drain_search_queue.front().xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1743
 *                 while not drain_search_queue.empty():
 *                     xi_q = drain_search_queue.front().xi
 *                     yi_q = drain_search_queue.front().yi             # <<<<<<<<<<<<<<
 *                     drain_search_queue.pop()
 * 
 */
          __pyx_t_28 = __pyx_v_drain_search_queue.front().yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1744
 *                     xi_q = drain_search_queue.front().xi
 *                     yi_q = drain_search_queue.front().yi
 *                     drain_search_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                     sum_of_slope_weights = 0.0
 */
          __pyx_v_drain_search_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":1746
 *                     drain_search_queue.pop()
 * 
 *                     sum_of_slope_weights = 0.0             # <<<<<<<<<<<<<<
 *                     sum_of_nodata_slope_weights = 0.0
 *                     for i_n in range(8):
 */
          __pyx_v_sum_of_slope_weights = 0.0;

          /* "pygeoprocessing/routing/routing.pyx":1747
 * 
 *                     sum_of_slope_weights = 0.0
 *                     sum_of_nodata_slope_weights = 0.0             # <<<<<<<<<<<<<<
 *                     for i_n in range(8):
 *                         # initialize downhill slopes to 0.0
 */
          __pyx_v_sum_of_nodata_slope_weights = 0.0;

          /* "pygeoprocessing/routing/routing.pyx":1748
 *                     sum_of_slope_weights = 0.0
 *                     sum_of_nodata_slope_weights = 0.0
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         # initialize downhill slopes to 0.0
 *                         downhill_slope_array[i_n] = 0.0
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1750
 *                     for i_n in range(8):
 *                         # initialize downhill slopes to 0.0
 *                         downhill_slope_array[i_n] = 0.0             # <<<<<<<<<<<<<<
 *                         nodata_downhill_slope_array[i_n] = 0.0
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 */
            (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = 0.0;

            /* "pygeoprocessing/routing/routing.pyx":1751
 *                         # initialize downhill slopes to 0.0
 *                         downhill_slope_array[i_n] = 0.0
 *                         nodata_downhill_slope_array[i_n] = 0.0             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
            (__pyx_v_nodata_downhill_slope_array[__pyx_v_i_n]) = 0.0;

            /* "pygeoprocessing/routing/routing.pyx":1752
 *                         downhill_slope_array[i_n] = 0.0
 *                         nodata_downhill_slope_array[i_n] = 0.0
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":1753
 *                         nodata_downhill_slope_array[i_n] = 0.0
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":1755
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L44_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L44_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1756
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             n_height = dem_nodata
 *                         else:
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L44_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L44_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1755
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1757
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata             # <<<<<<<<<<<<<<
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 */
              __pyx_v_n_height = __pyx_v_dem_nodata;

              /* "pygeoprocessing/routing/routing.pyx":1755
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             n_height = dem_nodata
 */
              goto __pyx_L43;
            }

            /* "pygeoprocessing/routing/routing.pyx":1759
 *                             n_height = dem_nodata
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)             # <<<<<<<<<<<<<<
 *                         if is_close(n_height, dem_nodata):
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 */
            /*else*/ {
              __pyx_v_n_height = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);
            }
            __pyx_L43:;

            /* "pygeoprocessing/routing/routing.pyx":1760
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             sum_of_nodata_slope_weights += n_slope
 */
            __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_height, __pyx_v_dem_nodata) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1761
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0             # <<<<<<<<<<<<<<
 *                             sum_of_nodata_slope_weights += n_slope
 *                             nodata_downhill_slope_array[i_n] = n_slope
 */
              if (((__pyx_v_i_n & 1) != 0)) {
                __pyx_t_8 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV;
              } else {
                __pyx_t_8 = 1.0;
              }
              __pyx_v_n_slope = __pyx_t_8;

              /* "pygeoprocessing/routing/routing.pyx":1762
 *                         if is_close(n_height, dem_nodata):
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             sum_of_nodata_slope_weights += n_slope             # <<<<<<<<<<<<<<
 *                             nodata_downhill_slope_array[i_n] = n_slope
 *                             continue
 */
              __pyx_v_sum_of_nodata_slope_weights = (__pyx_v_sum_of_nodata_slope_weights + __pyx_v_n_slope);

              /* "pygeoprocessing/routing/routing.pyx":1763
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             sum_of_nodata_slope_weights += n_slope
 *                             nodata_downhill_slope_array[i_n] = n_slope             # <<<<<<<<<<<<<<
 *                             continue
 *                         n_slope = root_height - n_height
 */
              (__pyx_v_nodata_downhill_slope_array[__pyx_v_i_n]) = __pyx_v_n_slope;

              /* "pygeoprocessing/routing/routing.pyx":1764
 *                             sum_of_nodata_slope_weights += n_slope
 *                             nodata_downhill_slope_array[i_n] = n_slope
 *                             continue             # <<<<<<<<<<<<<<
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:
 */
              goto __pyx_L41_continue;

              /* "pygeoprocessing/routing/routing.pyx":1760
 *                         else:
 *                             n_height = dem_managed_raster.get(xi_n, yi_n)
 *                         if is_close(n_height, dem_nodata):             # <<<<<<<<<<<<<<
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             sum_of_nodata_slope_weights += n_slope
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1765
 *                             nodata_downhill_slope_array[i_n] = n_slope
 *                             continue
 *                         n_slope = root_height - n_height             # <<<<<<<<<<<<<<
 *                         if n_slope < 0:
 *                             continue
 */
            __pyx_v_n_slope = (__pyx_v_root_height - __pyx_v_n_height);

            /* "pygeoprocessing/routing/routing.pyx":1766
 *                             continue
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if n_slope == 0.0:
 */
            __pyx_t_6 = ((__pyx_v_n_slope < 0.0) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1767
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:
 *                             continue             # <<<<<<<<<<<<<<
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(
 */
              goto __pyx_L41_continue;

              /* "pygeoprocessing/routing/routing.pyx":1766
 *                             continue
 *                         n_slope = root_height - n_height
 *                         if n_slope < 0:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if n_slope == 0.0:
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1768
 *                         if n_slope < 0:
 *                             continue
 *                         if n_slope == 0.0:             # <<<<<<<<<<<<<<
 *                             if flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata:
 */
            __pyx_t_6 = ((__pyx_v_n_slope == 0.0) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1770
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata:             # <<<<<<<<<<<<<<
 *                                 # only grow if it's at the same level and not
 *                                 # previously visited
 */
              __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == __pyx_v_mask_nodata) != 0);

              /* "pygeoprocessing/routing/routing.pyx":1769
 *                             continue
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n) == mask_nodata:
 *                                 # only grow if it's at the same level and not
 */
              if (__pyx_t_6) {

                /* "pygeoprocessing/routing/routing.pyx":1774
 *                                 # previously visited
 *                                 drain_search_queue.push(
 *                                     CoordinateType(xi_n, yi_n))             # <<<<<<<<<<<<<<
 *                                 flat_region_mask_managed_raster.set(
 *                                     xi_n, yi_n, 1)
 */
                __pyx_t_32.xi = __pyx_v_xi_n;
                __pyx_t_32.yi = __pyx_v_yi_n;

                /* "pygeoprocessing/routing/routing.pyx":1773
 *                                 # only grow if it's at the same level and not
 *                                 # previously visited
 *                                 drain_search_queue.push(             # <<<<<<<<<<<<<<
 *                                     CoordinateType(xi_n, yi_n))
 *                                 flat_region_mask_managed_raster.set(
 */
                __pyx_v_drain_search_queue.push(__pyx_t_32);

                /* "pygeoprocessing/routing/routing.pyx":1775
 *                                 drain_search_queue.push(
 *                                     CoordinateType(xi_n, yi_n))
 *                                 flat_region_mask_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n, 1)
 *                             continue
 */
                __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flat_region_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0);

                /* "pygeoprocessing/routing/routing.pyx":1769
 *                             continue
 *                         if n_slope == 0.0:
 *                             if flat_region_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n) == mask_nodata:
 *                                 # only grow if it's at the same level and not
 */
              }

              /* "pygeoprocessing/routing/routing.pyx":1777
 *                                 flat_region_mask_managed_raster.set(
 *                                     xi_n, yi_n, 1)
 *                             continue             # <<<<<<<<<<<<<<
 *                         if i_n & 1:
 *                             n_slope *= SQRT2_INV
 */
              goto __pyx_L41_continue;

              /* "pygeoprocessing/routing/routing.pyx":1768
 *                         if n_slope < 0:
 *                             continue
 *                         if n_slope == 0.0:             # <<<<<<<<<<<<<<
 *                             if flat_region_mask_managed_raster.get(
 *                                     xi_n, yi_n) == mask_nodata:
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1778
 *                                     xi_n, yi_n, 1)
 *                             continue
 *                         if i_n & 1:             # <<<<<<<<<<<<<<
 *                             n_slope *= SQRT2_INV
 *                         downhill_slope_array[i_n] = n_slope
 */
            __pyx_t_6 = ((__pyx_v_i_n & 1) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1779
 *                             continue
 *                         if i_n & 1:
 *                             n_slope *= SQRT2_INV             # <<<<<<<<<<<<<<
 *                         downhill_slope_array[i_n] = n_slope
 *                         sum_of_slope_weights += downhill_slope_array[i_n]
 */
              __pyx_v_n_slope = (__pyx_v_n_slope * __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV);

              /* "pygeoprocessing/routing/routing.pyx":1778
 *                                     xi_n, yi_n, 1)
 *                             continue
 *                         if i_n & 1:             # <<<<<<<<<<<<<<
 *                             n_slope *= SQRT2_INV
 *                         downhill_slope_array[i_n] = n_slope
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1780
 *                         if i_n & 1:
 *                             n_slope *= SQRT2_INV
 *                         downhill_slope_array[i_n] = n_slope             # <<<<<<<<<<<<<<
 *                         sum_of_slope_weights += downhill_slope_array[i_n]
 * 
 */
            (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = __pyx_v_n_slope;

            /* "pygeoprocessing/routing/routing.pyx":1781
 *                             n_slope *= SQRT2_INV
 *                         downhill_slope_array[i_n] = n_slope
 *                         sum_of_slope_weights += downhill_slope_array[i_n]             # <<<<<<<<<<<<<<
 * 
 *                     working_downhill_slope_sum = 0.0
 */
            __pyx_v_sum_of_slope_weights = (__pyx_v_sum_of_slope_weights + (__pyx_v_downhill_slope_array[__pyx_v_i_n]));
            __pyx_L41_continue:;
          }

          /* "pygeoprocessing/routing/routing.pyx":1783
 *                         sum_of_slope_weights += downhill_slope_array[i_n]
 * 
 *                     working_downhill_slope_sum = 0.0             # <<<<<<<<<<<<<<
 *                     working_downhill_slope_array = NULL
 *                     if sum_of_slope_weights > 0.0:
 */
          __pyx_v_working_downhill_slope_sum = 0.0;

          /* "pygeoprocessing/routing/routing.pyx":1784
 * 
 *                     working_downhill_slope_sum = 0.0
 *                     working_downhill_slope_array = NULL             # <<<<<<<<<<<<<<
 *                     if sum_of_slope_weights > 0.0:
 *                         working_downhill_slope_array = downhill_slope_array
 */
          __pyx_v_working_downhill_slope_array = NULL;

          /* "pygeoprocessing/routing/routing.pyx":1785
 *                     working_downhill_slope_sum = 0.0
 *                     working_downhill_slope_array = NULL
 *                     if sum_of_slope_weights > 0.0:             # <<<<<<<<<<<<<<
 *                         working_downhill_slope_array = downhill_slope_array
 *                         working_downhill_slope_sum = sum_of_slope_weights
 */
          __pyx_t_6 = ((__pyx_v_sum_of_slope_weights > 0.0) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1786
 *                     working_downhill_slope_array = NULL
 *                     if sum_of_slope_weights > 0.0:
 *                         working_downhill_slope_array = downhill_slope_array             # <<<<<<<<<<<<<<
 *                         working_downhill_slope_sum = sum_of_slope_weights
 *                     elif sum_of_nodata_slope_weights > 0.0:
 */
            __pyx_v_working_downhill_slope_array = __pyx_v_downhill_slope_array;

            /* "pygeoprocessing/routing/routing.pyx":1787
 *                     if sum_of_slope_weights > 0.0:
 *                         working_downhill_slope_array = downhill_slope_array
 *                         working_downhill_slope_sum = sum_of_slope_weights             # <<<<<<<<<<<<<<
 *                     elif sum_of_nodata_slope_weights > 0.0:
 *                         working_downhill_slope_array = (
 */
            __pyx_v_working_downhill_slope_sum = __pyx_v_sum_of_slope_weights;

            /* "pygeoprocessing/routing/routing.pyx":1785
 *                     working_downhill_slope_sum = 0.0
 *                     working_downhill_slope_array = NULL
 *                     if sum_of_slope_weights > 0.0:             # <<<<<<<<<<<<<<
 *                         working_downhill_slope_array = downhill_slope_array
 *                         working_downhill_slope_sum = sum_of_slope_weights
 */
            goto __pyx_L53;
          }

          /* "pygeoprocessing/routing/routing.pyx":1788
 *                         working_downhill_slope_array = downhill_slope_array
 *                         working_downhill_slope_sum = sum_of_slope_weights
 *                     elif sum_of_nodata_slope_weights > 0.0:             # <<<<<<<<<<<<<<
 *                         working_downhill_slope_array = (
 *                             nodata_downhill_slope_array)
 */
          __pyx_t_6 = ((__pyx_v_sum_of_nodata_slope_weights > 0.0) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1790
 *                     elif sum_of_nodata_slope_weights > 0.0:
 *                         working_downhill_slope_array = (
 *                             nodata_downhill_slope_array)             # <<<<<<<<<<<<<<
 *                         working_downhill_slope_sum = (
 *                             sum_of_nodata_slope_weights)
 */
            __pyx_v_working_downhill_slope_array = __pyx_v_nodata_downhill_slope_array;

            /* "pygeoprocessing/routing/routing.pyx":1792
 *                             nodata_downhill_slope_array)
 *                         working_downhill_slope_sum = (
 *                             sum_of_nodata_slope_weights)             # <<<<<<<<<<<<<<
 * 
 *                     if working_downhill_slope_sum > 0.0:
 */
            __pyx_v_working_downhill_slope_sum = __pyx_v_sum_of_nodata_slope_weights;

            /* "pygeoprocessing/routing/routing.pyx":1788
 *                         working_downhill_slope_array = downhill_slope_array
 *                         working_downhill_slope_sum = sum_of_slope_weights
 *                     elif sum_of_nodata_slope_weights > 0.0:             # <<<<<<<<<<<<<<
 *                         working_downhill_slope_array = (
 *                             nodata_downhill_slope_array)
 */
          }
          __pyx_L53:;

          /* "pygeoprocessing/routing/routing.pyx":1794
 *                             sum_of_nodata_slope_weights)
 * 
 *                     if working_downhill_slope_sum > 0.0:             # <<<<<<<<<<<<<<
 *                         compressed_integer_slopes = 0
 *                         for i_n in range(8):
 */
          __pyx_t_6 = ((__pyx_v_working_downhill_slope_sum > 0.0) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1795
 * 
 *                     if working_downhill_slope_sum > 0.0:
 *                         compressed_integer_slopes = 0             # <<<<<<<<<<<<<<
 *                         for i_n in range(8):
 *                             compressed_integer_slopes |= (<int>(
 */
            __pyx_v_compressed_integer_slopes = 0;

            /* "pygeoprocessing/routing/routing.pyx":1796
 *                     if working_downhill_slope_sum > 0.0:
 *                         compressed_integer_slopes = 0
 *                         for i_n in range(8):             # <<<<<<<<<<<<<<
 *                             compressed_integer_slopes |= (<int>(
 *                                 0.5 + working_downhill_slope_array[i_n] /
 */
            for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
              __pyx_v_i_n = __pyx_t_28;

              /* "pygeoprocessing/routing/routing.pyx":1798
 *                         for i_n in range(8):
 *                             compressed_integer_slopes |= (<int>(
 *                                 0.5 + working_downhill_slope_array[i_n] /             # <<<<<<<<<<<<<<
 *                                 working_downhill_slope_sum * 0xF)) << (
 *                                 i_n * 4)
 */
              if (unlikely(__pyx_v_working_downhill_slope_sum == 0)) {
                PyErr_SetString(PyExc_ZeroDivisionError, "float division");
                __PYX_ERR(0, 1798, __pyx_L1_error)
              }

              /* "pygeoprocessing/routing/routing.pyx":1797
 *                         compressed_integer_slopes = 0
 *                         for i_n in range(8):
 *                             compressed_integer_slopes |= (<int>(             # <<<<<<<<<<<<<<
 *                                 0.5 + working_downhill_slope_array[i_n] /
 *                                 working_downhill_slope_sum * 0xF)) << (
 */
              __pyx_v_compressed_integer_slopes = (__pyx_v_compressed_integer_slopes | (((int)(0.5 + (((__pyx_v_working_downhill_slope_array[__pyx_v_i_n]) / __pyx_v_working_downhill_slope_sum) * 15.0))) << (__pyx_v_i_n * 4)));
            }

            /* "pygeoprocessing/routing/routing.pyx":1801
 *                                 working_downhill_slope_sum * 0xF)) << (
 *                                 i_n * 4)
 *                         if sum_of_slope_weights > 0.0:             # <<<<<<<<<<<<<<
 *                             # regular downhill pixel
 *                             flow_dir_managed_raster.set(
 */
            __pyx_t_6 = ((__pyx_v_sum_of_slope_weights > 0.0) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1803
 *                         if sum_of_slope_weights > 0.0:
 *                             # regular downhill pixel
 *                             flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_q, yi_q, compressed_integer_slopes)
 *                             plateau_distance_managed_raster.set(
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, __pyx_v_compressed_integer_slopes);

              /* "pygeoprocessing/routing/routing.pyx":1805
 *                             flow_dir_managed_raster.set(
 *                                 xi_q, yi_q, compressed_integer_slopes)
 *                             plateau_distance_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_q, yi_q, 0.0)
 *                             plateau_drain_mask_managed_raster.set(
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, 0.0);

              /* "pygeoprocessing/routing/routing.pyx":1807
 *                             plateau_distance_managed_raster.set(
 *                                 xi_q, yi_q, 0.0)
 *                             plateau_drain_mask_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_q, yi_q, 1)
 *                             distance_drain_queue.push(
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_drain_mask_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, 1.0);

              /* "pygeoprocessing/routing/routing.pyx":1810
 *                                 xi_q, yi_q, 1)
 *                             distance_drain_queue.push(
 *                                 CoordinateType(xi_q, yi_q))             # <<<<<<<<<<<<<<
 *                         else:
 *                             nodata_distance_drain_queue.push(
 */
              __pyx_t_32.xi = __pyx_v_xi_q;
              __pyx_t_32.yi = __pyx_v_yi_q;

              /* "pygeoprocessing/routing/routing.pyx":1809
 *                             plateau_drain_mask_managed_raster.set(
 *                                 xi_q, yi_q, 1)
 *                             distance_drain_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_q, yi_q))
 *                         else:
 */
              __pyx_v_distance_drain_queue.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1801
 *                                 working_downhill_slope_sum * 0xF)) << (
 *                                 i_n * 4)
 *                         if sum_of_slope_weights > 0.0:             # <<<<<<<<<<<<<<
 *                             # regular downhill pixel
 *                             flow_dir_managed_raster.set(
 */
              goto __pyx_L57;
            }

            /* "pygeoprocessing/routing/routing.pyx":1812
 *                                 CoordinateType(xi_q, yi_q))
 *                         else:
 *                             nodata_distance_drain_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_q, yi_q))
 *                             nodata_flow_dir_queue.push(
 */
            /*else*/ {

              /* "pygeoprocessing/routing/routing.pyx":1813
 *                         else:
 *                             nodata_distance_drain_queue.push(
 *                                 CoordinateType(xi_q, yi_q))             # <<<<<<<<<<<<<<
 *                             nodata_flow_dir_queue.push(
 *                                 compressed_integer_slopes)
 */
              __pyx_t_32.xi = __pyx_v_xi_q;
              __pyx_t_32.yi = __pyx_v_yi_q;

              /* "pygeoprocessing/routing/routing.pyx":1812
 *                                 CoordinateType(xi_q, yi_q))
 *                         else:
 *                             nodata_distance_drain_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_q, yi_q))
 *                             nodata_flow_dir_queue.push(
 */
              __pyx_v_nodata_distance_drain_queue.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1814
 *                             nodata_distance_drain_queue.push(
 *                                 CoordinateType(xi_q, yi_q))
 *                             nodata_flow_dir_queue.push(             # <<<<<<<<<<<<<<
 *                                 compressed_integer_slopes)
 * 
 */
              __pyx_v_nodata_flow_dir_queue.push(__pyx_v_compressed_integer_slopes);
            }
            __pyx_L57:;

            /* "pygeoprocessing/routing/routing.pyx":1794
 *                             sum_of_nodata_slope_weights)
 * 
 *                     if working_downhill_slope_sum > 0.0:             # <<<<<<<<<<<<<<
 *                         compressed_integer_slopes = 0
 *                         for i_n in range(8):
 */
          }
        }

        /* "pygeoprocessing/routing/routing.pyx":1818
 * 
 *                 # if there's no downhill drains, try the nodata drains
 *                 if distance_drain_queue.empty():             # <<<<<<<<<<<<<<
 *                     # push the nodata drain queue over to the drain queue
 *                     # and set all the flow directions on the nodata drain
 */
        __pyx_t_6 = (__pyx_v_distance_drain_queue.empty() != 0);
        if (__pyx_t_6) {

          /* "pygeoprocessing/routing/routing.pyx":1822
 *                     # and set all the flow directions on the nodata drain
 *                     # pixels
 *                     while not nodata_distance_drain_queue.empty():             # <<<<<<<<<<<<<<
 *                         xi_q = nodata_distance_drain_queue.front().xi
 *                         yi_q = nodata_distance_drain_queue.front().yi
 */
          while (1) {
            __pyx_t_6 = ((!(__pyx_v_nodata_distance_drain_queue.empty() != 0)) != 0);
            if (!__pyx_t_6) break;

            /* "pygeoprocessing/routing/routing.pyx":1823
 *                     # pixels
 *                     while not nodata_distance_drain_queue.empty():
 *                         xi_q = nodata_distance_drain_queue.front().xi             # <<<<<<<<<<<<<<
 *                         yi_q = nodata_distance_drain_queue.front().yi
 *                         flow_dir_managed_raster.set(
 */
            __pyx_t_28 = __pyx_v_nodata_distance_drain_queue.front().xi;
            __pyx_v_xi_q = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1824
 *                     while not nodata_distance_drain_queue.empty():
 *                         xi_q = nodata_distance_drain_queue.front().xi
 *                         yi_q = nodata_distance_drain_queue.front().yi             # <<<<<<<<<<<<<<
 *                         flow_dir_managed_raster.set(
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 */
            __pyx_t_28 = __pyx_v_nodata_distance_drain_queue.front().yi;
            __pyx_v_yi_q = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1825
 *                         xi_q = nodata_distance_drain_queue.front().xi
 *                         yi_q = nodata_distance_drain_queue.front().yi
 *                         flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, __pyx_v_nodata_flow_dir_queue.front());

            /* "pygeoprocessing/routing/routing.pyx":1827
 *                         flow_dir_managed_raster.set(
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)             # <<<<<<<<<<<<<<
 *                         plateau_drain_mask_managed_raster.set(xi_q, yi_q, 1)
 *                         distance_drain_queue.push(
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, 0.0);

            /* "pygeoprocessing/routing/routing.pyx":1828
 *                             xi_q, yi_q, nodata_flow_dir_queue.front())
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)
 *                         plateau_drain_mask_managed_raster.set(xi_q, yi_q, 1)             # <<<<<<<<<<<<<<
 *                         distance_drain_queue.push(
 *                             nodata_distance_drain_queue.front())
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_drain_mask_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, 1.0);

            /* "pygeoprocessing/routing/routing.pyx":1829
 *                         plateau_distance_managed_raster.set(xi_q, yi_q, 0.0)
 *                         plateau_drain_mask_managed_raster.set(xi_q, yi_q, 1)
 *                         distance_drain_queue.push(             # <<<<<<<<<<<<<<
 *                             nodata_distance_drain_queue.front())
 *                         nodata_flow_dir_queue.pop()
 */
            __pyx_v_distance_drain_queue.push(__pyx_v_nodata_distance_drain_queue.front());

            /* "pygeoprocessing/routing/routing.pyx":1831
 *                         distance_drain_queue.push(
 *                             nodata_distance_drain_queue.front())
 *                         nodata_flow_dir_queue.pop()             # <<<<<<<<<<<<<<
 *                         nodata_distance_drain_queue.pop()
 *                 else:
 */
            __pyx_v_nodata_flow_dir_queue.pop();

            /* "pygeoprocessing/routing/routing.pyx":1832
 *                             nodata_distance_drain_queue.front())
 *                         nodata_flow_dir_queue.pop()
 *                         nodata_distance_drain_queue.pop()             # <<<<<<<<<<<<<<
 *                 else:
 *                     # clear the nodata drain queues
 */
            __pyx_v_nodata_distance_drain_queue.pop();
          }

          /* "pygeoprocessing/routing/routing.pyx":1818
 * 
 *                 # if there's no downhill drains, try the nodata drains
 *                 if distance_drain_queue.empty():             # <<<<<<<<<<<<<<
 *                     # push the nodata drain queue over to the drain queue
 *                     # and set all the flow directions on the nodata drain
 */
          goto __pyx_L58;
        }

        /* "pygeoprocessing/routing/routing.pyx":1835
 *                 else:
 *                     # clear the nodata drain queues
 *                     nodata_flow_dir_queue = IntQueueType()             # <<<<<<<<<<<<<<
 *                     nodata_distance_drain_queue = CoordinateQueueType()
 * 
 */
        /*else*/ {
          try {
            __pyx_t_33 = __pyx_t_15pygeoprocessing_7routing_7routing_IntQueueType();
          } catch(...) {
            __Pyx_CppExn2PyErr();
            __PYX_ERR(0, 1835, __pyx_L1_error)
          }
          __pyx_v_nodata_flow_dir_queue = __pyx_t_33;

          /* "pygeoprocessing/routing/routing.pyx":1836
 *                     # clear the nodata drain queues
 *                     nodata_flow_dir_queue = IntQueueType()
 *                     nodata_distance_drain_queue = CoordinateQueueType()             # <<<<<<<<<<<<<<
 * 
 *                 # copy the drain queue to another queue
 */
          try {
            __pyx_t_34 = __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType();
          } catch(...) {
            __Pyx_CppExn2PyErr();
            __PYX_ERR(0, 1836, __pyx_L1_error)
          }
          __pyx_v_nodata_distance_drain_queue = __pyx_t_34;
        }
        __pyx_L58:;

        /* "pygeoprocessing/routing/routing.pyx":1839
 * 
 *                 # copy the drain queue to another queue
 *                 for _ in range(distance_drain_queue.size()):             # <<<<<<<<<<<<<<
 *                     distance_drain_queue.push(
 *                         distance_drain_queue.front())
 */
        __pyx_t_35 = __pyx_v_distance_drain_queue.size();
        __pyx_t_36 = __pyx_t_35;
        for (__pyx_t_37 = 0; __pyx_t_37 < __pyx_t_36; __pyx_t_37+=1) {
          __pyx_v__ = __pyx_t_37;

          /* "pygeoprocessing/routing/routing.pyx":1840
 *                 # copy the drain queue to another queue
 *                 for _ in range(distance_drain_queue.size()):
 *                     distance_drain_queue.push(             # <<<<<<<<<<<<<<
 *                         distance_drain_queue.front())
 *                     direction_drain_queue.push(distance_drain_queue.front())
 */
          __pyx_v_distance_drain_queue.push(__pyx_v_distance_drain_queue.front());

          /* "pygeoprocessing/routing/routing.pyx":1842
 *                     distance_drain_queue.push(
 *                         distance_drain_queue.front())
 *                     direction_drain_queue.push(distance_drain_queue.front())             # <<<<<<<<<<<<<<
 *                     distance_drain_queue.pop()
 * 
 */
          __pyx_v_direction_drain_queue.push(__pyx_v_distance_drain_queue.front());

          /* "pygeoprocessing/routing/routing.pyx":1843
 *                         distance_drain_queue.front())
 *                     direction_drain_queue.push(distance_drain_queue.front())
 *                     distance_drain_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                 # PHASE 3 - build up a distance raster for the plateau such
 */
          __pyx_v_distance_drain_queue.pop();
        }

        /* "pygeoprocessing/routing/routing.pyx":1851
 *                 # this loop does a BFS from the plateau drain to any other
 *                 # neighboring undefined pixels
 *                 while not distance_drain_queue.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = distance_drain_queue.front().xi
 *                     yi_q = distance_drain_queue.front().yi
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_distance_drain_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":1852
 *                 # neighboring undefined pixels
 *                 while not distance_drain_queue.empty():
 *                     xi_q = distance_drain_queue.front().xi             # <<<<<<<<<<<<<<
 *                     yi_q = distance_drain_queue.front().yi
 *                     distance_drain_queue.pop()
 */
          __pyx_t_28 = __pyx_v_distance_drain_queue.front().xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1853
 *                 while not distance_drain_queue.empty():
 *                     xi_q = distance_drain_queue.front().xi
 *                     yi_q = distance_drain_queue.front().yi             # <<<<<<<<<<<<<<
 *                     distance_drain_queue.pop()
 * 
 */
          __pyx_t_28 = __pyx_v_distance_drain_queue.front().yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1854
 *                     xi_q = distance_drain_queue.front().xi
 *                     yi_q = distance_drain_queue.front().yi
 *                     distance_drain_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                     drain_distance = plateau_distance_managed_raster.get(
 */
          __pyx_v_distance_drain_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":1856
 *                     distance_drain_queue.pop()
 * 
 *                     drain_distance = plateau_distance_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_q, yi_q)
 * 
 */
          __pyx_v_drain_distance = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q);

          /* "pygeoprocessing/routing/routing.pyx":1859
 *                         xi_q, yi_q)
 * 
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1860
 * 
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":1861
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":1862
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L68_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L68_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1863
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L68_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L68_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1862
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1864
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         n_drain_distance = drain_distance + (
 */
              goto __pyx_L65_continue;

              /* "pygeoprocessing/routing/routing.pyx":1862
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1867
 * 
 *                         n_drain_distance = drain_distance + (
 *                             SQRT2 if i_n & 1 else 1.0)             # <<<<<<<<<<<<<<
 * 
 *                         if is_close(dem_managed_raster.get(
 */
            if (((__pyx_v_i_n & 1) != 0)) {
              __pyx_t_8 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2;
            } else {
              __pyx_t_8 = 1.0;
            }

            /* "pygeoprocessing/routing/routing.pyx":1866
 *                             continue
 * 
 *                         n_drain_distance = drain_distance + (             # <<<<<<<<<<<<<<
 *                             SQRT2 if i_n & 1 else 1.0)
 * 
 */
            __pyx_v_n_drain_distance = (__pyx_v_drain_distance + __pyx_t_8);

            /* "pygeoprocessing/routing/routing.pyx":1869
 *                             SQRT2 if i_n & 1 else 1.0)
 * 
 *                         if is_close(dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n), root_height) and (
 *                                 plateau_distance_managed_raster.get(
 */
            __pyx_t_7 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n), __pyx_v_root_height) != 0);
            if (__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L73_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1872
 *                                 xi_n, yi_n), root_height) and (
 *                                 plateau_distance_managed_raster.get(
 *                                     xi_n, yi_n) > n_drain_distance):             # <<<<<<<<<<<<<<
 *                             # neighbor is at same level and has longer drain
 *                             # flow path than current
 */
            __pyx_t_7 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) > __pyx_v_n_drain_distance) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L73_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1869
 *                             SQRT2 if i_n & 1 else 1.0)
 * 
 *                         if is_close(dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n), root_height) and (
 *                                 plateau_distance_managed_raster.get(
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1875
 *                             # neighbor is at same level and has longer drain
 *                             # flow path than current
 *                             plateau_distance_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n, n_drain_distance)
 *                             distance_drain_queue.push(
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, __pyx_v_n_drain_distance);

              /* "pygeoprocessing/routing/routing.pyx":1878
 *                                 xi_n, yi_n, n_drain_distance)
 *                             distance_drain_queue.push(
 *                                 CoordinateType(xi_n, yi_n))             # <<<<<<<<<<<<<<
 * 
 *                 # PHASE 4 - set the plateau pixel flow direction based on the
 */
              __pyx_t_32.xi = __pyx_v_xi_n;
              __pyx_t_32.yi = __pyx_v_yi_n;

              /* "pygeoprocessing/routing/routing.pyx":1877
 *                             plateau_distance_managed_raster.set(
 *                                 xi_n, yi_n, n_drain_distance)
 *                             distance_drain_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_n, yi_n))
 * 
 */
              __pyx_v_distance_drain_queue.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1869
 *                             SQRT2 if i_n & 1 else 1.0)
 * 
 *                         if is_close(dem_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n), root_height) and (
 *                                 plateau_distance_managed_raster.get(
 */
            }
            __pyx_L65_continue:;
          }
        }

        /* "pygeoprocessing/routing/routing.pyx":1882
 *                 # PHASE 4 - set the plateau pixel flow direction based on the
 *                 # distance to the nearest drain
 *                 while not direction_drain_queue.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = direction_drain_queue.front().xi
 *                     yi_q = direction_drain_queue.front().yi
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_direction_drain_queue.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":1883
 *                 # distance to the nearest drain
 *                 while not direction_drain_queue.empty():
 *                     xi_q = direction_drain_queue.front().xi             # <<<<<<<<<<<<<<
 *                     yi_q = direction_drain_queue.front().yi
 *                     direction_drain_queue.pop()
 */
          __pyx_t_28 = __pyx_v_direction_drain_queue.front().xi;
          __pyx_v_xi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1884
 *                 while not direction_drain_queue.empty():
 *                     xi_q = direction_drain_queue.front().xi
 *                     yi_q = direction_drain_queue.front().yi             # <<<<<<<<<<<<<<
 *                     direction_drain_queue.pop()
 * 
 */
          __pyx_t_28 = __pyx_v_direction_drain_queue.front().yi;
          __pyx_v_yi_q = __pyx_t_28;

          /* "pygeoprocessing/routing/routing.pyx":1885
 *                     xi_q = direction_drain_queue.front().xi
 *                     yi_q = direction_drain_queue.front().yi
 *                     direction_drain_queue.pop()             # <<<<<<<<<<<<<<
 * 
 *                     drain_distance = plateau_distance_managed_raster.get(
 */
          __pyx_v_direction_drain_queue.pop();

          /* "pygeoprocessing/routing/routing.pyx":1887
 *                     direction_drain_queue.pop()
 * 
 *                     drain_distance = plateau_distance_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_q, yi_q)
 * 
 */
          __pyx_v_drain_distance = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q);

          /* "pygeoprocessing/routing/routing.pyx":1890
 *                         xi_q, yi_q)
 * 
 *                     sum_of_slope_weights = 0.0             # <<<<<<<<<<<<<<
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 */
          __pyx_v_sum_of_slope_weights = 0.0;

          /* "pygeoprocessing/routing/routing.pyx":1891
 * 
 *                     sum_of_slope_weights = 0.0
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1892
 *                     sum_of_slope_weights = 0.0
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         downhill_slope_array[i_n] = 0.0
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":1893
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         downhill_slope_array[i_n] = 0.0
 * 
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":1894
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         downhill_slope_array[i_n] = 0.0             # <<<<<<<<<<<<<<
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = 0.0;

            /* "pygeoprocessing/routing/routing.pyx":1896
 *                         downhill_slope_array[i_n] = 0.0
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L80_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L80_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":1897
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L80_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L80_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":1896
 *                         downhill_slope_array[i_n] = 0.0
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1898
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         if dem_managed_raster.get(xi_n, yi_n) != root_height:
 */
              goto __pyx_L77_continue;

              /* "pygeoprocessing/routing/routing.pyx":1896
 *                         downhill_slope_array[i_n] = 0.0
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1900
 *                             continue
 * 
 *                         if dem_managed_raster.get(xi_n, yi_n) != root_height:             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_6 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_dem_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) != __pyx_v_root_height) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1901
 * 
 *                         if dem_managed_raster.get(xi_n, yi_n) != root_height:
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         n_distance = plateau_distance_managed_raster.get(
 */
              goto __pyx_L77_continue;

              /* "pygeoprocessing/routing/routing.pyx":1900
 *                             continue
 * 
 *                         if dem_managed_raster.get(xi_n, yi_n) != root_height:             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1903
 *                             continue
 * 
 *                         n_distance = plateau_distance_managed_raster.get(             # <<<<<<<<<<<<<<
 *                             xi_n, yi_n)
 *                         if n_distance == plateau_distance_nodata:
 */
            __pyx_v_n_distance = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_plateau_distance_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);

            /* "pygeoprocessing/routing/routing.pyx":1905
 *                         n_distance = plateau_distance_managed_raster.get(
 *                             xi_n, yi_n)
 *                         if n_distance == plateau_distance_nodata:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if n_distance < drain_distance:
 */
            __pyx_t_6 = ((__pyx_v_n_distance == __pyx_v_plateau_distance_nodata) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1906
 *                             xi_n, yi_n)
 *                         if n_distance == plateau_distance_nodata:
 *                             continue             # <<<<<<<<<<<<<<
 *                         if n_distance < drain_distance:
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 */
              goto __pyx_L77_continue;

              /* "pygeoprocessing/routing/routing.pyx":1905
 *                         n_distance = plateau_distance_managed_raster.get(
 *                             xi_n, yi_n)
 *                         if n_distance == plateau_distance_nodata:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if n_distance < drain_distance:
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":1907
 *                         if n_distance == plateau_distance_nodata:
 *                             continue
 *                         if n_distance < drain_distance:             # <<<<<<<<<<<<<<
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             downhill_slope_array[i_n] = n_slope
 */
            __pyx_t_6 = ((__pyx_v_n_distance < __pyx_v_drain_distance) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1908
 *                             continue
 *                         if n_distance < drain_distance:
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0             # <<<<<<<<<<<<<<
 *                             downhill_slope_array[i_n] = n_slope
 *                             sum_of_slope_weights += n_slope
 */
              if (((__pyx_v_i_n & 1) != 0)) {
                __pyx_t_8 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV;
              } else {
                __pyx_t_8 = 1.0;
              }
              __pyx_v_n_slope = __pyx_t_8;

              /* "pygeoprocessing/routing/routing.pyx":1909
 *                         if n_distance < drain_distance:
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             downhill_slope_array[i_n] = n_slope             # <<<<<<<<<<<<<<
 *                             sum_of_slope_weights += n_slope
 *                         elif not plateau_drain_mask_managed_raster.get(
 */
              (__pyx_v_downhill_slope_array[__pyx_v_i_n]) = __pyx_v_n_slope;

              /* "pygeoprocessing/routing/routing.pyx":1910
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             downhill_slope_array[i_n] = n_slope
 *                             sum_of_slope_weights += n_slope             # <<<<<<<<<<<<<<
 *                         elif not plateau_drain_mask_managed_raster.get(
 *                                 xi_n, yi_n):
 */
              __pyx_v_sum_of_slope_weights = (__pyx_v_sum_of_slope_weights + __pyx_v_n_slope);

              /* "pygeoprocessing/routing/routing.pyx":1907
 *                         if n_distance == plateau_distance_nodata:
 *                             continue
 *                         if n_distance < drain_distance:             # <<<<<<<<<<<<<<
 *                             n_slope = SQRT2_INV if i_n & 1 else 1.0
 *                             downhill_slope_array[i_n] = n_slope
 */
              goto __pyx_L86;
            }

            /* "pygeoprocessing/routing/routing.pyx":1911
 *                             downhill_slope_array[i_n] = n_slope
 *                             sum_of_slope_weights += n_slope
 *                         elif not plateau_drain_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n):
 *                             direction_drain_queue.push(
 */
            __pyx_t_6 = ((!(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_plateau_drain_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) != 0)) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":1914
 *                                 xi_n, yi_n):
 *                             direction_drain_queue.push(
 *                                 CoordinateType(xi_n, yi_n))             # <<<<<<<<<<<<<<
 *                             plateau_drain_mask_managed_raster.set(
 *                                 xi_n, yi_n, 1)
 */
              __pyx_t_32.xi = __pyx_v_xi_n;
              __pyx_t_32.yi = __pyx_v_yi_n;

              /* "pygeoprocessing/routing/routing.pyx":1913
 *                         elif not plateau_drain_mask_managed_raster.get(
 *                                 xi_n, yi_n):
 *                             direction_drain_queue.push(             # <<<<<<<<<<<<<<
 *                                 CoordinateType(xi_n, yi_n))
 *                             plateau_drain_mask_managed_raster.set(
 */
              __pyx_v_direction_drain_queue.push(__pyx_t_32);

              /* "pygeoprocessing/routing/routing.pyx":1915
 *                             direction_drain_queue.push(
 *                                 CoordinateType(xi_n, yi_n))
 *                             plateau_drain_mask_managed_raster.set(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n, 1)
 * 
 */
              __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_plateau_drain_mask_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n, 1.0);

              /* "pygeoprocessing/routing/routing.pyx":1911
 *                             downhill_slope_array[i_n] = n_slope
 *                             sum_of_slope_weights += n_slope
 *                         elif not plateau_drain_mask_managed_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_n, yi_n):
 *                             direction_drain_queue.push(
 */
            }
            __pyx_L86:;
            __pyx_L77_continue:;
          }

          /* "pygeoprocessing/routing/routing.pyx":1918
 *                                 xi_n, yi_n, 1)
 * 
 *                     if sum_of_slope_weights == 0:             # <<<<<<<<<<<<<<
 *                         continue
 *                     compressed_integer_slopes = 0
 */
          __pyx_t_6 = ((__pyx_v_sum_of_slope_weights == 0.0) != 0);
          if (__pyx_t_6) {

            /* "pygeoprocessing/routing/routing.pyx":1919
 * 
 *                     if sum_of_slope_weights == 0:
 *                         continue             # <<<<<<<<<<<<<<
 *                     compressed_integer_slopes = 0
 *                     for i_n in range(8):
 */
            goto __pyx_L75_continue;

            /* "pygeoprocessing/routing/routing.pyx":1918
 *                                 xi_n, yi_n, 1)
 * 
 *                     if sum_of_slope_weights == 0:             # <<<<<<<<<<<<<<
 *                         continue
 *                     compressed_integer_slopes = 0
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":1920
 *                     if sum_of_slope_weights == 0:
 *                         continue
 *                     compressed_integer_slopes = 0             # <<<<<<<<<<<<<<
 *                     for i_n in range(8):
 *                         compressed_integer_slopes |= (<int>(
 */
          __pyx_v_compressed_integer_slopes = 0;

          /* "pygeoprocessing/routing/routing.pyx":1921
 *                         continue
 *                     compressed_integer_slopes = 0
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         compressed_integer_slopes |= (<int>(
 *                             0.5 + downhill_slope_array[i_n] /
 */
          for (__pyx_t_28 = 0; __pyx_t_28 < 8; __pyx_t_28+=1) {
            __pyx_v_i_n = __pyx_t_28;

            /* "pygeoprocessing/routing/routing.pyx":1923
 *                     for i_n in range(8):
 *                         compressed_integer_slopes |= (<int>(
 *                             0.5 + downhill_slope_array[i_n] /             # <<<<<<<<<<<<<<
 *                             sum_of_slope_weights * 0xF)) << (i_n * 4)
 *                     flow_dir_managed_raster.set(
 */
            if (unlikely(__pyx_v_sum_of_slope_weights == 0)) {
              PyErr_SetString(PyExc_ZeroDivisionError, "float division");
              __PYX_ERR(0, 1923, __pyx_L1_error)
            }

            /* "pygeoprocessing/routing/routing.pyx":1922
 *                     compressed_integer_slopes = 0
 *                     for i_n in range(8):
 *                         compressed_integer_slopes |= (<int>(             # <<<<<<<<<<<<<<
 *                             0.5 + downhill_slope_array[i_n] /
 *                             sum_of_slope_weights * 0xF)) << (i_n * 4)
 */
            __pyx_v_compressed_integer_slopes = (__pyx_v_compressed_integer_slopes | (((int)(0.5 + (((__pyx_v_downhill_slope_array[__pyx_v_i_n]) / __pyx_v_sum_of_slope_weights) * 15.0))) << (__pyx_v_i_n * 4)));
          }

          /* "pygeoprocessing/routing/routing.pyx":1925
 *                             0.5 + downhill_slope_array[i_n] /
 *                             sum_of_slope_weights * 0xF)) << (i_n * 4)
 *                     flow_dir_managed_raster.set(             # <<<<<<<<<<<<<<
 *                         xi_q, yi_q, compressed_integer_slopes)
 * 
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, __pyx_v_compressed_integer_slopes);
          __pyx_L75_continue:;
        }
        __pyx_L27_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":1648
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             compatable_dem_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1928
 *                         xi_q, yi_q, compressed_integer_slopes)
 * 
 *     dem_band = None             # <<<<<<<<<<<<<<
 *     dem_raster = None
 *     plateau_drain_mask_managed_raster.close()
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_dem_band, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":1929
 * 
 *     dem_band = None
 *     dem_raster = None             # <<<<<<<<<<<<<<
 *     plateau_drain_mask_managed_raster.close()
 *     flow_dir_managed_raster.close()
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_dem_raster, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":1930
 *     dem_band = None
 *     dem_raster = None
 *     plateau_drain_mask_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flow_dir_managed_raster.close()
 *     flat_region_mask_managed_raster.close()
 */
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_plateau_drain_mask_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1930, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1930, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1930, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1931
 *     dem_raster = None
 *     plateau_drain_mask_managed_raster.close()
 *     flow_dir_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flat_region_mask_managed_raster.close()
 *     dem_managed_raster.close()
 */
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1931, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1931, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1931, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1932
 *     plateau_drain_mask_managed_raster.close()
 *     flow_dir_managed_raster.close()
 *     flat_region_mask_managed_raster.close()             # <<<<<<<<<<<<<<
 *     dem_managed_raster.close()
 *     plateau_distance_managed_raster.close()
 */
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flat_region_mask_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1932, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1932, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1932, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1933
 *     flow_dir_managed_raster.close()
 *     flat_region_mask_managed_raster.close()
 *     dem_managed_raster.close()             # <<<<<<<<<<<<<<
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 */
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dem_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1933, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1933, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1933, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1934
 *     flat_region_mask_managed_raster.close()
 *     dem_managed_raster.close()
 *     plateau_distance_managed_raster.close()             # <<<<<<<<<<<<<<
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_plateau_distance_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1934, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
    __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15);
    if (likely(__pyx_t_16)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
      __Pyx_INCREF(__pyx_t_16);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_15, function);
    }
  }
  if (__pyx_t_16) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1934, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  } else {
    __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1934, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1935
 *     dem_managed_raster.close()
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)             # <<<<<<<<<<<<<<
 *     LOGGER.info('%.1f%% complete', 100.0)
 * 
 */
  __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_shutil); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_rmtree); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_16);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_16, function);
    }
  }
  if (!__pyx_t_15) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_v_working_dir_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1935, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_16)) {
      PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_v_working_dir_path};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1935, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
      PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_v_working_dir_path};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1935, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1935, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_15); __pyx_t_15 = NULL;
      __Pyx_INCREF(__pyx_v_working_dir_path);
      __Pyx_GIVEREF(__pyx_v_working_dir_path);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_working_dir_path);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1935, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1936
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_info); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_16);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1448
 * 
 * 
 * def flow_dir_mfd(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path, working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_dir_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_dem_buffer_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dem_buffer_array);
  __Pyx_XDECREF(__pyx_v_dem_raster_info);
  __Pyx_XDECREF(__pyx_v_base_nodata);
  __Pyx_XDECREF(__pyx_v_working_dir_path);
  __Pyx_XDECREF(__pyx_v_flat_region_mask_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_flat_region_mask_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster);
  __Pyx_XDECREF(__pyx_v_plateu_drain_mask_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_plateau_drain_mask_managed_raster);
  __Pyx_XDECREF(__pyx_v_plateau_distance_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_plateau_distance_managed_raster);
  __Pyx_XDECREF(__pyx_v_compatable_dem_raster_path_band);
  __Pyx_XDECREF(__pyx_v_dem_block_xsize);
  __Pyx_XDECREF(__pyx_v_dem_block_ysize);
  __Pyx_XDECREF(__pyx_v_geotiff_driver);
  __Pyx_XDECREF(__pyx_v_dem_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_dem_managed_raster);
  __Pyx_XDECREF(__pyx_v_dem_band);
  __Pyx_XDECREF(__pyx_v_offset_dict);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_modified_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":1939
 * 
 * 
 * def flow_accumulation_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_10flow_accumulation_mfd[] = "Multiple flow direction accumulation.\n\n    Parameters:\n        flow_dir_mfd_raster_path_band (tuple): a path, band number tuple\n            for a multiple flow direction raster generated from a call to\n            `flow_dir_mfd`. The format of this raster is described in the\n            docstring of that function.\n        target_flow_accum_raster_path (string): a path to a raster created by\n            a call to this function that is the same dimensions and projection\n            as `flow_dir_mfd_raster_path_band[0]`. The value in each pixel is\n            1 plus the proportional contribution of all upstream pixels that\n            flow into it. The proportion is determined as the value of the\n            upstream flow dir pixel in the downslope direction pointing to\n            the current pixel divided by the sum of all the flow weights\n            exiting that pixel. Note the target type of this raster\n            is a 64 bit float so there is minimal risk of overflow and the\n            possibility of handling a float dtype in\n            `weight_raster_path_band`.\n        weight_raster_path_band (tuple): optional path and band number to a\n            raster that will be used as the per-pixel flow accumulation\n            weight. If `None`, 1 is the default flow accumulation weight.\n            This raster must be the same dimensions as\n            `flow_dir_mfd_raster_path_band`. If a weight nodata pixel is\n            encountered it will be treated as a weight value of 0.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd = {"flow_accumulation_mfd", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_10flow_accumulation_mfd};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_flow_dir_mfd_raster_path_band = 0;
  PyObject *__pyx_v_target_flow_accum_raster_path = 0;
  PyObject *__pyx_v_weight_raster_path_band = 0;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("flow_accumulation_mfd (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_mfd_raster_path_band,&__pyx_n_s_target_flow_accum_raster_path,&__pyx_n_s_weight_raster_path_band,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pygeoprocessing/routing/routing.pyx":1941
 * def flow_accumulation_mfd(
 *         flow_dir_mfd_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 *     """Multiple flow direction accumulation.
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = __pyx_k__22;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_mfd_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_flow_accum_raster_path)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("flow_accumulation_mfd", 0, 2, 4, 1); __PYX_ERR(0, 1939, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_weight_raster_path_band);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "flow_accumulation_mfd") < 0)) __PYX_ERR(0, 1939, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_flow_dir_mfd_raster_path_band = values[0];
    __pyx_v_target_flow_accum_raster_path = values[1];
    __pyx_v_weight_raster_path_band = values[2];
    __pyx_v_gtiff_creation_options = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("flow_accumulation_mfd", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1939, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_accumulation_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_10flow_accumulation_mfd(__pyx_self, __pyx_v_flow_dir_mfd_raster_path_band, __pyx_v_target_flow_accum_raster_path, __pyx_v_weight_raster_path_band, __pyx_v_gtiff_creation_options);

  /* "pygeoprocessing/routing/routing.pyx":1939
 * 
 * 
 * def flow_accumulation_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_10flow_accumulation_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_mfd_raster_path_band, PyObject *__pyx_v_target_flow_accum_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options) {
  PyArrayObject *__pyx_v_flow_dir_mfd_buffer_array = 0;
  int __pyx_v_win_ysize;
  int __pyx_v_win_xsize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_xi_root;
  int __pyx_v_yi_root;
  int __pyx_v_i_n;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  int __pyx_v_i_upstream_flow;
  int __pyx_v_flow_dir_mfd;
  int __pyx_v_upstream_flow_weight;
  int __pyx_v_compressed_upstream_flow_dir;
  int __pyx_v_upstream_flow_dir_sum;
  double __pyx_v_upstream_flow_accum;
  double __pyx_v_flow_accum_nodata;
  double __pyx_v_weight_nodata;
  double __pyx_v_weight_val;
  std::stack<struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType>  __pyx_v_search_stack;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_v_flow_pixel;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  time_t __pyx_v_last_log_time;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_accum_managed_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_managed_raster = NULL;
  PyObject *__pyx_v_flow_dir_raster = NULL;
  PyObject *__pyx_v_flow_dir_band = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_weight_raster = 0;
  PyObject *__pyx_v_raw_weight_nodata = NULL;
  PyObject *__pyx_v_flow_dir_raster_info = NULL;
  PyObject *__pyx_v_offset_dict = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_modified_offset_dict = NULL;
  long __pyx_v_preempted;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_flow_dir_mfd_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_flow_dir_mfd_buffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  double __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  long __pyx_t_23;
  long __pyx_t_24;
  long __pyx_t_25;
  long __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  int __pyx_t_29;
  Py_ssize_t __pyx_t_30;
  Py_ssize_t __pyx_t_31;
  int __pyx_t_32;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_33;
  __Pyx_RefNannySetupContext("flow_accumulation_mfd", 0);
  __pyx_pybuffer_flow_dir_mfd_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_flow_dir_mfd_buffer_array.refcount = 0;
  __pyx_pybuffernd_flow_dir_mfd_buffer_array.data = NULL;
  __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer = &__pyx_pybuffer_flow_dir_mfd_buffer_array;

  /* "pygeoprocessing/routing/routing.pyx":1999
 *     cdef double upstream_flow_accum
 * 
 *     cdef double flow_accum_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 *     cdef double weight_nodata = IMPROBABLE_FLOAT_NODATA
 * 
 */
  __pyx_v_flow_accum_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;

  /* "pygeoprocessing/routing/routing.pyx":2000
 * 
 *     cdef double flow_accum_nodata = IMPROBABLE_FLOAT_NODATA
 *     cdef double weight_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 * 
 *     # this value is used to store the current weight which might be 1 or
 */
  __pyx_v_weight_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;

  /* "pygeoprocessing/routing/routing.pyx":2017
 *     # used for time-delayed logging
 *     cdef time_t last_log_time
 *     last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_mfd_raster_path_band):
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":2019
 *     last_log_time = ctime(NULL)
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_mfd_raster_path_band):             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2019, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_flow_dir_mfd_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2019, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_flow_dir_mfd_raster_path_band};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2019, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_flow_dir_mfd_raster_path_band};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2019, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2019, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_flow_dir_mfd_raster_path_band);
      __Pyx_GIVEREF(__pyx_v_flow_dir_mfd_raster_path_band);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_flow_dir_mfd_raster_path_band);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2019, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2019, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "pygeoprocessing/routing/routing.pyx":2021
 *     if not _is_raster_path_band_formatted(flow_dir_mfd_raster_path_band):
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (             # <<<<<<<<<<<<<<
 *                 flow_dir_mfd_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_is_supposed_to_be_a_raster_ba, __pyx_v_flow_dir_mfd_raster_path_band); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2021, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "pygeoprocessing/routing/routing.pyx":2020
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_mfd_raster_path_band):
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_mfd_raster_path_band))
 */
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2020, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2020, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":2019
 *     last_log_time = ctime(NULL)
 * 
 *     if not _is_raster_path_band_formatted(flow_dir_mfd_raster_path_band):             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2023
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_mfd_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         raise ValueError(
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2023, __pyx_L1_error)
  if (__pyx_t_5) {
  } else {
    __pyx_t_6 = __pyx_t_5;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2023, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":2024
 *                 flow_dir_mfd_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(
 *             weight_raster_path_band):             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (
 */
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2023, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_weight_raster_path_band};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2023, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_weight_raster_path_band};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2023, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2023, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_INCREF(__pyx_v_weight_raster_path_band);
      __Pyx_GIVEREF(__pyx_v_weight_raster_path_band);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_weight_raster_path_band);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2023, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2023
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_mfd_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         raise ValueError(
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2023, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = ((!__pyx_t_5) != 0);
  __pyx_t_6 = __pyx_t_7;
  __pyx_L5_bool_binop_done:;
  if (unlikely(__pyx_t_6)) {

    /* "pygeoprocessing/routing/routing.pyx":2026
 *             weight_raster_path_band):
 *         raise ValueError(
 *             "%s is supposed to be a raster band tuple but it's not." % (             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band))
 * 
 */
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_is_supposed_to_be_a_raster_ba, __pyx_v_weight_raster_path_band); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2026, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "pygeoprocessing/routing/routing.pyx":2025
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(
 *             weight_raster_path_band):
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 weight_raster_path_band))
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2025, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2025, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":2023
 *             "%s is supposed to be a raster band tuple but it's not." % (
 *                 flow_dir_mfd_raster_path_band))
 *     if weight_raster_path_band and not _is_raster_path_band_formatted(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         raise ValueError(
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2029
 *                 weight_raster_path_band))
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2030
 * 
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path,             # <<<<<<<<<<<<<<
 *         gdal.GDT_Float64, [flow_accum_nodata],
 *         fill_value_list=[flow_accum_nodata],
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2030, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":2031
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],             # <<<<<<<<<<<<<<
 *         fill_value_list=[flow_accum_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_flow_accum_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2031, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_3);
  PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2029
 *                 weight_raster_path_band))
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_target_flow_accum_raster_path);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_8);
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2032
 *         flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 *         fill_value_list=[flow_accum_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 * 
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2032, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_4 = PyFloat_FromDouble(__pyx_v_flow_accum_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2032, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2032, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_fill_value_list, __pyx_t_1) < 0) __PYX_ERR(0, 2032, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2033
 *         gdal.GDT_Float64, [flow_accum_nodata],
 *         fill_value_list=[flow_accum_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 * 
 *     flow_accum_managed_raster = _ManagedRaster(
 */
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 2032, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2029
 *                 weight_raster_path_band))
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0], target_flow_accum_raster_path,
 *         gdal.GDT_Float64, [flow_accum_nodata],
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2035
 *         gtiff_creation_options=gtiff_creation_options)
 * 
 *     flow_accum_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         target_flow_accum_raster_path, 1, 1)
 * 
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_target_flow_accum_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_flow_accum_raster_path);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_target_flow_accum_raster_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_1);
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2035, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_flow_accum_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2039
 * 
 *     flow_dir_managed_raster = _ManagedRaster(
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *     flow_dir_raster = gdal.OpenEx(
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)
 */
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2039, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":2038
 *         target_flow_accum_raster_path, 1, 1)
 * 
 *     flow_dir_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)
 *     flow_dir_raster = gdal.OpenEx(
 */
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_0);
  __pyx_t_8 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2038, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_flow_dir_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2040
 *     flow_dir_managed_raster = _ManagedRaster(
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)
 *     flow_dir_raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_band = flow_dir_raster.GetRasterBand(
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2040, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2041
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)
 *     flow_dir_raster = gdal.OpenEx(
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     flow_dir_band = flow_dir_raster.GetRasterBand(
 *         flow_dir_mfd_raster_path_band[1])
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2041, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2041, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2041, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_9 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
      __pyx_t_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_3, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2040, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_3, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2040, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  {
    __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2040, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2040, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_flow_dir_raster = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2042
 *     flow_dir_raster = gdal.OpenEx(
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_band = flow_dir_raster.GetRasterBand(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[1])
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2042, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":2043
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_band = flow_dir_raster.GetRasterBand(
 *         flow_dir_mfd_raster_path_band[1])             # <<<<<<<<<<<<<<
 * 
 *     cdef _ManagedRaster weight_raster = None
 */
  __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2043, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2042, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2042, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2042, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2042, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2042, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_flow_dir_band = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2045
 *         flow_dir_mfd_raster_path_band[1])
 * 
 *     cdef _ManagedRaster weight_raster = None             # <<<<<<<<<<<<<<
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_weight_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)Py_None);

  /* "pygeoprocessing/routing/routing.pyx":2046
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2046, __pyx_L1_error)
  if (__pyx_t_6) {

    /* "pygeoprocessing/routing/routing.pyx":2048
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2048, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2048, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "pygeoprocessing/routing/routing.pyx":2047
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 */
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2047, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_0);
    __pyx_t_1 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2047, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8));
    __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2049
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2049, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2050
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2050, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_10) {
      __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2049, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_8);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_3};
        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2049, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_3};
        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2049, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else
      #endif
      {
        __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2049, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); __pyx_t_10 = NULL;
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2049, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_8, __pyx_n_s_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2050, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2051
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata
 */
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2051, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_t_8, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2051, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2050
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2050, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_raw_weight_nodata = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2052
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 * 
 */
    __pyx_t_6 = (__pyx_v_raw_weight_nodata != Py_None);
    __pyx_t_7 = (__pyx_t_6 != 0);
    if (__pyx_t_7) {

      /* "pygeoprocessing/routing/routing.pyx":2053
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata             # <<<<<<<<<<<<<<
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 */
      __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_v_raw_weight_nodata); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2053, __pyx_L1_error)
      __pyx_v_weight_nodata = __pyx_t_11;

      /* "pygeoprocessing/routing/routing.pyx":2052
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 * 
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":2046
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2055
 *             weight_nodata = raw_weight_nodata
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2056
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_mfd_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 * 
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2055, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_8);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2055, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2055, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2055, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2055, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_flow_dir_raster_info = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2057
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_mfd_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 */
  __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
    PyObject* sequence = __pyx_t_8;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 2057, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_10);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    #endif
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_12 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_12(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L9_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_4); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_10);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_4), 2) < 0) __PYX_ERR(0, 2057, __pyx_L1_error)
    __pyx_t_12 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L10_unpacking_done;
    __pyx_L9_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_12 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 2057, __pyx_L1_error)
    __pyx_L10_unpacking_done:;
  }
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2057, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2057, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_v_raster_x_size = __pyx_t_9;
  __pyx_v_raster_y_size = __pyx_t_13;

  /* "pygeoprocessing/routing/routing.pyx":2060
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_mfd_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2061
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             flow_dir_mfd_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":2060
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_mfd_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2061
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(
 *             flow_dir_mfd_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2061, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2061, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2060
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_mfd_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_8 = __pyx_t_4; __Pyx_INCREF(__pyx_t_8); __pyx_t_14 = 0;
    __pyx_t_15 = NULL;
  } else {
    __pyx_t_14 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2060, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2060, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_15)) {
      if (likely(PyList_CheckExact(__pyx_t_8))) {
        if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_4); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2060, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2060, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_4); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 2060, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2060, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_15(__pyx_t_8);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2060, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2063
 *             flow_dir_mfd_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_win_xsize = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":2064
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']             # <<<<<<<<<<<<<<
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2064, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2064, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_win_ysize = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":2065
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']             # <<<<<<<<<<<<<<
 *         yoff = offset_dict['yoff']
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2065, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2065, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_xoff = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":2066
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']             # <<<<<<<<<<<<<<
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2066, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2066, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_yoff = __pyx_t_13;

    /* "pygeoprocessing/routing/routing.pyx":2068
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    __pyx_t_7 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
    if (__pyx_t_7) {

      /* "pygeoprocessing/routing/routing.pyx":2069
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
      __pyx_v_last_log_time = time(NULL);

      /* "pygeoprocessing/routing/routing.pyx":2070
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))
 */
      __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2070, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pygeoprocessing/routing/routing.pyx":2071
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "pygeoprocessing/routing/routing.pyx":2072
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 */
      __pyx_t_3 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);

      /* "pygeoprocessing/routing/routing.pyx":2071
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_13 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_13 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_10)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_2};
        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2071, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_2};
        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2071, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2071, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_13, __pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_13, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2071, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "pygeoprocessing/routing/routing.pyx":2068
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":2075
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_mfd_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2076
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_mfd_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.int32)
 *         flow_dir_mfd_buffer_array[:] = 0  # 0 means no flow at all
 */
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
    __pyx_t_1 = 0;
    __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2075
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_mfd_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2077
 *         flow_dir_mfd_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_buffer_array[:] = 0  # 0 means no flow at all
 * 
 */
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2077, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2077, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2077, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 2077, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2075
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         flow_dir_mfd_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2075, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_3);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer);
      __pyx_t_13 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_13 < 0)) {
        PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_flow_dir_mfd_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
        }
        __pyx_t_17 = __pyx_t_18 = __pyx_t_19 = 0;
      }
      __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].strides = __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape = __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].strides = __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape = __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 2075, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __Pyx_XDECREF_SET(__pyx_v_flow_dir_mfd_buffer_array, ((PyArrayObject *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2078
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 *         flow_dir_mfd_buffer_array[:] = 0  # 0 means no flow at all             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_mfd_buffer_array), __pyx_slice__23, __pyx_int_0) < 0)) __PYX_ERR(0, 2078, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":2082
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2082, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "pygeoprocessing/routing/routing.pyx":2083
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.int32)
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2083, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2083, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_1 = NULL;
    __pyx_t_13 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_13 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_10};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_offset_dict, __pyx_t_2, __pyx_t_10};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    } else
    #endif
    {
      __pyx_t_20 = PyTuple_New(3+__pyx_t_13); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(__pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_v_offset_dict);
      PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_13, __pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_13, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_13, __pyx_t_10);
      __pyx_t_2 = 0;
      __pyx_t_10 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2082, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_20);
      #else
      __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_4 = __pyx_t_12(__pyx_t_10); if (unlikely(!__pyx_t_4)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      index = 1; __pyx_t_20 = __pyx_t_12(__pyx_t_10); if (unlikely(!__pyx_t_20)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_20);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_10), 2) < 0) __PYX_ERR(0, 2082, __pyx_L1_error)
      __pyx_t_12 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L15_unpacking_done;
      __pyx_L14_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_12 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2082, __pyx_L1_error)
      __pyx_L15_unpacking_done:;
    }

    /* "pygeoprocessing/routing/routing.pyx":2082
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 */
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2082, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_21 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_21);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_10,&__pyx_t_2,&__pyx_t_1,&__pyx_t_21};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2082, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_10,&__pyx_t_2,&__pyx_t_1,&__pyx_t_21};
      __pyx_t_22 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2082, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_12 = Py_TYPE(__pyx_t_22)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_12(__pyx_t_22); if (unlikely(!item)) goto __pyx_L16_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_22), 4) < 0) __PYX_ERR(0, 2082, __pyx_L1_error)
      __pyx_t_12 = NULL;
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      goto __pyx_L17_unpacking_done;
      __pyx_L16_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      __pyx_t_12 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2082, __pyx_L1_error)
      __pyx_L17_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_10);
    __pyx_t_10 = 0;
    __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_21);
    __pyx_t_21 = 0;
    __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_20);
    __pyx_t_20 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2084
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.int32)
 * 
 */
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);

    /* "pygeoprocessing/routing/routing.pyx":2085
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.int32)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 2085, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_4 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2085, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_4 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2084, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    }

    /* "pygeoprocessing/routing/routing.pyx":2084
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.int32)
 * 
 */
    __pyx_t_21 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2085
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(
 *                 **modified_offset_dict).astype(numpy.int32)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2085, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_t_21 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2085, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_int32); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2085, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_t_21 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_21)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_21);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_21) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_20); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2085, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_t_20};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2085, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_t_20};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2085, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2085, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_21); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_21); __pyx_t_21 = NULL;
        __Pyx_GIVEREF(__pyx_t_20);
        PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_20);
        __pyx_t_20 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2085, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2084
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         flow_dir_mfd_buffer_array[ya:yb, xa:xb] = flow_dir_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *                 **modified_offset_dict).astype(numpy.int32)
 * 
 */
    __pyx_t_4 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_20 = PyTuple_New(2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_mfd_buffer_array), __pyx_t_20, __pyx_t_3) < 0)) __PYX_ERR(0, 2084, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2088
 * 
 *         # ensure these are set for the complier
 *         xi_n = -1             # <<<<<<<<<<<<<<
 *         yi_n = -1
 * 
 */
    __pyx_v_xi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":2089
 *         # ensure these are set for the complier
 *         xi_n = -1
 *         yi_n = -1             # <<<<<<<<<<<<<<
 * 
 *         # search block for to set flow accumulation
 */
    __pyx_v_yi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":2092
 * 
 *         # search block for to set flow accumulation
 *         for yi in range(1, win_ysize+1):             # <<<<<<<<<<<<<<
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir_mfd = flow_dir_mfd_buffer_array[yi, xi]
 */
    __pyx_t_23 = (__pyx_v_win_ysize + 1);
    __pyx_t_24 = __pyx_t_23;
    for (__pyx_t_13 = 1; __pyx_t_13 < __pyx_t_24; __pyx_t_13+=1) {
      __pyx_v_yi = __pyx_t_13;

      /* "pygeoprocessing/routing/routing.pyx":2093
 *         # search block for to set flow accumulation
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):             # <<<<<<<<<<<<<<
 *                 flow_dir_mfd = flow_dir_mfd_buffer_array[yi, xi]
 *                 if flow_dir_mfd == 0:
 */
      __pyx_t_25 = (__pyx_v_win_xsize + 1);
      __pyx_t_26 = __pyx_t_25;
      for (__pyx_t_9 = 1; __pyx_t_9 < __pyx_t_26; __pyx_t_9+=1) {
        __pyx_v_xi = __pyx_t_9;

        /* "pygeoprocessing/routing/routing.pyx":2094
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir_mfd = flow_dir_mfd_buffer_array[yi, xi]             # <<<<<<<<<<<<<<
 *                 if flow_dir_mfd == 0:
 *                     # no flow in this pixel, so skip
 */
        __pyx_t_27 = __pyx_v_yi;
        __pyx_t_28 = __pyx_v_xi;
        __pyx_t_29 = -1;
        if (__pyx_t_27 < 0) {
          __pyx_t_27 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_27 < 0)) __pyx_t_29 = 0;
        } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0;
        if (__pyx_t_28 < 0) {
          __pyx_t_28 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_28 < 0)) __pyx_t_29 = 1;
        } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape)) __pyx_t_29 = 1;
        if (unlikely(__pyx_t_29 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_29);
          __PYX_ERR(0, 2094, __pyx_L1_error)
        }
        __pyx_v_flow_dir_mfd = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].strides));

        /* "pygeoprocessing/routing/routing.pyx":2095
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir_mfd = flow_dir_mfd_buffer_array[yi, xi]
 *                 if flow_dir_mfd == 0:             # <<<<<<<<<<<<<<
 *                     # no flow in this pixel, so skip
 *                     continue
 */
        __pyx_t_7 = ((__pyx_v_flow_dir_mfd == 0) != 0);
        if (__pyx_t_7) {

          /* "pygeoprocessing/routing/routing.pyx":2097
 *                 if flow_dir_mfd == 0:
 *                     # no flow in this pixel, so skip
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 for i_n in range(8):
 */
          goto __pyx_L20_continue;

          /* "pygeoprocessing/routing/routing.pyx":2095
 *             for xi in range(1, win_xsize+1):
 *                 flow_dir_mfd = flow_dir_mfd_buffer_array[yi, xi]
 *                 if flow_dir_mfd == 0:             # <<<<<<<<<<<<<<
 *                     # no flow in this pixel, so skip
 *                     continue
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2099
 *                     continue
 * 
 *                 for i_n in range(8):             # <<<<<<<<<<<<<<
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:
 *                         # no flow in that direction
 */
        for (__pyx_t_29 = 0; __pyx_t_29 < 8; __pyx_t_29+=1) {
          __pyx_v_i_n = __pyx_t_29;

          /* "pygeoprocessing/routing/routing.pyx":2100
 * 
 *                 for i_n in range(8):
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:             # <<<<<<<<<<<<<<
 *                         # no flow in that direction
 *                         continue
 */
          __pyx_t_7 = ((((__pyx_v_flow_dir_mfd >> (__pyx_v_i_n * 4)) & 0xF) == 0) != 0);
          if (__pyx_t_7) {

            /* "pygeoprocessing/routing/routing.pyx":2102
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:
 *                         # no flow in that direction
 *                         continue             # <<<<<<<<<<<<<<
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
            goto __pyx_L23_continue;

            /* "pygeoprocessing/routing/routing.pyx":2100
 * 
 *                 for i_n in range(8):
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:             # <<<<<<<<<<<<<<
 *                         # no flow in that direction
 *                         continue
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":2103
 *                         # no flow in that direction
 *                         continue
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 */
          __pyx_v_xi_n = (__pyx_v_xi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

          /* "pygeoprocessing/routing/routing.pyx":2104
 *                         continue
 *                     xi_n = xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 * 
 *                     if flow_dir_mfd_buffer_array[yi_n, xi_n] == 0:
 */
          __pyx_v_yi_n = (__pyx_v_yi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

          /* "pygeoprocessing/routing/routing.pyx":2106
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                     if flow_dir_mfd_buffer_array[yi_n, xi_n] == 0:             # <<<<<<<<<<<<<<
 *                         # if the entire value is zero, it flows nowhere
 *                         # and the root pixel is draining to it, thus the
 */
          __pyx_t_30 = __pyx_v_yi_n;
          __pyx_t_31 = __pyx_v_xi_n;
          __pyx_t_32 = -1;
          if (__pyx_t_30 < 0) {
            __pyx_t_30 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape;
            if (unlikely(__pyx_t_30 < 0)) __pyx_t_32 = 0;
          } else if (unlikely(__pyx_t_30 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].shape)) __pyx_t_32 = 0;
          if (__pyx_t_31 < 0) {
            __pyx_t_31 += __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape;
            if (unlikely(__pyx_t_31 < 0)) __pyx_t_32 = 1;
          } else if (unlikely(__pyx_t_31 >= __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].shape)) __pyx_t_32 = 1;
          if (unlikely(__pyx_t_32 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_32);
            __PYX_ERR(0, 2106, __pyx_L1_error)
          }
          __pyx_t_7 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[0].strides, __pyx_t_31, __pyx_pybuffernd_flow_dir_mfd_buffer_array.diminfo[1].strides)) == 0) != 0);
          if (__pyx_t_7) {

            /* "pygeoprocessing/routing/routing.pyx":2110
 *                         # and the root pixel is draining to it, thus the
 *                         # root must be a drain
 *                         xi_root = xi-1+xoff             # <<<<<<<<<<<<<<
 *                         yi_root = yi-1+yoff
 *                         if weight_raster is not None:
 */
            __pyx_v_xi_root = ((__pyx_v_xi - 1) + __pyx_v_xoff);

            /* "pygeoprocessing/routing/routing.pyx":2111
 *                         # root must be a drain
 *                         xi_root = xi-1+xoff
 *                         yi_root = yi-1+yoff             # <<<<<<<<<<<<<<
 *                         if weight_raster is not None:
 *                             weight_val = <double>weight_raster.get(
 */
            __pyx_v_yi_root = ((__pyx_v_yi - 1) + __pyx_v_yoff);

            /* "pygeoprocessing/routing/routing.pyx":2112
 *                         xi_root = xi-1+xoff
 *                         yi_root = yi-1+yoff
 *                         if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                             weight_val = <double>weight_raster.get(
 *                                 xi_root, yi_root)
 */
            __pyx_t_7 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
            __pyx_t_6 = (__pyx_t_7 != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":2113
 *                         yi_root = yi-1+yoff
 *                         if weight_raster is not None:
 *                             weight_val = <double>weight_raster.get(             # <<<<<<<<<<<<<<
 *                                 xi_root, yi_root)
 *                             if is_close(weight_val, weight_nodata):
 */
              __pyx_v_weight_val = ((double)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_weight_raster, __pyx_v_xi_root, __pyx_v_yi_root));

              /* "pygeoprocessing/routing/routing.pyx":2115
 *                             weight_val = <double>weight_raster.get(
 *                                 xi_root, yi_root)
 *                             if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                 weight_val = 0.0
 *                         else:
 */
              __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_weight_val, __pyx_v_weight_nodata) != 0);
              if (__pyx_t_6) {

                /* "pygeoprocessing/routing/routing.pyx":2116
 *                                 xi_root, yi_root)
 *                             if is_close(weight_val, weight_nodata):
 *                                 weight_val = 0.0             # <<<<<<<<<<<<<<
 *                         else:
 *                             weight_val = 1.0
 */
                __pyx_v_weight_val = 0.0;

                /* "pygeoprocessing/routing/routing.pyx":2115
 *                             weight_val = <double>weight_raster.get(
 *                                 xi_root, yi_root)
 *                             if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                 weight_val = 0.0
 *                         else:
 */
              }

              /* "pygeoprocessing/routing/routing.pyx":2112
 *                         xi_root = xi-1+xoff
 *                         yi_root = yi-1+yoff
 *                         if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                             weight_val = <double>weight_raster.get(
 *                                 xi_root, yi_root)
 */
              goto __pyx_L27;
            }

            /* "pygeoprocessing/routing/routing.pyx":2118
 *                                 weight_val = 0.0
 *                         else:
 *                             weight_val = 1.0             # <<<<<<<<<<<<<<
 *                         search_stack.push(
 *                             FlowPixelType(xi_root, yi_root, 0, weight_val))
 */
            /*else*/ {
              __pyx_v_weight_val = 1.0;
            }
            __pyx_L27:;

            /* "pygeoprocessing/routing/routing.pyx":2120
 *                             weight_val = 1.0
 *                         search_stack.push(
 *                             FlowPixelType(xi_root, yi_root, 0, weight_val))             # <<<<<<<<<<<<<<
 *                         break
 * 
 */
            __pyx_t_33.xi = __pyx_v_xi_root;
            __pyx_t_33.yi = __pyx_v_yi_root;
            __pyx_t_33.last_flow_dir = 0;
            __pyx_t_33.value = __pyx_v_weight_val;

            /* "pygeoprocessing/routing/routing.pyx":2119
 *                         else:
 *                             weight_val = 1.0
 *                         search_stack.push(             # <<<<<<<<<<<<<<
 *                             FlowPixelType(xi_root, yi_root, 0, weight_val))
 *                         break
 */
            __pyx_v_search_stack.push(__pyx_t_33);

            /* "pygeoprocessing/routing/routing.pyx":2121
 *                         search_stack.push(
 *                             FlowPixelType(xi_root, yi_root, 0, weight_val))
 *                         break             # <<<<<<<<<<<<<<
 * 
 *                 while not search_stack.empty():
 */
            goto __pyx_L24_break;

            /* "pygeoprocessing/routing/routing.pyx":2106
 *                     yi_n = yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                     if flow_dir_mfd_buffer_array[yi_n, xi_n] == 0:             # <<<<<<<<<<<<<<
 *                         # if the entire value is zero, it flows nowhere
 *                         # and the root pixel is draining to it, thus the
 */
          }
          __pyx_L23_continue:;
        }
        __pyx_L24_break:;

        /* "pygeoprocessing/routing/routing.pyx":2123
 *                         break
 * 
 *                 while not search_stack.empty():             # <<<<<<<<<<<<<<
 *                     flow_pixel = search_stack.top()
 *                     search_stack.pop()
 */
        while (1) {
          __pyx_t_6 = ((!(__pyx_v_search_stack.empty() != 0)) != 0);
          if (!__pyx_t_6) break;

          /* "pygeoprocessing/routing/routing.pyx":2124
 * 
 *                 while not search_stack.empty():
 *                     flow_pixel = search_stack.top()             # <<<<<<<<<<<<<<
 *                     search_stack.pop()
 * 
 */
          __pyx_v_flow_pixel = __pyx_v_search_stack.top();

          /* "pygeoprocessing/routing/routing.pyx":2125
 *                 while not search_stack.empty():
 *                     flow_pixel = search_stack.top()
 *                     search_stack.pop()             # <<<<<<<<<<<<<<
 * 
 *                     preempted = 0
 */
          __pyx_v_search_stack.pop();

          /* "pygeoprocessing/routing/routing.pyx":2127
 *                     search_stack.pop()
 * 
 *                     preempted = 0             # <<<<<<<<<<<<<<
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 */
          __pyx_v_preempted = 0;

          /* "pygeoprocessing/routing/routing.pyx":2128
 * 
 *                     preempted = 0
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):             # <<<<<<<<<<<<<<
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_29 = __pyx_v_flow_pixel.last_flow_dir; __pyx_t_29 < 8; __pyx_t_29+=1) {
            __pyx_v_i_n = __pyx_t_29;

            /* "pygeoprocessing/routing/routing.pyx":2129
 *                     preempted = 0
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_xi_n = (__pyx_v_flow_pixel.xi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":2130
 *                     for i_n in range(flow_pixel.last_flow_dir, 8):
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 */
            __pyx_v_yi_n = (__pyx_v_flow_pixel.yi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":2131
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 */
            __pyx_t_7 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L34_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L34_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":2132
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             # no upstream here
 *                             continue
 */
            __pyx_t_7 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_7) {
            } else {
              __pyx_t_6 = __pyx_t_7;
              goto __pyx_L34_bool_binop_done;
            }
            __pyx_t_7 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_6 = __pyx_t_7;
            __pyx_L34_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":2131
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 */
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":2134
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 *                             continue             # <<<<<<<<<<<<<<
 *                         compressed_upstream_flow_dir = (
 *                             <int>flow_dir_managed_raster.get(xi_n, yi_n))
 */
              goto __pyx_L31_continue;

              /* "pygeoprocessing/routing/routing.pyx":2131
 *                         xi_n = flow_pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = flow_pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             # no upstream here
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2136
 *                             continue
 *                         compressed_upstream_flow_dir = (
 *                             <int>flow_dir_managed_raster.get(xi_n, yi_n))             # <<<<<<<<<<<<<<
 *                         upstream_flow_weight = (
 *                             compressed_upstream_flow_dir >> (
 */
            __pyx_v_compressed_upstream_flow_dir = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n));

            /* "pygeoprocessing/routing/routing.pyx":2139
 *                         upstream_flow_weight = (
 *                             compressed_upstream_flow_dir >> (
 *                                 D8_REVERSE_DIRECTION[i_n] * 4)) & 0xF             # <<<<<<<<<<<<<<
 *                         if upstream_flow_weight == 0:
 *                             # no upstream flow to this pixel
 */
            __pyx_v_upstream_flow_weight = ((__pyx_v_compressed_upstream_flow_dir >> ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_i_n]) * 4)) & 0xF);

            /* "pygeoprocessing/routing/routing.pyx":2140
 *                             compressed_upstream_flow_dir >> (
 *                                 D8_REVERSE_DIRECTION[i_n] * 4)) & 0xF
 *                         if upstream_flow_weight == 0:             # <<<<<<<<<<<<<<
 *                             # no upstream flow to this pixel
 *                             continue
 */
            __pyx_t_6 = ((__pyx_v_upstream_flow_weight == 0) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":2142
 *                         if upstream_flow_weight == 0:
 *                             # no upstream flow to this pixel
 *                             continue             # <<<<<<<<<<<<<<
 *                         upstream_flow_accum = (
 *                             flow_accum_managed_raster.get(xi_n, yi_n))
 */
              goto __pyx_L31_continue;

              /* "pygeoprocessing/routing/routing.pyx":2140
 *                             compressed_upstream_flow_dir >> (
 *                                 D8_REVERSE_DIRECTION[i_n] * 4)) & 0xF
 *                         if upstream_flow_weight == 0:             # <<<<<<<<<<<<<<
 *                             # no upstream flow to this pixel
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2144
 *                             continue
 *                         upstream_flow_accum = (
 *                             flow_accum_managed_raster.get(xi_n, yi_n))             # <<<<<<<<<<<<<<
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):
 *                             # process upstream before this one
 */
            __pyx_v_upstream_flow_accum = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);

            /* "pygeoprocessing/routing/routing.pyx":2145
 *                         upstream_flow_accum = (
 *                             flow_accum_managed_raster.get(xi_n, yi_n))
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):             # <<<<<<<<<<<<<<
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n
 */
            __pyx_t_6 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_upstream_flow_accum, __pyx_v_flow_accum_nodata) != 0);
            if (__pyx_t_6) {

              /* "pygeoprocessing/routing/routing.pyx":2147
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n             # <<<<<<<<<<<<<<
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:
 */
              __pyx_v_flow_pixel.last_flow_dir = __pyx_v_i_n;

              /* "pygeoprocessing/routing/routing.pyx":2148
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n
 *                             search_stack.push(flow_pixel)             # <<<<<<<<<<<<<<
 *                             if weight_raster is not None:
 *                                 weight_val = <double>weight_raster.get(
 */
              __pyx_v_search_stack.push(__pyx_v_flow_pixel);

              /* "pygeoprocessing/routing/routing.pyx":2149
 *                             flow_pixel.last_flow_dir = i_n
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 */
              __pyx_t_6 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
              __pyx_t_7 = (__pyx_t_6 != 0);
              if (__pyx_t_7) {

                /* "pygeoprocessing/routing/routing.pyx":2150
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:
 *                                 weight_val = <double>weight_raster.get(             # <<<<<<<<<<<<<<
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):
 */
                __pyx_v_weight_val = ((double)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_weight_raster, __pyx_v_xi_n, __pyx_v_yi_n));

                /* "pygeoprocessing/routing/routing.pyx":2152
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                     weight_val = 0.0
 *                             else:
 */
                __pyx_t_7 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_weight_val, __pyx_v_weight_nodata) != 0);
                if (__pyx_t_7) {

                  /* "pygeoprocessing/routing/routing.pyx":2153
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):
 *                                     weight_val = 0.0             # <<<<<<<<<<<<<<
 *                             else:
 *                                 weight_val = 1.0
 */
                  __pyx_v_weight_val = 0.0;

                  /* "pygeoprocessing/routing/routing.pyx":2152
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                     weight_val = 0.0
 *                             else:
 */
                }

                /* "pygeoprocessing/routing/routing.pyx":2149
 *                             flow_pixel.last_flow_dir = i_n
 *                             search_stack.push(flow_pixel)
 *                             if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                                 weight_val = <double>weight_raster.get(
 *                                     xi_n, yi_n)
 */
                goto __pyx_L40;
              }

              /* "pygeoprocessing/routing/routing.pyx":2155
 *                                     weight_val = 0.0
 *                             else:
 *                                 weight_val = 1.0             # <<<<<<<<<<<<<<
 *                             search_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 */
              /*else*/ {
                __pyx_v_weight_val = 1.0;
              }
              __pyx_L40:;

              /* "pygeoprocessing/routing/routing.pyx":2157
 *                                 weight_val = 1.0
 *                             search_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))             # <<<<<<<<<<<<<<
 *                             preempted = 1
 *                             break
 */
              __pyx_t_33.xi = __pyx_v_xi_n;
              __pyx_t_33.yi = __pyx_v_yi_n;
              __pyx_t_33.last_flow_dir = 0;
              __pyx_t_33.value = __pyx_v_weight_val;

              /* "pygeoprocessing/routing/routing.pyx":2156
 *                             else:
 *                                 weight_val = 1.0
 *                             search_stack.push(             # <<<<<<<<<<<<<<
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 *                             preempted = 1
 */
              __pyx_v_search_stack.push(__pyx_t_33);

              /* "pygeoprocessing/routing/routing.pyx":2158
 *                             search_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 *                             preempted = 1             # <<<<<<<<<<<<<<
 *                             break
 *                         upstream_flow_dir_sum = 0
 */
              __pyx_v_preempted = 1;

              /* "pygeoprocessing/routing/routing.pyx":2159
 *                                 FlowPixelType(xi_n, yi_n, 0, weight_val))
 *                             preempted = 1
 *                             break             # <<<<<<<<<<<<<<
 *                         upstream_flow_dir_sum = 0
 *                         for i_upstream_flow in range(8):
 */
              goto __pyx_L32_break;

              /* "pygeoprocessing/routing/routing.pyx":2145
 *                         upstream_flow_accum = (
 *                             flow_accum_managed_raster.get(xi_n, yi_n))
 *                         if is_close(upstream_flow_accum, flow_accum_nodata):             # <<<<<<<<<<<<<<
 *                             # process upstream before this one
 *                             flow_pixel.last_flow_dir = i_n
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2160
 *                             preempted = 1
 *                             break
 *                         upstream_flow_dir_sum = 0             # <<<<<<<<<<<<<<
 *                         for i_upstream_flow in range(8):
 *                             upstream_flow_dir_sum += (
 */
            __pyx_v_upstream_flow_dir_sum = 0;

            /* "pygeoprocessing/routing/routing.pyx":2161
 *                             break
 *                         upstream_flow_dir_sum = 0
 *                         for i_upstream_flow in range(8):             # <<<<<<<<<<<<<<
 *                             upstream_flow_dir_sum += (
 *                                 compressed_upstream_flow_dir >> (
 */
            for (__pyx_t_32 = 0; __pyx_t_32 < 8; __pyx_t_32+=1) {
              __pyx_v_i_upstream_flow = __pyx_t_32;

              /* "pygeoprocessing/routing/routing.pyx":2162
 *                         upstream_flow_dir_sum = 0
 *                         for i_upstream_flow in range(8):
 *                             upstream_flow_dir_sum += (             # <<<<<<<<<<<<<<
 *                                 compressed_upstream_flow_dir >> (
 *                                     i_upstream_flow * 4)) & 0xF
 */
              __pyx_v_upstream_flow_dir_sum = (__pyx_v_upstream_flow_dir_sum + ((__pyx_v_compressed_upstream_flow_dir >> (__pyx_v_i_upstream_flow * 4)) & 0xF));
            }

            /* "pygeoprocessing/routing/routing.pyx":2167
 * 
 *                         flow_pixel.value += (
 *                             upstream_flow_accum * upstream_flow_weight /             # <<<<<<<<<<<<<<
 *                             <float>upstream_flow_dir_sum)
 *                     if not preempted:
 */
            __pyx_t_11 = (__pyx_v_upstream_flow_accum * __pyx_v_upstream_flow_weight);

            /* "pygeoprocessing/routing/routing.pyx":2168
 *                         flow_pixel.value += (
 *                             upstream_flow_accum * upstream_flow_weight /
 *                             <float>upstream_flow_dir_sum)             # <<<<<<<<<<<<<<
 *                     if not preempted:
 *                         flow_accum_managed_raster.set(
 */
            if (unlikely(((float)__pyx_v_upstream_flow_dir_sum) == 0)) {
              PyErr_SetString(PyExc_ZeroDivisionError, "float division");
              __PYX_ERR(0, 2167, __pyx_L1_error)
            }

            /* "pygeoprocessing/routing/routing.pyx":2166
 *                                     i_upstream_flow * 4)) & 0xF
 * 
 *                         flow_pixel.value += (             # <<<<<<<<<<<<<<
 *                             upstream_flow_accum * upstream_flow_weight /
 *                             <float>upstream_flow_dir_sum)
 */
            __pyx_v_flow_pixel.value = (__pyx_v_flow_pixel.value + (__pyx_t_11 / ((float)__pyx_v_upstream_flow_dir_sum)));
            __pyx_L31_continue:;
          }
          __pyx_L32_break:;

          /* "pygeoprocessing/routing/routing.pyx":2169
 *                             upstream_flow_accum * upstream_flow_weight /
 *                             <float>upstream_flow_dir_sum)
 *                     if not preempted:             # <<<<<<<<<<<<<<
 *                         flow_accum_managed_raster.set(
 *                             flow_pixel.xi, flow_pixel.yi,
 */
          __pyx_t_7 = ((!(__pyx_v_preempted != 0)) != 0);
          if (__pyx_t_7) {

            /* "pygeoprocessing/routing/routing.pyx":2170
 *                             <float>upstream_flow_dir_sum)
 *                     if not preempted:
 *                         flow_accum_managed_raster.set(             # <<<<<<<<<<<<<<
 *                             flow_pixel.xi, flow_pixel.yi,
 *                             flow_pixel.value)
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_flow_accum_managed_raster, __pyx_v_flow_pixel.xi, __pyx_v_flow_pixel.yi, __pyx_v_flow_pixel.value);

            /* "pygeoprocessing/routing/routing.pyx":2169
 *                             upstream_flow_accum * upstream_flow_weight /
 *                             <float>upstream_flow_dir_sum)
 *                     if not preempted:             # <<<<<<<<<<<<<<
 *                         flow_accum_managed_raster.set(
 *                             flow_pixel.xi, flow_pixel.yi,
 */
          }
        }
        __pyx_L20_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":2060
 * 
 *     # this outer loop searches for a pixel that is locally undrained
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             flow_dir_mfd_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2173
 *                             flow_pixel.xi, flow_pixel.yi,
 *                             flow_pixel.value)
 *     flow_accum_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_accum_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_20 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_20)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_20) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_20); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2173, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2173, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2174
 *                             flow_pixel.value)
 *     flow_accum_managed_raster.close()
 *     flow_dir_managed_raster.close()             # <<<<<<<<<<<<<<
 *     if weight_raster is not None:
 *         weight_raster.close()
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_20 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_20)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_20) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_20); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2174, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2174, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2175
 *     flow_accum_managed_raster.close()
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  __pyx_t_7 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
  __pyx_t_6 = (__pyx_t_7 != 0);
  if (__pyx_t_6) {

    /* "pygeoprocessing/routing/routing.pyx":2176
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:
 *         weight_raster.close()             # <<<<<<<<<<<<<<
 *     LOGGER.info('%.1f%% complete', 100.0)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2176, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_20 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_20)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_20);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (__pyx_t_20) {
      __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_20); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2176, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    } else {
      __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2176, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2175
 *     flow_accum_managed_raster.close()
 *     flow_dir_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2177
 *     if weight_raster is not None:
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1939
 * 
 * 
 * def flow_accumulation_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.flow_accumulation_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_mfd_buffer_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_mfd_buffer_array);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_accum_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_managed_raster);
  __Pyx_XDECREF(__pyx_v_flow_dir_raster);
  __Pyx_XDECREF(__pyx_v_flow_dir_band);
  __Pyx_XDECREF((PyObject *)__pyx_v_weight_raster);
  __Pyx_XDECREF(__pyx_v_raw_weight_nodata);
  __Pyx_XDECREF(__pyx_v_flow_dir_raster_info);
  __Pyx_XDECREF(__pyx_v_offset_dict);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_modified_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":2180
 * 
 * 
 * def distance_to_channel_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path,
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_12distance_to_channel_d8[] = "Calculate distance to channel with D8 flow.\n\n    Parameters:\n        flow_dir_d8_raster_path_band (tuple): a path/band index tuple\n            indicating the raster that defines the D8 flow direction\n            raster for this call. The pixel values are integers that\n            correspond to outflow in the following configuration:\n                321\n                4x0\n                567\n        channel_raster_path_band (tuple): a path/band tuple of the same\n            dimensions and projection as `flow_dir_d8_raster_path_band[0]`\n            that indicates where the channels in the problem space lie. A\n            channel is indicated if the value of the pixel is 1. Other values\n            are ignored.\n        target_distance_to_channel_raster_path (string): path to a raster\n            created by this call that has per-pixel distances from a given\n            pixel to the nearest downhill channel.\n        weight_raster_path_band (tuple): optional path and band number to a\n            raster that will be used as the per-pixel flow distance\n            weight. If `None`, 1 is the default distance between neighboring\n            pixels. This raster must be the same dimensions as\n            `flow_dir_mfd_raster_path_band`.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8 = {"distance_to_channel_d8", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_12distance_to_channel_d8};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_flow_dir_d8_raster_path_band = 0;
  PyObject *__pyx_v_channel_raster_path_band = 0;
  PyObject *__pyx_v_target_distance_to_channel_raster_path = 0;
  PyObject *__pyx_v_weight_raster_path_band = 0;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("distance_to_channel_d8 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_d8_raster_path_band,&__pyx_n_s_channel_raster_path_band,&__pyx_n_s_target_distance_to_channel_raste,&__pyx_n_s_weight_raster_path_band,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pygeoprocessing/routing/routing.pyx":2183
 *         flow_dir_d8_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path,
 *         weight_raster_path_band=None,             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 *     """Calculate distance to channel with D8 flow.
 */
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k__25;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_d8_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_channel_raster_path_band)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("distance_to_channel_d8", 0, 3, 5, 1); __PYX_ERR(0, 2180, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_distance_to_channel_raste)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("distance_to_channel_d8", 0, 3, 5, 2); __PYX_ERR(0, 2180, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_weight_raster_path_band);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "distance_to_channel_d8") < 0)) __PYX_ERR(0, 2180, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_flow_dir_d8_raster_path_band = values[0];
    __pyx_v_channel_raster_path_band = values[1];
    __pyx_v_target_distance_to_channel_raster_path = values[2];
    __pyx_v_weight_raster_path_band = values[3];
    __pyx_v_gtiff_creation_options = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("distance_to_channel_d8", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2180, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.distance_to_channel_d8", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_12distance_to_channel_d8(__pyx_self, __pyx_v_flow_dir_d8_raster_path_band, __pyx_v_channel_raster_path_band, __pyx_v_target_distance_to_channel_raster_path, __pyx_v_weight_raster_path_band, __pyx_v_gtiff_creation_options);

  /* "pygeoprocessing/routing/routing.pyx":2180
 * 
 * 
 * def distance_to_channel_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_12distance_to_channel_d8(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_d8_raster_path_band, PyObject *__pyx_v_channel_raster_path_band, PyObject *__pyx_v_target_distance_to_channel_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options) {
  PyArrayObject *__pyx_v_channel_buffer_array = 0;
  int __pyx_v_win_ysize;
  int __pyx_v_win_xsize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_i_n;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_q;
  int __pyx_v_yi_q;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  std::stack<struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType>  __pyx_v_distance_to_channel_stack;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  double __pyx_v_weight_val;
  double __pyx_v_pixel_val;
  double __pyx_v_weight_nodata;
  time_t __pyx_v_last_log_time;
  PyObject *__pyx_v_path = NULL;
  long __pyx_v_distance_nodata;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_distance_to_channel_managed_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_weight_raster = 0;
  PyObject *__pyx_v_raw_weight_nodata = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_channel_managed_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_d8_managed_raster = NULL;
  PyObject *__pyx_v_channel_raster = NULL;
  PyObject *__pyx_v_channel_band = NULL;
  PyObject *__pyx_v_flow_dir_raster_info = NULL;
  PyObject *__pyx_v_offset_dict = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_modified_offset_dict = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_channel_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_channel_buffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  double __pyx_t_10;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  int __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  long __pyx_t_23;
  long __pyx_t_24;
  long __pyx_t_25;
  long __pyx_t_26;
  Py_ssize_t __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  int __pyx_t_29;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_PixelType __pyx_t_30;
  __Pyx_RefNannySetupContext("distance_to_channel_d8", 0);
  __pyx_pybuffer_channel_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_channel_buffer_array.refcount = 0;
  __pyx_pybuffernd_channel_buffer_array.data = NULL;
  __pyx_pybuffernd_channel_buffer_array.rcbuffer = &__pyx_pybuffer_channel_buffer_array;

  /* "pygeoprocessing/routing/routing.pyx":2234
 *     # for distance updates
 *     cdef double weight_val, pixel_val
 *     cdef double weight_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 * 
 *     # used for time-delayed logging
 */
  __pyx_v_weight_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;

  /* "pygeoprocessing/routing/routing.pyx":2238
 *     # used for time-delayed logging
 *     cdef time_t last_log_time
 *     last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     for path in (
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":2241
 * 
 *     for path in (
 *             flow_dir_d8_raster_path_band, channel_raster_path_band,             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2241, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_flow_dir_d8_raster_path_band);
  __Pyx_GIVEREF(__pyx_v_flow_dir_d8_raster_path_band);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flow_dir_d8_raster_path_band);
  __Pyx_INCREF(__pyx_v_channel_raster_path_band);
  __Pyx_GIVEREF(__pyx_v_channel_raster_path_band);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_channel_raster_path_band);
  __Pyx_INCREF(__pyx_v_weight_raster_path_band);
  __Pyx_GIVEREF(__pyx_v_weight_raster_path_band);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_weight_raster_path_band);

  /* "pygeoprocessing/routing/routing.pyx":2240
 *     last_log_time = ctime(NULL)
 * 
 *     for path in (             # <<<<<<<<<<<<<<
 *             flow_dir_d8_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 */
  __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_3 >= 3) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2240, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2240, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_path, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2243
 *             flow_dir_d8_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "%s is supposed to be a raster band tuple but it's not." % (
 */
    __pyx_t_5 = (__pyx_v_path != Py_None);
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {
    } else {
      __pyx_t_4 = __pyx_t_6;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2243, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2243, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_path};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2243, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_path};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2243, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2243, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
        __Pyx_INCREF(__pyx_v_path);
        __Pyx_GIVEREF(__pyx_v_path);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_path);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2243, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2243, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_5 = ((!__pyx_t_6) != 0);
    __pyx_t_4 = __pyx_t_5;
    __pyx_L6_bool_binop_done:;
    if (unlikely(__pyx_t_4)) {

      /* "pygeoprocessing/routing/routing.pyx":2245
 *         if path is not None and not _is_raster_path_band_formatted(path):
 *             raise ValueError(
 *                 "%s is supposed to be a raster band tuple but it's not." % (             # <<<<<<<<<<<<<<
 *                     path))
 * 
 */
      __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_is_supposed_to_be_a_raster_ba, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2245, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "pygeoprocessing/routing/routing.pyx":2244
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "%s is supposed to be a raster band tuple but it's not." % (
 *                     path))
 */
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2244, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 2244, __pyx_L1_error)

      /* "pygeoprocessing/routing/routing.pyx":2243
 *             flow_dir_d8_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "%s is supposed to be a raster band tuple but it's not." % (
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":2240
 *     last_log_time = ctime(NULL)
 * 
 *     for path in (             # <<<<<<<<<<<<<<
 *             flow_dir_d8_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2248
 *                     path))
 * 
 *     distance_nodata = -1             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_d8_raster_path_band[0],
 */
  __pyx_v_distance_nodata = -1L;

  /* "pygeoprocessing/routing/routing.pyx":2249
 * 
 *     distance_nodata = -1
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2249, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2249, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2250
 *     distance_nodata = -1
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_d8_raster_path_band[0],             # <<<<<<<<<<<<<<
 *         target_distance_to_channel_raster_path,
 *         gdal.GDT_Float64, [distance_nodata],
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2250, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "pygeoprocessing/routing/routing.pyx":2252
 *         flow_dir_d8_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 *         gdal.GDT_Float64, [distance_nodata],             # <<<<<<<<<<<<<<
 *         fill_value_list=[distance_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_distance_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2249
 * 
 *     distance_nodata = -1
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2249, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_target_distance_to_channel_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_distance_to_channel_raster_path);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_target_distance_to_channel_raster_path);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_8);
  __pyx_t_2 = 0;
  __pyx_t_9 = 0;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2253
 *         target_distance_to_channel_raster_path,
 *         gdal.GDT_Float64, [distance_nodata],
 *         fill_value_list=[distance_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     distance_to_channel_managed_raster = _ManagedRaster(
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_v_distance_nodata); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
  __pyx_t_9 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_fill_value_list, __pyx_t_2) < 0) __PYX_ERR(0, 2253, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2254
 *         gdal.GDT_Float64, [distance_nodata],
 *         fill_value_list=[distance_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     distance_to_channel_managed_raster = _ManagedRaster(
 *         target_distance_to_channel_raster_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 2253, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2249
 * 
 *     distance_nodata = -1
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2249, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2255
 *         fill_value_list=[distance_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     distance_to_channel_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         target_distance_to_channel_raster_path, 1, 1)
 * 
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2255, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_target_distance_to_channel_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_distance_to_channel_raster_path);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_target_distance_to_channel_raster_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_1);
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2255, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_distance_to_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2258
 *         target_distance_to_channel_raster_path, 1, 1)
 * 
 *     cdef _ManagedRaster weight_raster = None             # <<<<<<<<<<<<<<
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_weight_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)Py_None);

  /* "pygeoprocessing/routing/routing.pyx":2259
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2259, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "pygeoprocessing/routing/routing.pyx":2261
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 */
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2261, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2261, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "pygeoprocessing/routing/routing.pyx":2260
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 */
    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2260, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0);
    __pyx_t_8 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2260, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2262
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2262, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2262, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2263
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2263, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    if (!__pyx_t_7) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_1};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_1};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2262, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_s_nodata); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2263, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2264
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2264, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_PyInt_SubtractObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2264, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2263
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2263, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_raw_weight_nodata = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2265
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 * 
 */
    __pyx_t_4 = (__pyx_v_raw_weight_nodata != Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {

      /* "pygeoprocessing/routing/routing.pyx":2266
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata             # <<<<<<<<<<<<<<
 * 
 *     channel_managed_raster = _ManagedRaster(
 */
      __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_raw_weight_nodata); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2266, __pyx_L1_error)
      __pyx_v_weight_nodata = __pyx_t_10;

      /* "pygeoprocessing/routing/routing.pyx":2265
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 * 
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":2259
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2269
 * 
 *     channel_managed_raster = _ManagedRaster(
 *         channel_raster_path_band[0], channel_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 * 
 *     flow_dir_d8_managed_raster = _ManagedRaster(
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2269, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);

  /* "pygeoprocessing/routing/routing.pyx":2268
 *             weight_nodata = raw_weight_nodata
 * 
 *     channel_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], channel_raster_path_band[1], 0)
 * 
 */
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_0);
  __pyx_t_2 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_9);
  __pyx_t_9 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2272
 * 
 *     flow_dir_d8_managed_raster = _ManagedRaster(
 *         flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])
 */
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2272, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2272, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":2271
 *         channel_raster_path_band[0], channel_raster_path_band[1], 0)
 * 
 *     flow_dir_d8_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0)
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
  __pyx_t_9 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_flow_dir_d8_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2273
 *     flow_dir_d8_managed_raster = _ManagedRaster(
 *         flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0)
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])
 * 
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2273, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2273, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2273, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2273, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2273, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_9)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_2, __pyx_t_7};
    __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2273, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_2, __pyx_t_7};
    __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2273, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  } else
  #endif
  {
    __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2273, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_7);
    __pyx_t_2 = 0;
    __pyx_t_7 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2273, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_channel_raster = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2274
 *         flow_dir_d8_raster_path_band[0], flow_dir_d8_raster_path_band[1], 0)
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])             # <<<<<<<<<<<<<<
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2274, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_12 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2274, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  if (!__pyx_t_7) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2274, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_GOTREF(__pyx_t_8);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_9)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_12};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2274, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
      PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_12};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2274, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2274, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7); __pyx_t_7 = NULL;
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_12);
      __pyx_t_12 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2274, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_channel_band = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2276
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 */
  __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2277
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_d8_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 * 
 */
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_flow_dir_d8_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2277, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_12 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_12) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2276, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_GOTREF(__pyx_t_8);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_t_9};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2276, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_t_9};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2276, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2276, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_12); __pyx_t_12 = NULL;
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2276, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_flow_dir_raster_info = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2278
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_d8_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     # this outer loop searches for undefined channels
 */
  __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
    PyObject* sequence = __pyx_t_8;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 2278, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_7);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_9 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_13 = Py_TYPE(__pyx_t_9)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_2)) goto __pyx_L10_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_7 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L10_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_9), 2) < 0) __PYX_ERR(0, 2278, __pyx_L1_error)
    __pyx_t_13 = NULL;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L11_unpacking_done;
    __pyx_L10_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_13 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 2278, __pyx_L1_error)
    __pyx_L11_unpacking_done:;
  }
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2278, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2278, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_raster_x_size = __pyx_t_11;
  __pyx_v_raster_y_size = __pyx_t_14;

  /* "pygeoprocessing/routing/routing.pyx":2281
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2282
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(
 *         channel_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":2281
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2282
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(
 *         channel_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2282, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2282, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2281
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) {
    __pyx_t_8 = __pyx_t_9; __Pyx_INCREF(__pyx_t_8); __pyx_t_3 = 0;
    __pyx_t_15 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2281, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2281, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  for (;;) {
    if (likely(!__pyx_t_15)) {
      if (likely(PyList_CheckExact(__pyx_t_8))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_3); __Pyx_INCREF(__pyx_t_9); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2281, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2281, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_3); __Pyx_INCREF(__pyx_t_9); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2281, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2281, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      }
    } else {
      __pyx_t_9 = __pyx_t_15(__pyx_t_8);
      if (unlikely(!__pyx_t_9)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2281, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_9);
    }
    __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2284
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2284, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2284, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_win_xsize = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2285
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']             # <<<<<<<<<<<<<<
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2285, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2285, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_win_ysize = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2286
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']             # <<<<<<<<<<<<<<
 *         yoff = offset_dict['yoff']
 * 
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2286, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2286, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_xoff = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2287
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']             # <<<<<<<<<<<<<<
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2287, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2287, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_yoff = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2289
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
    if (__pyx_t_5) {

      /* "pygeoprocessing/routing/routing.pyx":2290
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
      __pyx_v_last_log_time = time(NULL);

      /* "pygeoprocessing/routing/routing.pyx":2291
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))
 */
      __pyx_t_9 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2291, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pygeoprocessing/routing/routing.pyx":2292
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);

      /* "pygeoprocessing/routing/routing.pyx":2293
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 */
      __pyx_t_12 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);

      /* "pygeoprocessing/routing/routing.pyx":2292
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2292, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = NULL;
      __pyx_t_14 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_14 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_s_1f_complete, __pyx_t_1};
        __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2292, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_s_1f_complete, __pyx_t_1};
        __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2292, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_12) {
          __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_12); __pyx_t_12 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_14, __pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_14, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pygeoprocessing/routing/routing.pyx":2289
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":2296
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2297
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.uint8)
 *         channel_buffer_array[:] = 0  # 0 means no channel
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2297, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2297, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2297, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2297, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2297, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2296
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2298
 *         channel_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)             # <<<<<<<<<<<<<<
 *         channel_buffer_array[:] = 0  # 0 means no channel
 * 
 */
    __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2298, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2298, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_uint8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2298, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_dtype, __pyx_t_12) < 0) __PYX_ERR(0, 2298, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2296
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2296, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2296, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_12);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer);
      __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_14 < 0)) {
        PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_channel_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
        }
        __pyx_t_17 = __pyx_t_18 = __pyx_t_19 = 0;
      }
      __pyx_pybuffernd_channel_buffer_array.diminfo[0].strides = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_channel_buffer_array.diminfo[0].shape = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_channel_buffer_array.diminfo[1].strides = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_channel_buffer_array.diminfo[1].shape = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 2296, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __Pyx_XDECREF_SET(__pyx_v_channel_buffer_array, ((PyArrayObject *)__pyx_t_12));
    __pyx_t_12 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2299
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 *         channel_buffer_array[:] = 0  # 0 means no channel             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_slice__26, __pyx_int_0) < 0)) __PYX_ERR(0, 2299, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":2303
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 */
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2303, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);

    /* "pygeoprocessing/routing/routing.pyx":2304
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)             # <<<<<<<<<<<<<<
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int8)
 */
    __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2304, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2304, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = NULL;
    __pyx_t_14 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
        __pyx_t_14 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_9)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_1, __pyx_t_7};
      __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_offset_dict, __pyx_t_1, __pyx_t_7};
      __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    {
      __pyx_t_20 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_v_offset_dict);
      PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_14, __pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_14, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_14, __pyx_t_7);
      __pyx_t_1 = 0;
      __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_20, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
      PyObject* sequence = __pyx_t_12;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2303, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_20 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_20);
      #else
      __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_20 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      #endif
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_7 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_13 = Py_TYPE(__pyx_t_7)->tp_iternext;
      index = 0; __pyx_t_9 = __pyx_t_13(__pyx_t_7); if (unlikely(!__pyx_t_9)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      index = 1; __pyx_t_20 = __pyx_t_13(__pyx_t_7); if (unlikely(!__pyx_t_20)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_20);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_7), 2) < 0) __PYX_ERR(0, 2303, __pyx_L1_error)
      __pyx_t_13 = NULL;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L16_unpacking_done;
      __pyx_L15_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_13 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2303, __pyx_L1_error)
      __pyx_L16_unpacking_done:;
    }

    /* "pygeoprocessing/routing/routing.pyx":2303
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 */
    if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
      PyObject* sequence = __pyx_t_9;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2303, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_21 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_21 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_21);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_7,&__pyx_t_1,&__pyx_t_2,&__pyx_t_21};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2303, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_7,&__pyx_t_1,&__pyx_t_2,&__pyx_t_21};
      __pyx_t_22 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_22);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_13 = Py_TYPE(__pyx_t_22)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_13(__pyx_t_22); if (unlikely(!item)) goto __pyx_L17_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_22), 4) < 0) __PYX_ERR(0, 2303, __pyx_L1_error)
      __pyx_t_13 = NULL;
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      goto __pyx_L18_unpacking_done;
      __pyx_L17_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      __pyx_t_13 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2303, __pyx_L1_error)
      __pyx_L18_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_21);
    __pyx_t_21 = 0;
    __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_20);
    __pyx_t_20 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2305
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 */
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);

    /* "pygeoprocessing/routing/routing.pyx":2306
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int8)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 2306, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_9 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2306, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
    } else {
      __pyx_t_9 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2305, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
    }

    /* "pygeoprocessing/routing/routing.pyx":2305
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 */
    __pyx_t_21 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_empty_tuple, __pyx_t_9); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2306
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int8)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_astype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2306, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_t_21 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2306, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_int8); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2306, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __pyx_t_21 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_21)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_21);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    if (!__pyx_t_21) {
      __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_20); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2306, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_GOTREF(__pyx_t_12);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_t_20};
        __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2306, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_t_20};
        __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2306, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2306, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_21); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_21); __pyx_t_21 = NULL;
        __Pyx_GIVEREF(__pyx_t_20);
        PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_20);
        __pyx_t_20 = 0;
        __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2306, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2305
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 */
    __pyx_t_9 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_2 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_20 = PyTuple_New(2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2305, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_2);
    __pyx_t_9 = 0;
    __pyx_t_2 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_t_20, __pyx_t_12) < 0)) __PYX_ERR(0, 2305, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2309
 * 
 *         # ensure these are set for the complier
 *         xi_n = -1             # <<<<<<<<<<<<<<
 *         yi_n = -1
 * 
 */
    __pyx_v_xi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":2310
 *         # ensure these are set for the complier
 *         xi_n = -1
 *         yi_n = -1             # <<<<<<<<<<<<<<
 * 
 *         # search block for to search for a channel seed
 */
    __pyx_v_yi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":2313
 * 
 *         # search block for to search for a channel seed
 *         for yi in range(1, win_ysize+1):             # <<<<<<<<<<<<<<
 *             for xi in range(1, win_xsize+1):
 *                 if channel_buffer_array[yi, xi] != 1:
 */
    __pyx_t_23 = (__pyx_v_win_ysize + 1);
    __pyx_t_24 = __pyx_t_23;
    for (__pyx_t_14 = 1; __pyx_t_14 < __pyx_t_24; __pyx_t_14+=1) {
      __pyx_v_yi = __pyx_t_14;

      /* "pygeoprocessing/routing/routing.pyx":2314
 *         # search block for to search for a channel seed
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):             # <<<<<<<<<<<<<<
 *                 if channel_buffer_array[yi, xi] != 1:
 *                     # no channel seed
 */
      __pyx_t_25 = (__pyx_v_win_xsize + 1);
      __pyx_t_26 = __pyx_t_25;
      for (__pyx_t_11 = 1; __pyx_t_11 < __pyx_t_26; __pyx_t_11+=1) {
        __pyx_v_xi = __pyx_t_11;

        /* "pygeoprocessing/routing/routing.pyx":2315
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 if channel_buffer_array[yi, xi] != 1:             # <<<<<<<<<<<<<<
 *                     # no channel seed
 *                     continue
 */
        __pyx_t_27 = __pyx_v_yi;
        __pyx_t_28 = __pyx_v_xi;
        __pyx_t_29 = -1;
        if (__pyx_t_27 < 0) {
          __pyx_t_27 += __pyx_pybuffernd_channel_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_27 < 0)) __pyx_t_29 = 0;
        } else if (unlikely(__pyx_t_27 >= __pyx_pybuffernd_channel_buffer_array.diminfo[0].shape)) __pyx_t_29 = 0;
        if (__pyx_t_28 < 0) {
          __pyx_t_28 += __pyx_pybuffernd_channel_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_28 < 0)) __pyx_t_29 = 1;
        } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_channel_buffer_array.diminfo[1].shape)) __pyx_t_29 = 1;
        if (unlikely(__pyx_t_29 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_29);
          __PYX_ERR(0, 2315, __pyx_L1_error)
        }
        __pyx_t_5 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_channel_buffer_array.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_channel_buffer_array.diminfo[1].strides)) != 1) != 0);
        if (__pyx_t_5) {

          /* "pygeoprocessing/routing/routing.pyx":2317
 *                 if channel_buffer_array[yi, xi] != 1:
 *                     # no channel seed
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 distance_to_channel_stack.push(
 */
          goto __pyx_L21_continue;

          /* "pygeoprocessing/routing/routing.pyx":2315
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 if channel_buffer_array[yi, xi] != 1:             # <<<<<<<<<<<<<<
 *                     # no channel seed
 *                     continue
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2320
 * 
 *                 distance_to_channel_stack.push(
 *                     PixelType(0.0, xi+xoff-1, yi+yoff-1, 0))             # <<<<<<<<<<<<<<
 * 
 *                 while not distance_to_channel_stack.empty():
 */
        __pyx_t_30.value = 0.0;
        __pyx_t_30.xi = ((__pyx_v_xi + __pyx_v_xoff) - 1);
        __pyx_t_30.yi = ((__pyx_v_yi + __pyx_v_yoff) - 1);
        __pyx_t_30.priority = 0;

        /* "pygeoprocessing/routing/routing.pyx":2319
 *                     continue
 * 
 *                 distance_to_channel_stack.push(             # <<<<<<<<<<<<<<
 *                     PixelType(0.0, xi+xoff-1, yi+yoff-1, 0))
 * 
 */
        __pyx_v_distance_to_channel_stack.push(__pyx_t_30);

        /* "pygeoprocessing/routing/routing.pyx":2322
 *                     PixelType(0.0, xi+xoff-1, yi+yoff-1, 0))
 * 
 *                 while not distance_to_channel_stack.empty():             # <<<<<<<<<<<<<<
 *                     xi_q = distance_to_channel_stack.top().xi
 *                     yi_q = distance_to_channel_stack.top().yi
 */
        while (1) {
          __pyx_t_5 = ((!(__pyx_v_distance_to_channel_stack.empty() != 0)) != 0);
          if (!__pyx_t_5) break;

          /* "pygeoprocessing/routing/routing.pyx":2323
 * 
 *                 while not distance_to_channel_stack.empty():
 *                     xi_q = distance_to_channel_stack.top().xi             # <<<<<<<<<<<<<<
 *                     yi_q = distance_to_channel_stack.top().yi
 *                     pixel_val = distance_to_channel_stack.top().value
 */
          __pyx_t_29 = __pyx_v_distance_to_channel_stack.top().xi;
          __pyx_v_xi_q = __pyx_t_29;

          /* "pygeoprocessing/routing/routing.pyx":2324
 *                 while not distance_to_channel_stack.empty():
 *                     xi_q = distance_to_channel_stack.top().xi
 *                     yi_q = distance_to_channel_stack.top().yi             # <<<<<<<<<<<<<<
 *                     pixel_val = distance_to_channel_stack.top().value
 *                     distance_to_channel_stack.pop()
 */
          __pyx_t_29 = __pyx_v_distance_to_channel_stack.top().yi;
          __pyx_v_yi_q = __pyx_t_29;

          /* "pygeoprocessing/routing/routing.pyx":2325
 *                     xi_q = distance_to_channel_stack.top().xi
 *                     yi_q = distance_to_channel_stack.top().yi
 *                     pixel_val = distance_to_channel_stack.top().value             # <<<<<<<<<<<<<<
 *                     distance_to_channel_stack.pop()
 * 
 */
          __pyx_t_10 = __pyx_v_distance_to_channel_stack.top().value;
          __pyx_v_pixel_val = __pyx_t_10;

          /* "pygeoprocessing/routing/routing.pyx":2326
 *                     yi_q = distance_to_channel_stack.top().yi
 *                     pixel_val = distance_to_channel_stack.top().value
 *                     distance_to_channel_stack.pop()             # <<<<<<<<<<<<<<
 * 
 *                     distance_to_channel_managed_raster.set(
 */
          __pyx_v_distance_to_channel_stack.pop();

          /* "pygeoprocessing/routing/routing.pyx":2328
 *                     distance_to_channel_stack.pop()
 * 
 *                     distance_to_channel_managed_raster.set(             # <<<<<<<<<<<<<<
 *                         xi_q, yi_q, pixel_val)
 * 
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_distance_to_channel_managed_raster, __pyx_v_xi_q, __pyx_v_yi_q, __pyx_v_pixel_val);

          /* "pygeoprocessing/routing/routing.pyx":2331
 *                         xi_q, yi_q, pixel_val)
 * 
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
          for (__pyx_t_29 = 0; __pyx_t_29 < 8; __pyx_t_29+=1) {
            __pyx_v_i_n = __pyx_t_29;

            /* "pygeoprocessing/routing/routing.pyx":2332
 * 
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 */
            __pyx_v_xi_n = (__pyx_v_xi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":2333
 *                     for i_n in range(8):
 *                         xi_n = xi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_yi_n = (__pyx_v_yi_q + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":2335
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            __pyx_t_4 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_4) {
            } else {
              __pyx_t_5 = __pyx_t_4;
              goto __pyx_L29_bool_binop_done;
            }
            __pyx_t_4 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_4) {
            } else {
              __pyx_t_5 = __pyx_t_4;
              goto __pyx_L29_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":2336
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_4 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_4) {
            } else {
              __pyx_t_5 = __pyx_t_4;
              goto __pyx_L29_bool_binop_done;
            }
            __pyx_t_4 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_5 = __pyx_t_4;
            __pyx_L29_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":2335
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            if (__pyx_t_5) {

              /* "pygeoprocessing/routing/routing.pyx":2337
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         if channel_managed_raster.get(xi_n, yi_n) == 1:
 */
              goto __pyx_L26_continue;

              /* "pygeoprocessing/routing/routing.pyx":2335
 *                         yi_n = yi_q+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2339
 *                             continue
 * 
 *                         if channel_managed_raster.get(xi_n, yi_n) == 1:             # <<<<<<<<<<<<<<
 *                             # it's a channel, it'll get picked up in the
 *                             # outer loop
 */
            __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_channel_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == 1.0) != 0);
            if (__pyx_t_5) {

              /* "pygeoprocessing/routing/routing.pyx":2342
 *                             # it's a channel, it'll get picked up in the
 *                             # outer loop
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         if (flow_dir_d8_managed_raster.get(xi_n, yi_n) ==
 */
              goto __pyx_L26_continue;

              /* "pygeoprocessing/routing/routing.pyx":2339
 *                             continue
 * 
 *                         if channel_managed_raster.get(xi_n, yi_n) == 1:             # <<<<<<<<<<<<<<
 *                             # it's a channel, it'll get picked up in the
 *                             # outer loop
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2344
 *                             continue
 * 
 *                         if (flow_dir_d8_managed_raster.get(xi_n, yi_n) ==             # <<<<<<<<<<<<<<
 *                                 D8_REVERSE_DIRECTION[i_n]):
 *                             # if a weight is passed we use it directly and do
 */
            __pyx_t_5 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_d8_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n) == (__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_i_n])) != 0);
            if (__pyx_t_5) {

              /* "pygeoprocessing/routing/routing.pyx":2351
 *                             # then "distance" is being calculated and we
 *                             # account for diagonal distance.
 *                             if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                                 weight_val = weight_raster.get(xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):
 */
              __pyx_t_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
              __pyx_t_4 = (__pyx_t_5 != 0);
              if (__pyx_t_4) {

                /* "pygeoprocessing/routing/routing.pyx":2352
 *                             # account for diagonal distance.
 *                             if weight_raster is not None:
 *                                 weight_val = weight_raster.get(xi_n, yi_n)             # <<<<<<<<<<<<<<
 *                                 if is_close(weight_val, weight_nodata):
 *                                     weight_val = 0.0
 */
                __pyx_v_weight_val = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_weight_raster, __pyx_v_xi_n, __pyx_v_yi_n);

                /* "pygeoprocessing/routing/routing.pyx":2353
 *                             if weight_raster is not None:
 *                                 weight_val = weight_raster.get(xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                     weight_val = 0.0
 *                             else:
 */
                __pyx_t_4 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_weight_val, __pyx_v_weight_nodata) != 0);
                if (__pyx_t_4) {

                  /* "pygeoprocessing/routing/routing.pyx":2354
 *                                 weight_val = weight_raster.get(xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):
 *                                     weight_val = 0.0             # <<<<<<<<<<<<<<
 *                             else:
 *                                 weight_val = (SQRT2 if i_n % 2 else 1)
 */
                  __pyx_v_weight_val = 0.0;

                  /* "pygeoprocessing/routing/routing.pyx":2353
 *                             if weight_raster is not None:
 *                                 weight_val = weight_raster.get(xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                     weight_val = 0.0
 *                             else:
 */
                }

                /* "pygeoprocessing/routing/routing.pyx":2351
 *                             # then "distance" is being calculated and we
 *                             # account for diagonal distance.
 *                             if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                                 weight_val = weight_raster.get(xi_n, yi_n)
 *                                 if is_close(weight_val, weight_nodata):
 */
                goto __pyx_L35;
              }

              /* "pygeoprocessing/routing/routing.pyx":2356
 *                                     weight_val = 0.0
 *                             else:
 *                                 weight_val = (SQRT2 if i_n % 2 else 1)             # <<<<<<<<<<<<<<
 * 
 *                             distance_to_channel_stack.push(
 */
              /*else*/ {
                if ((__Pyx_mod_long(__pyx_v_i_n, 2) != 0)) {
                  __pyx_t_10 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2;
                } else {
                  __pyx_t_10 = 1.0;
                }
                __pyx_v_weight_val = __pyx_t_10;
              }
              __pyx_L35:;

              /* "pygeoprocessing/routing/routing.pyx":2360
 *                             distance_to_channel_stack.push(
 *                                 PixelType(
 *                                     weight_val + pixel_val, xi_n, yi_n, 0))             # <<<<<<<<<<<<<<
 * 
 *     distance_to_channel_managed_raster.close()
 */
              __pyx_t_30.value = (__pyx_v_weight_val + __pyx_v_pixel_val);
              __pyx_t_30.xi = __pyx_v_xi_n;
              __pyx_t_30.yi = __pyx_v_yi_n;
              __pyx_t_30.priority = 0;

              /* "pygeoprocessing/routing/routing.pyx":2358
 *                                 weight_val = (SQRT2 if i_n % 2 else 1)
 * 
 *                             distance_to_channel_stack.push(             # <<<<<<<<<<<<<<
 *                                 PixelType(
 *                                     weight_val + pixel_val, xi_n, yi_n, 0))
 */
              __pyx_v_distance_to_channel_stack.push(__pyx_t_30);

              /* "pygeoprocessing/routing/routing.pyx":2344
 *                             continue
 * 
 *                         if (flow_dir_d8_managed_raster.get(xi_n, yi_n) ==             # <<<<<<<<<<<<<<
 *                                 D8_REVERSE_DIRECTION[i_n]):
 *                             # if a weight is passed we use it directly and do
 */
            }
            __pyx_L26_continue:;
          }
        }
        __pyx_L21_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":2281
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2362
 *                                     weight_val + pixel_val, xi_n, yi_n, 0))
 * 
 *     distance_to_channel_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flow_dir_d8_managed_raster.close()
 *     channel_managed_raster.close()
 */
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distance_to_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2362, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_20 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
    __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_12);
    if (likely(__pyx_t_20)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_12, function);
    }
  }
  if (__pyx_t_20) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_20); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2362, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2362, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2363
 * 
 *     distance_to_channel_managed_raster.close()
 *     flow_dir_d8_managed_raster.close()             # <<<<<<<<<<<<<<
 *     channel_managed_raster.close()
 *     if weight_raster is not None:
 */
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_d8_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_20 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
    __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_12);
    if (likely(__pyx_t_20)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_12, function);
    }
  }
  if (__pyx_t_20) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_20); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2363, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2363, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2364
 *     distance_to_channel_managed_raster.close()
 *     flow_dir_d8_managed_raster.close()
 *     channel_managed_raster.close()             # <<<<<<<<<<<<<<
 *     if weight_raster is not None:
 *         weight_raster.close()
 */
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_20 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
    __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_12);
    if (likely(__pyx_t_20)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_20);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_12, function);
    }
  }
  if (__pyx_t_20) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_20); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2364, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2364, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2365
 *     flow_dir_d8_managed_raster.close()
 *     channel_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 * 
 */
  __pyx_t_4 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "pygeoprocessing/routing/routing.pyx":2366
 *     channel_managed_raster.close()
 *     if weight_raster is not None:
 *         weight_raster.close()             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2366, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_20 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_12);
      if (likely(__pyx_t_20)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
        __Pyx_INCREF(__pyx_t_20);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_12, function);
      }
    }
    if (__pyx_t_20) {
      __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_20); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2366, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    } else {
      __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2366, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2365
 *     flow_dir_d8_managed_raster.close()
 *     channel_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 * 
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2180
 * 
 * 
 * def distance_to_channel_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.distance_to_channel_d8", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_channel_buffer_array);
  __Pyx_XDECREF(__pyx_v_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_distance_to_channel_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_weight_raster);
  __Pyx_XDECREF(__pyx_v_raw_weight_nodata);
  __Pyx_XDECREF((PyObject *)__pyx_v_channel_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_d8_managed_raster);
  __Pyx_XDECREF(__pyx_v_channel_raster);
  __Pyx_XDECREF(__pyx_v_channel_band);
  __Pyx_XDECREF(__pyx_v_flow_dir_raster_info);
  __Pyx_XDECREF(__pyx_v_offset_dict);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_modified_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":2369
 * 
 * 
 * def distance_to_channel_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path, weight_raster_path_band=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_14distance_to_channel_mfd[] = "Calculate distance to channel with multiple flow direction.\n\n    Parameters:\n        flow_dir_mfd_raster_path_band (tuple): a path/band index tuple\n            indicating the raster that defines the mfd flow accumulation\n            raster for this call. This raster should be generated by a call\n            to `pygeoprocessing.routing.flow_dir_mfd.\n\n        channel_raster_path_band (tuple): a path/band tuple of the same\n            dimensions and projection as `flow_dir_mfd_raster_path_band[0]`\n            that indicates where the channels in the problem space lie. A\n            channel is indicated if the value of the pixel is 1. Other values\n            are ignored.\n        target_distance_to_channel_raster_path (string): path to a raster\n            created by this call that has per-pixel distances from a given\n            pixel to the nearest downhill channel.\n        weight_raster_path_band (tuple): optional path and band number to a\n            raster that will be used as the per-pixel flow distance\n            weight. If `None`, 1 is the default distance between neighboring\n            pixels. This raster must be the same dimensions as\n            `flow_dir_mfd_raster_path_band`.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd = {"distance_to_channel_mfd", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_14distance_to_channel_mfd};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_flow_dir_mfd_raster_path_band = 0;
  PyObject *__pyx_v_channel_raster_path_band = 0;
  PyObject *__pyx_v_target_distance_to_channel_raster_path = 0;
  PyObject *__pyx_v_weight_raster_path_band = 0;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("distance_to_channel_mfd (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_dir_mfd_raster_path_band,&__pyx_n_s_channel_raster_path_band,&__pyx_n_s_target_distance_to_channel_raste,&__pyx_n_s_weight_raster_path_band,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pygeoprocessing/routing/routing.pyx":2371
 * def distance_to_channel_mfd(
 *         flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path, weight_raster_path_band=None,             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 *     """Calculate distance to channel with multiple flow direction.
 */
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k__27;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_mfd_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_channel_raster_path_band)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("distance_to_channel_mfd", 0, 3, 5, 1); __PYX_ERR(0, 2369, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_distance_to_channel_raste)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("distance_to_channel_mfd", 0, 3, 5, 2); __PYX_ERR(0, 2369, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_weight_raster_path_band);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "distance_to_channel_mfd") < 0)) __PYX_ERR(0, 2369, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_flow_dir_mfd_raster_path_band = values[0];
    __pyx_v_channel_raster_path_band = values[1];
    __pyx_v_target_distance_to_channel_raster_path = values[2];
    __pyx_v_weight_raster_path_band = values[3];
    __pyx_v_gtiff_creation_options = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("distance_to_channel_mfd", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2369, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.distance_to_channel_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_14distance_to_channel_mfd(__pyx_self, __pyx_v_flow_dir_mfd_raster_path_band, __pyx_v_channel_raster_path_band, __pyx_v_target_distance_to_channel_raster_path, __pyx_v_weight_raster_path_band, __pyx_v_gtiff_creation_options);

  /* "pygeoprocessing/routing/routing.pyx":2369
 * 
 * 
 * def distance_to_channel_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path, weight_raster_path_band=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_14distance_to_channel_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_dir_mfd_raster_path_band, PyObject *__pyx_v_channel_raster_path_band, PyObject *__pyx_v_target_distance_to_channel_raster_path, PyObject *__pyx_v_weight_raster_path_band, PyObject *__pyx_v_gtiff_creation_options) {
  PyArrayObject *__pyx_v_channel_buffer_array = 0;
  PyArrayObject *__pyx_v_flow_dir_buffer_array = 0;
  int __pyx_v_win_ysize;
  int __pyx_v_win_xsize;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_i_n;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  int __pyx_v_flow_dir_weight;
  int __pyx_v_sum_of_flow_weights;
  int __pyx_v_compressed_flow_dir;
  int __pyx_v_is_a_channel;
  std::stack<struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType>  __pyx_v_distance_to_channel_stack;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  double __pyx_v_weight_val;
  double __pyx_v_weight_nodata;
  time_t __pyx_v_last_log_time;
  PyObject *__pyx_v_path = NULL;
  double __pyx_v_distance_nodata;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_distance_to_channel_managed_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_channel_managed_raster = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_mfd_managed_raster = NULL;
  PyObject *__pyx_v_channel_raster = NULL;
  PyObject *__pyx_v_channel_band = NULL;
  PyObject *__pyx_v_flow_dir_mfd_raster = NULL;
  PyObject *__pyx_v_flow_dir_mfd_band = NULL;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_weight_raster = 0;
  PyObject *__pyx_v_raw_weight_nodata = NULL;
  PyObject *__pyx_v_flow_dir_raster_info = NULL;
  PyObject *__pyx_v_offset_dict = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_xa = NULL;
  PyObject *__pyx_v_xb = NULL;
  PyObject *__pyx_v_ya = NULL;
  PyObject *__pyx_v_yb = NULL;
  PyObject *__pyx_v_modified_offset_dict = NULL;
  long __pyx_v_xi_root;
  long __pyx_v_yi_root;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_v_pixel;
  long __pyx_v_preempted;
  double __pyx_v_n_distance;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_channel_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_channel_buffer_array;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_flow_dir_buffer_array;
  __Pyx_Buffer __pyx_pybuffer_flow_dir_buffer_array;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  double __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  int __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyArrayObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyArrayObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  PyObject *__pyx_t_23 = NULL;
  long __pyx_t_24;
  long __pyx_t_25;
  long __pyx_t_26;
  long __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  int __pyx_t_30;
  Py_ssize_t __pyx_t_31;
  Py_ssize_t __pyx_t_32;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_FlowPixelType __pyx_t_33;
  __Pyx_RefNannySetupContext("distance_to_channel_mfd", 0);
  __pyx_pybuffer_channel_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_channel_buffer_array.refcount = 0;
  __pyx_pybuffernd_channel_buffer_array.data = NULL;
  __pyx_pybuffernd_channel_buffer_array.rcbuffer = &__pyx_pybuffer_channel_buffer_array;
  __pyx_pybuffer_flow_dir_buffer_array.pybuffer.buf = NULL;
  __pyx_pybuffer_flow_dir_buffer_array.refcount = 0;
  __pyx_pybuffernd_flow_dir_buffer_array.data = NULL;
  __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer = &__pyx_pybuffer_flow_dir_buffer_array;

  /* "pygeoprocessing/routing/routing.pyx":2425
 *     # come from a predefined flow accumulation weight raster
 *     cdef double weight_val
 *     cdef double weight_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 * 
 *     # used for time-delayed logging
 */
  __pyx_v_weight_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;

  /* "pygeoprocessing/routing/routing.pyx":2429
 *     # used for time-delayed logging
 *     cdef time_t last_log_time
 *     last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     for path in (
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":2432
 * 
 *     for path in (
 *             flow_dir_mfd_raster_path_band, channel_raster_path_band,             # <<<<<<<<<<<<<<
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2432, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_flow_dir_mfd_raster_path_band);
  __Pyx_GIVEREF(__pyx_v_flow_dir_mfd_raster_path_band);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_flow_dir_mfd_raster_path_band);
  __Pyx_INCREF(__pyx_v_channel_raster_path_band);
  __Pyx_GIVEREF(__pyx_v_channel_raster_path_band);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_channel_raster_path_band);
  __Pyx_INCREF(__pyx_v_weight_raster_path_band);
  __Pyx_GIVEREF(__pyx_v_weight_raster_path_band);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_weight_raster_path_band);

  /* "pygeoprocessing/routing/routing.pyx":2431
 *     last_log_time = ctime(NULL)
 * 
 *     for path in (             # <<<<<<<<<<<<<<
 *             flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 */
  __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_3 >= 3) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2431, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_path, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2434
 *             flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "%s is supposed to be a raster band tuple but it's not." % (
 */
    __pyx_t_5 = (__pyx_v_path != Py_None);
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {
    } else {
      __pyx_t_4 = __pyx_t_6;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_is_raster_path_band_formatted); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2434, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2434, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_path};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2434, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_path};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2434, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2434, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
        __Pyx_INCREF(__pyx_v_path);
        __Pyx_GIVEREF(__pyx_v_path);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_path);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2434, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2434, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_5 = ((!__pyx_t_6) != 0);
    __pyx_t_4 = __pyx_t_5;
    __pyx_L6_bool_binop_done:;
    if (unlikely(__pyx_t_4)) {

      /* "pygeoprocessing/routing/routing.pyx":2436
 *         if path is not None and not _is_raster_path_band_formatted(path):
 *             raise ValueError(
 *                 "%s is supposed to be a raster band tuple but it's not." % (             # <<<<<<<<<<<<<<
 *                     path))
 * 
 */
      __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_is_supposed_to_be_a_raster_ba, __pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2436, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "pygeoprocessing/routing/routing.pyx":2435
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "%s is supposed to be a raster band tuple but it's not." % (
 *                     path))
 */
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 2435, __pyx_L1_error)

      /* "pygeoprocessing/routing/routing.pyx":2434
 *             flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 *         if path is not None and not _is_raster_path_band_formatted(path):             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "%s is supposed to be a raster band tuple but it's not." % (
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":2431
 *     last_log_time = ctime(NULL)
 * 
 *     for path in (             # <<<<<<<<<<<<<<
 *             flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *             weight_raster_path_band):
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2439
 *                     path))
 * 
 *     distance_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_mfd_raster_path_band[0],
 */
  __pyx_v_distance_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;

  /* "pygeoprocessing/routing/routing.pyx":2440
 * 
 *     distance_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2440, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2440, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2441
 *     distance_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(
 *         flow_dir_mfd_raster_path_band[0],             # <<<<<<<<<<<<<<
 *         target_distance_to_channel_raster_path,
 *         gdal.GDT_Float64, [distance_nodata],
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2441, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "pygeoprocessing/routing/routing.pyx":2443
 *         flow_dir_mfd_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 *         gdal.GDT_Float64, [distance_nodata],             # <<<<<<<<<<<<<<
 *         fill_value_list=[distance_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GDT_Float64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_distance_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2443, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2440
 * 
 *     distance_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2440, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_target_distance_to_channel_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_distance_to_channel_raster_path);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_target_distance_to_channel_raster_path);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_8);
  __pyx_t_2 = 0;
  __pyx_t_9 = 0;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2444
 *         target_distance_to_channel_raster_path,
 *         gdal.GDT_Float64, [distance_nodata],
 *         fill_value_list=[distance_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 *     distance_to_channel_managed_raster = _ManagedRaster(
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyFloat_FromDouble(__pyx_v_distance_nodata); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_9);
  __pyx_t_9 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_fill_value_list, __pyx_t_2) < 0) __PYX_ERR(0, 2444, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2445
 *         gdal.GDT_Float64, [distance_nodata],
 *         fill_value_list=[distance_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 *     distance_to_channel_managed_raster = _ManagedRaster(
 *         target_distance_to_channel_raster_path, 1, 1)
 */
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 2444, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2440
 * 
 *     distance_nodata = IMPROBABLE_FLOAT_NODATA
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0],
 *         target_distance_to_channel_raster_path,
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2440, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2446
 *         fill_value_list=[distance_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 *     distance_to_channel_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         target_distance_to_channel_raster_path, 1, 1)
 * 
 */
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2446, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_target_distance_to_channel_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_distance_to_channel_raster_path);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_target_distance_to_channel_raster_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_1);
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2446, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_distance_to_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2450
 * 
 *     channel_managed_raster = _ManagedRaster(
 *         channel_raster_path_band[0], channel_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 * 
 *     flow_dir_mfd_managed_raster = _ManagedRaster(
 */
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "pygeoprocessing/routing/routing.pyx":2449
 *         target_distance_to_channel_raster_path, 1, 1)
 * 
 *     channel_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], channel_raster_path_band[1], 0)
 * 
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0);
  __pyx_t_8 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_channel_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2453
 * 
 *     flow_dir_mfd_managed_raster = _ManagedRaster(
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pygeoprocessing/routing/routing.pyx":2452
 *         channel_raster_path_band[0], channel_raster_path_band[1], 0)
 * 
 *     flow_dir_mfd_managed_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)
 */
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_int_0);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_flow_dir_mfd_managed_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2454
 *     flow_dir_mfd_managed_raster = _ManagedRaster(
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])
 * 
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  __pyx_t_10 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_10 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_t_9};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2454, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_t_9};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2454, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  {
    __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2454, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if (__pyx_t_7) {
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_7); __pyx_t_7 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_9);
    __pyx_t_8 = 0;
    __pyx_t_9 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2454, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_channel_raster = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2455
 *         flow_dir_mfd_raster_path_band[0], flow_dir_mfd_raster_path_band[1], 0)
 *     channel_raster = gdal.OpenEx(channel_raster_path_band[0], gdal.OF_RASTER)
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])             # <<<<<<<<<<<<<<
 * 
 *     flow_dir_mfd_raster = gdal.OpenEx(
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2455, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2455, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_9 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_9) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2455, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_11};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2455, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_11};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2455, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2455, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); __pyx_t_9 = NULL;
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2455, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_channel_band = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2457
 *     channel_band = channel_raster.GetRasterBand(channel_raster_path_band[1])
 * 
 *     flow_dir_mfd_raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_mfd_band = flow_dir_mfd_raster.GetRasterBand(
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2458
 * 
 *     flow_dir_mfd_raster = gdal.OpenEx(
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)             # <<<<<<<<<<<<<<
 *     flow_dir_mfd_band = flow_dir_mfd_raster.GetRasterBand(
 *         flow_dir_mfd_raster_path_band[1])
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = NULL;
  __pyx_t_10 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
      __pyx_t_10 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_2, __pyx_t_9};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_2, __pyx_t_9};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_11) {
      __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_11); __pyx_t_11 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_10, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_10, __pyx_t_9);
    __pyx_t_2 = 0;
    __pyx_t_9 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2457, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_flow_dir_mfd_raster = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2459
 *     flow_dir_mfd_raster = gdal.OpenEx(
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_mfd_band = flow_dir_mfd_raster.GetRasterBand(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[1])
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_mfd_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":2460
 *         flow_dir_mfd_raster_path_band[0], gdal.OF_RASTER)
 *     flow_dir_mfd_band = flow_dir_mfd_raster.GetRasterBand(
 *         flow_dir_mfd_raster_path_band[1])             # <<<<<<<<<<<<<<
 * 
 *     cdef _ManagedRaster weight_raster = None
 */
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2460, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (!__pyx_t_9) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2459, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2459, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2459, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2459, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_9); __pyx_t_9 = NULL;
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2459, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_flow_dir_mfd_band = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2462
 *         flow_dir_mfd_raster_path_band[1])
 * 
 *     cdef _ManagedRaster weight_raster = None             # <<<<<<<<<<<<<<
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_weight_raster = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)Py_None);

  /* "pygeoprocessing/routing/routing.pyx":2463
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_weight_raster_path_band); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2463, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "pygeoprocessing/routing/routing.pyx":2465
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "pygeoprocessing/routing/routing.pyx":2464
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:
 *         weight_raster = _ManagedRaster(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 */
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2464, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
    __pyx_t_1 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2464, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_weight_raster, ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_8));
    __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2466
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2466, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2466, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2467
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2467, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_7) {
      __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2466, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_8);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_2};
        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2466, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_2};
        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2466, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2466, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2466, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_8, __pyx_n_s_nodata); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2467, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2468
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata
 */
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_weight_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2468, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyInt_SubtractObjC(__pyx_t_8, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2468, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2467
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 *         raw_weight_nodata = pygeoprocessing.get_raster_info(
 *             weight_raster_path_band[0])['nodata'][             # <<<<<<<<<<<<<<
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 */
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2467, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_raw_weight_nodata = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2469
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 *         else:
 */
    __pyx_t_4 = (__pyx_v_raw_weight_nodata != Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {

      /* "pygeoprocessing/routing/routing.pyx":2470
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:
 *             weight_nodata = raw_weight_nodata             # <<<<<<<<<<<<<<
 *         else:
 *             weight_nodata = IMPROBABLE_FLOAT_NODATA
 */
      __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_raw_weight_nodata); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2470, __pyx_L1_error)
      __pyx_v_weight_nodata = __pyx_t_12;

      /* "pygeoprocessing/routing/routing.pyx":2469
 *             weight_raster_path_band[0])['nodata'][
 *                 weight_raster_path_band[1]-1]
 *         if raw_weight_nodata is not None:             # <<<<<<<<<<<<<<
 *             weight_nodata = raw_weight_nodata
 *         else:
 */
      goto __pyx_L9;
    }

    /* "pygeoprocessing/routing/routing.pyx":2472
 *             weight_nodata = raw_weight_nodata
 *         else:
 *             weight_nodata = IMPROBABLE_FLOAT_NODATA             # <<<<<<<<<<<<<<
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 */
    /*else*/ {
      __pyx_v_weight_nodata = __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA;
    }
    __pyx_L9:;

    /* "pygeoprocessing/routing/routing.pyx":2463
 * 
 *     cdef _ManagedRaster weight_raster = None
 *     if weight_raster_path_band:             # <<<<<<<<<<<<<<
 *         weight_raster = _ManagedRaster(
 *             weight_raster_path_band[0], weight_raster_path_band[1], 0)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2474
 *             weight_nodata = IMPROBABLE_FLOAT_NODATA
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 */
  __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2474, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2474, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2475
 * 
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_mfd_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']
 * 
 */
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2475, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2474, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_GOTREF(__pyx_t_8);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_9};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2474, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_9};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2474, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2474, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2474, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_flow_dir_raster_info = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2476
 *     flow_dir_raster_info = pygeoprocessing.get_raster_info(
 *         flow_dir_mfd_raster_path_band[0])
 *     raster_x_size, raster_y_size = flow_dir_raster_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     # this outer loop searches for undefined channels
 */
  __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_dir_raster_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
    PyObject* sequence = __pyx_t_8;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 2476, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_7);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_9 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2476, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_13 = Py_TYPE(__pyx_t_9)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_1)) goto __pyx_L10_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_7 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L10_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_9), 2) < 0) __PYX_ERR(0, 2476, __pyx_L1_error)
    __pyx_t_13 = NULL;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L11_unpacking_done;
    __pyx_L10_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_13 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 2476, __pyx_L1_error)
    __pyx_L11_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2476, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_raster_x_size = __pyx_t_10;
  __pyx_v_raster_y_size = __pyx_t_14;

  /* "pygeoprocessing/routing/routing.pyx":2479
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2479, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2479, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2480
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(
 *         channel_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_channel_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pygeoprocessing/routing/routing.pyx":2479
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2479, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2480
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(
 *         channel_raster_path_band[0], offset_only=True,             # <<<<<<<<<<<<<<
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2480, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_largest_block, __pyx_int_0) < 0) __PYX_ERR(0, 2480, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2479
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2479, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) {
    __pyx_t_8 = __pyx_t_9; __Pyx_INCREF(__pyx_t_8); __pyx_t_3 = 0;
    __pyx_t_15 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2479, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2479, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  for (;;) {
    if (likely(!__pyx_t_15)) {
      if (likely(PyList_CheckExact(__pyx_t_8))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_3); __Pyx_INCREF(__pyx_t_9); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2479, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2479, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_3); __Pyx_INCREF(__pyx_t_9); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2479, __pyx_L1_error)
        #else
        __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2479, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        #endif
      }
    } else {
      __pyx_t_9 = __pyx_t_15(__pyx_t_8);
      if (unlikely(!__pyx_t_9)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2479, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_9);
    }
    __Pyx_XDECREF_SET(__pyx_v_offset_dict, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2482
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2482, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2482, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_win_xsize = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2483
 *             largest_block=0):
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']             # <<<<<<<<<<<<<<
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_win_ysize = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2484
 *         win_xsize = offset_dict['win_xsize']
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']             # <<<<<<<<<<<<<<
 *         yoff = offset_dict['yoff']
 * 
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_xoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2484, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2484, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_xoff = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2485
 *         win_ysize = offset_dict['win_ysize']
 *         xoff = offset_dict['xoff']
 *         yoff = offset_dict['yoff']             # <<<<<<<<<<<<<<
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_yoff); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2485, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2485, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_yoff = __pyx_t_14;

    /* "pygeoprocessing/routing/routing.pyx":2487
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    __pyx_t_5 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
    if (__pyx_t_5) {

      /* "pygeoprocessing/routing/routing.pyx":2488
 * 
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
      __pyx_v_last_log_time = time(NULL);

      /* "pygeoprocessing/routing/routing.pyx":2489
 *         if ctime(NULL) - last_log_time > 5.0:
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))
 */
      __pyx_t_9 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2489, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pygeoprocessing/routing/routing.pyx":2490
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2490, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2490, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2490, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "pygeoprocessing/routing/routing.pyx":2491
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                 raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 */
      __pyx_t_2 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2490, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);

      /* "pygeoprocessing/routing/routing.pyx":2490
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 *             LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                 raster_x_size * raster_y_size))
 * 
 */
      __pyx_t_11 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2490, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      __pyx_t_14 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_14 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_s_1f_complete, __pyx_t_11};
        __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2490, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_s_1f_complete, __pyx_t_11};
        __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2490, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else
      #endif
      {
        __pyx_t_1 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2490, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__pyx_t_2) {
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
        PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_14, __pyx_kp_s_1f_complete);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_14, __pyx_t_11);
        __pyx_t_11 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2490, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pygeoprocessing/routing/routing.pyx":2487
 *         yoff = offset_dict['yoff']
 * 
 *         if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *             last_log_time = ctime(NULL)
 *             current_pixel = xoff + yoff * raster_x_size
 */
    }

    /* "pygeoprocessing/routing/routing.pyx":2494
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_empty); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2495
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array = numpy.empty(
 */
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2495, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_11);
    __pyx_t_1 = 0;
    __pyx_t_11 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2494
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2496
 *         channel_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)             # <<<<<<<<<<<<<<
 *         flow_dir_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 */
    __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_uint8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 2496, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2494
 * 
 *         # make a buffer big enough to capture block and boundaries around it
 *         channel_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2494, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2494, __pyx_L1_error)
    __pyx_t_16 = ((PyArrayObject *)__pyx_t_2);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer);
      __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_14 < 0)) {
        PyErr_Fetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_channel_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_19);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
        }
        __pyx_t_17 = __pyx_t_18 = __pyx_t_19 = 0;
      }
      __pyx_pybuffernd_channel_buffer_array.diminfo[0].strides = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_channel_buffer_array.diminfo[0].shape = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_channel_buffer_array.diminfo[1].strides = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_channel_buffer_array.diminfo[1].shape = __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 2494, __pyx_L1_error)
    }
    __pyx_t_16 = 0;
    __Pyx_XDECREF_SET(__pyx_v_channel_buffer_array, ((PyArrayObject *)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2497
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2498
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),             # <<<<<<<<<<<<<<
 *             dtype=numpy.int32)
 *         channel_buffer_array[:] = 0  # 0 means no channel
 */
    __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2498, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2498, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_offset_dict, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2498, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2498, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2498, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7);
    __pyx_t_11 = 0;
    __pyx_t_7 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2497
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 */
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2499
 *         flow_dir_buffer_array = numpy.empty(
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)             # <<<<<<<<<<<<<<
 *         channel_buffer_array[:] = 0  # 0 means no channel
 *         flow_dir_buffer_array[:] = 0  # 0 means no flow
 */
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_1) < 0) __PYX_ERR(0, 2499, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2497
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array = numpy.empty(             # <<<<<<<<<<<<<<
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 2497, __pyx_L1_error)
    __pyx_t_20 = ((PyArrayObject *)__pyx_t_1);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer);
      __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_t_20, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_14 < 0)) {
        PyErr_Fetch(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_flow_dir_buffer_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_19); Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_17);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_19, __pyx_t_18, __pyx_t_17);
        }
        __pyx_t_19 = __pyx_t_18 = __pyx_t_17 = 0;
      }
      __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape = __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 2497, __pyx_L1_error)
    }
    __pyx_t_20 = 0;
    __Pyx_XDECREF_SET(__pyx_v_flow_dir_buffer_array, ((PyArrayObject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2500
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 *         channel_buffer_array[:] = 0  # 0 means no channel             # <<<<<<<<<<<<<<
 *         flow_dir_buffer_array[:] = 0  # 0 means no flow
 * 
 */
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_slice__28, __pyx_int_0) < 0)) __PYX_ERR(0, 2500, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":2501
 *             dtype=numpy.int32)
 *         channel_buffer_array[:] = 0  # 0 means no channel
 *         flow_dir_buffer_array[:] = 0  # 0 means no flow             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_slice__29, __pyx_int_0) < 0)) __PYX_ERR(0, 2501, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":2505
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_generate_read_bounds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2505, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "pygeoprocessing/routing/routing.pyx":2506
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)             # <<<<<<<<<<<<<<
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int8)
 */
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_raster_x_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2506, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_raster_y_size); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2506, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = NULL;
    __pyx_t_14 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_14 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[4] = {__pyx_t_11, __pyx_v_offset_dict, __pyx_t_7, __pyx_t_9};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[4] = {__pyx_t_11, __pyx_v_offset_dict, __pyx_t_7, __pyx_t_9};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    {
      __pyx_t_21 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_21);
      if (__pyx_t_11) {
        __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_11); __pyx_t_11 = NULL;
      }
      __Pyx_INCREF(__pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_v_offset_dict);
      PyTuple_SET_ITEM(__pyx_t_21, 0+__pyx_t_14, __pyx_v_offset_dict);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_21, 1+__pyx_t_14, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_21, 2+__pyx_t_14, __pyx_t_9);
      __pyx_t_7 = 0;
      __pyx_t_9 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
      PyObject* sequence = __pyx_t_1;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2505, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_21 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_21 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_21);
      #else
      __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_21 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_21);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_13 = Py_TYPE(__pyx_t_9)->tp_iternext;
      index = 0; __pyx_t_2 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 1; __pyx_t_21 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_21)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_21);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_9), 2) < 0) __PYX_ERR(0, 2505, __pyx_L1_error)
      __pyx_t_13 = NULL;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L16_unpacking_done;
      __pyx_L15_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_13 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2505, __pyx_L1_error)
      __pyx_L16_unpacking_done:;
    }

    /* "pygeoprocessing/routing/routing.pyx":2505
 *         # check if we can widen the border to include real data from the
 *         # raster
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(             # <<<<<<<<<<<<<<
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 */
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2505, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_22 = PyTuple_GET_ITEM(sequence, 3); 
      } else {
        __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_11 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_22 = PyList_GET_ITEM(sequence, 3); 
      }
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_22);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_9,&__pyx_t_7,&__pyx_t_11,&__pyx_t_22};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 2505, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[4] = {&__pyx_t_9,&__pyx_t_7,&__pyx_t_11,&__pyx_t_22};
      __pyx_t_23 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 2505, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_23);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_13 = Py_TYPE(__pyx_t_23)->tp_iternext;
      for (index=0; index < 4; index++) {
        PyObject* item = __pyx_t_13(__pyx_t_23); if (unlikely(!item)) goto __pyx_L17_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_23), 4) < 0) __PYX_ERR(0, 2505, __pyx_L1_error)
      __pyx_t_13 = NULL;
      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
      goto __pyx_L18_unpacking_done;
      __pyx_L17_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
      __pyx_t_13 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2505, __pyx_L1_error)
      __pyx_L18_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_xa, __pyx_t_9);
    __pyx_t_9 = 0;
    __Pyx_XDECREF_SET(__pyx_v_xb, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_XDECREF_SET(__pyx_v_ya, __pyx_t_11);
    __pyx_t_11 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yb, __pyx_t_22);
    __pyx_t_22 = 0;
    __Pyx_XDECREF_SET(__pyx_v_modified_offset_dict, __pyx_t_21);
    __pyx_t_21 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2507
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 */
    __pyx_t_21 = __Pyx_PyObject_GetAttrStr(__pyx_v_channel_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2507, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);

    /* "pygeoprocessing/routing/routing.pyx":2508
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int8)             # <<<<<<<<<<<<<<
 * 
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_mfd_band.ReadAsArray(
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 2508, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_2 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2508, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_2 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2507, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
    }

    /* "pygeoprocessing/routing/routing.pyx":2507
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 */
    __pyx_t_22 = __Pyx_PyObject_Call(__pyx_t_21, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2507, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_22);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2508
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int8)             # <<<<<<<<<<<<<<
 * 
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_mfd_band.ReadAsArray(
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2508, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
    __pyx_t_22 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2508, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_22);
    __pyx_t_21 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_int8); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2508, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
    __pyx_t_22 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_22)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_22);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (!__pyx_t_22) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2508, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_22, __pyx_t_21};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2508, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_22, __pyx_t_21};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2508, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2508, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_22); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_22); __pyx_t_22 = NULL;
        __Pyx_GIVEREF(__pyx_t_21);
        PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_21);
        __pyx_t_21 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2508, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2507
 *         (xa, xb, ya, yb), modified_offset_dict = _generate_read_bounds(
 *             offset_dict, raster_x_size, raster_y_size)
 *         channel_buffer_array[ya:yb, xa:xb] = channel_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 */
    __pyx_t_2 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2507, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2507, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2507, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_11);
    __pyx_t_2 = 0;
    __pyx_t_11 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_channel_buffer_array), __pyx_t_21, __pyx_t_1) < 0)) __PYX_ERR(0, 2507, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2510
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_mfd_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int32)
 * 
 */
    __pyx_t_21 = __Pyx_PyObject_GetAttrStr(__pyx_v_flow_dir_mfd_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);

    /* "pygeoprocessing/routing/routing.pyx":2511
 * 
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_mfd_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int32)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    if (unlikely(__pyx_v_modified_offset_dict == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 2511, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_modified_offset_dict))) {
      __pyx_t_11 = PyDict_Copy(__pyx_v_modified_offset_dict); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2511, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
    } else {
      __pyx_t_11 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_modified_offset_dict, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2510, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
    }

    /* "pygeoprocessing/routing/routing.pyx":2510
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_mfd_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int32)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_21, __pyx_empty_tuple, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2511
 * 
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_mfd_band.ReadAsArray(
 *             **modified_offset_dict).astype(numpy.int32)             # <<<<<<<<<<<<<<
 * 
 *         # ensure these are set for the complier
 */
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_astype); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_21 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int32); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_11);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_11, function);
      }
    }
    if (!__pyx_t_2) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_21); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2511, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_21};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2511, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_21};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2511, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      } else
      #endif
      {
        __pyx_t_22 = PyTuple_New(1+1); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2511, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_22);
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_2); __pyx_t_2 = NULL;
        __Pyx_GIVEREF(__pyx_t_21);
        PyTuple_SET_ITEM(__pyx_t_22, 0+1, __pyx_t_21);
        __pyx_t_21 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_22, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2511, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2510
 *             **modified_offset_dict).astype(numpy.int8)
 * 
 *         flow_dir_buffer_array[ya:yb, xa:xb] = flow_dir_mfd_band.ReadAsArray(             # <<<<<<<<<<<<<<
 *             **modified_offset_dict).astype(numpy.int32)
 * 
 */
    __pyx_t_11 = PySlice_New(__pyx_v_ya, __pyx_v_yb, Py_None); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_22 = PySlice_New(__pyx_v_xa, __pyx_v_xb, Py_None); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 2510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_22);
    __pyx_t_21 = PyTuple_New(2); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 2510, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_21);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_22);
    PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_22);
    __pyx_t_11 = 0;
    __pyx_t_22 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_flow_dir_buffer_array), __pyx_t_21, __pyx_t_1) < 0)) __PYX_ERR(0, 2510, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2514
 * 
 *         # ensure these are set for the complier
 *         xi_n = -1             # <<<<<<<<<<<<<<
 *         yi_n = -1
 * 
 */
    __pyx_v_xi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":2515
 *         # ensure these are set for the complier
 *         xi_n = -1
 *         yi_n = -1             # <<<<<<<<<<<<<<
 * 
 *         # search block for a pixel that has undefined distance to channel
 */
    __pyx_v_yi_n = -1;

    /* "pygeoprocessing/routing/routing.pyx":2518
 * 
 *         # search block for a pixel that has undefined distance to channel
 *         for yi in range(1, win_ysize+1):             # <<<<<<<<<<<<<<
 *             for xi in range(1, win_xsize+1):
 *                 xi_root = xi+xoff-1
 */
    __pyx_t_24 = (__pyx_v_win_ysize + 1);
    __pyx_t_25 = __pyx_t_24;
    for (__pyx_t_14 = 1; __pyx_t_14 < __pyx_t_25; __pyx_t_14+=1) {
      __pyx_v_yi = __pyx_t_14;

      /* "pygeoprocessing/routing/routing.pyx":2519
 *         # search block for a pixel that has undefined distance to channel
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):             # <<<<<<<<<<<<<<
 *                 xi_root = xi+xoff-1
 *                 yi_root = yi+yoff-1
 */
      __pyx_t_26 = (__pyx_v_win_xsize + 1);
      __pyx_t_27 = __pyx_t_26;
      for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_27; __pyx_t_10+=1) {
        __pyx_v_xi = __pyx_t_10;

        /* "pygeoprocessing/routing/routing.pyx":2520
 *         for yi in range(1, win_ysize+1):
 *             for xi in range(1, win_xsize+1):
 *                 xi_root = xi+xoff-1             # <<<<<<<<<<<<<<
 *                 yi_root = yi+yoff-1
 * 
 */
        __pyx_v_xi_root = ((__pyx_v_xi + __pyx_v_xoff) - 1);

        /* "pygeoprocessing/routing/routing.pyx":2521
 *             for xi in range(1, win_xsize+1):
 *                 xi_root = xi+xoff-1
 *                 yi_root = yi+yoff-1             # <<<<<<<<<<<<<<
 * 
 *                 if channel_buffer_array[yi, xi] == 1:
 */
        __pyx_v_yi_root = ((__pyx_v_yi + __pyx_v_yoff) - 1);

        /* "pygeoprocessing/routing/routing.pyx":2523
 *                 yi_root = yi+yoff-1
 * 
 *                 if channel_buffer_array[yi, xi] == 1:             # <<<<<<<<<<<<<<
 *                     distance_to_channel_managed_raster.set(
 *                         xi_root, yi_root, 0)
 */
        __pyx_t_28 = __pyx_v_yi;
        __pyx_t_29 = __pyx_v_xi;
        __pyx_t_30 = -1;
        if (__pyx_t_28 < 0) {
          __pyx_t_28 += __pyx_pybuffernd_channel_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_28 < 0)) __pyx_t_30 = 0;
        } else if (unlikely(__pyx_t_28 >= __pyx_pybuffernd_channel_buffer_array.diminfo[0].shape)) __pyx_t_30 = 0;
        if (__pyx_t_29 < 0) {
          __pyx_t_29 += __pyx_pybuffernd_channel_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 1;
        } else if (unlikely(__pyx_t_29 >= __pyx_pybuffernd_channel_buffer_array.diminfo[1].shape)) __pyx_t_30 = 1;
        if (unlikely(__pyx_t_30 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_30);
          __PYX_ERR(0, 2523, __pyx_L1_error)
        }
        __pyx_t_5 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_channel_buffer_array.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_channel_buffer_array.diminfo[1].strides)) == 1) != 0);
        if (__pyx_t_5) {

          /* "pygeoprocessing/routing/routing.pyx":2524
 * 
 *                 if channel_buffer_array[yi, xi] == 1:
 *                     distance_to_channel_managed_raster.set(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root, 0)
 *                     continue
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_distance_to_channel_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root, 0.0);

          /* "pygeoprocessing/routing/routing.pyx":2526
 *                     distance_to_channel_managed_raster.set(
 *                         xi_root, yi_root, 0)
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 if flow_dir_buffer_array[yi, xi] == 0:
 */
          goto __pyx_L21_continue;

          /* "pygeoprocessing/routing/routing.pyx":2523
 *                 yi_root = yi+yoff-1
 * 
 *                 if channel_buffer_array[yi, xi] == 1:             # <<<<<<<<<<<<<<
 *                     distance_to_channel_managed_raster.set(
 *                         xi_root, yi_root, 0)
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2528
 *                     continue
 * 
 *                 if flow_dir_buffer_array[yi, xi] == 0:             # <<<<<<<<<<<<<<
 *                     # nodata flow, so we skip
 *                     continue
 */
        __pyx_t_31 = __pyx_v_yi;
        __pyx_t_32 = __pyx_v_xi;
        __pyx_t_30 = -1;
        if (__pyx_t_31 < 0) {
          __pyx_t_31 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape;
          if (unlikely(__pyx_t_31 < 0)) __pyx_t_30 = 0;
        } else if (unlikely(__pyx_t_31 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].shape)) __pyx_t_30 = 0;
        if (__pyx_t_32 < 0) {
          __pyx_t_32 += __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape;
          if (unlikely(__pyx_t_32 < 0)) __pyx_t_30 = 1;
        } else if (unlikely(__pyx_t_32 >= __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].shape)) __pyx_t_30 = 1;
        if (unlikely(__pyx_t_30 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_30);
          __PYX_ERR(0, 2528, __pyx_L1_error)
        }
        __pyx_t_5 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[0].strides, __pyx_t_32, __pyx_pybuffernd_flow_dir_buffer_array.diminfo[1].strides)) == 0) != 0);
        if (__pyx_t_5) {

          /* "pygeoprocessing/routing/routing.pyx":2530
 *                 if flow_dir_buffer_array[yi, xi] == 0:
 *                     # nodata flow, so we skip
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 if is_close(distance_to_channel_managed_raster.get(
 */
          goto __pyx_L21_continue;

          /* "pygeoprocessing/routing/routing.pyx":2528
 *                     continue
 * 
 *                 if flow_dir_buffer_array[yi, xi] == 0:             # <<<<<<<<<<<<<<
 *                     # nodata flow, so we skip
 *                     continue
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2532
 *                     continue
 * 
 *                 if is_close(distance_to_channel_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root), distance_nodata):
 *                     distance_to_channel_stack.push(
 */
        __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_distance_to_channel_managed_raster, __pyx_v_xi_root, __pyx_v_yi_root), __pyx_v_distance_nodata) != 0);
        if (__pyx_t_5) {

          /* "pygeoprocessing/routing/routing.pyx":2535
 *                         xi_root, yi_root), distance_nodata):
 *                     distance_to_channel_stack.push(
 *                         FlowPixelType(xi_root, yi_root, 0, 0.0))             # <<<<<<<<<<<<<<
 * 
 *                 while not distance_to_channel_stack.empty():
 */
          __pyx_t_33.xi = __pyx_v_xi_root;
          __pyx_t_33.yi = __pyx_v_yi_root;
          __pyx_t_33.last_flow_dir = 0;
          __pyx_t_33.value = 0.0;

          /* "pygeoprocessing/routing/routing.pyx":2534
 *                 if is_close(distance_to_channel_managed_raster.get(
 *                         xi_root, yi_root), distance_nodata):
 *                     distance_to_channel_stack.push(             # <<<<<<<<<<<<<<
 *                         FlowPixelType(xi_root, yi_root, 0, 0.0))
 * 
 */
          __pyx_v_distance_to_channel_stack.push(__pyx_t_33);

          /* "pygeoprocessing/routing/routing.pyx":2532
 *                     continue
 * 
 *                 if is_close(distance_to_channel_managed_raster.get(             # <<<<<<<<<<<<<<
 *                         xi_root, yi_root), distance_nodata):
 *                     distance_to_channel_stack.push(
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2537
 *                         FlowPixelType(xi_root, yi_root, 0, 0.0))
 * 
 *                 while not distance_to_channel_stack.empty():             # <<<<<<<<<<<<<<
 *                     pixel = distance_to_channel_stack.top()
 *                     distance_to_channel_stack.pop()
 */
        while (1) {
          __pyx_t_5 = ((!(__pyx_v_distance_to_channel_stack.empty() != 0)) != 0);
          if (!__pyx_t_5) break;

          /* "pygeoprocessing/routing/routing.pyx":2538
 * 
 *                 while not distance_to_channel_stack.empty():
 *                     pixel = distance_to_channel_stack.top()             # <<<<<<<<<<<<<<
 *                     distance_to_channel_stack.pop()
 *                     is_a_channel = (
 */
          __pyx_v_pixel = __pyx_v_distance_to_channel_stack.top();

          /* "pygeoprocessing/routing/routing.pyx":2539
 *                 while not distance_to_channel_stack.empty():
 *                     pixel = distance_to_channel_stack.top()
 *                     distance_to_channel_stack.pop()             # <<<<<<<<<<<<<<
 *                     is_a_channel = (
 *                         channel_managed_raster.get(pixel.xi, pixel.yi) == 1)
 */
          __pyx_v_distance_to_channel_stack.pop();

          /* "pygeoprocessing/routing/routing.pyx":2541
 *                     distance_to_channel_stack.pop()
 *                     is_a_channel = (
 *                         channel_managed_raster.get(pixel.xi, pixel.yi) == 1)             # <<<<<<<<<<<<<<
 *                     if is_a_channel:
 *                         distance_to_channel_managed_raster.set(
 */
          __pyx_v_is_a_channel = (__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_channel_managed_raster, __pyx_v_pixel.xi, __pyx_v_pixel.yi) == 1.0);

          /* "pygeoprocessing/routing/routing.pyx":2542
 *                     is_a_channel = (
 *                         channel_managed_raster.get(pixel.xi, pixel.yi) == 1)
 *                     if is_a_channel:             # <<<<<<<<<<<<<<
 *                         distance_to_channel_managed_raster.set(
 *                             pixel.xi, pixel.yi, 0)
 */
          __pyx_t_5 = (__pyx_v_is_a_channel != 0);
          if (__pyx_t_5) {

            /* "pygeoprocessing/routing/routing.pyx":2543
 *                         channel_managed_raster.get(pixel.xi, pixel.yi) == 1)
 *                     if is_a_channel:
 *                         distance_to_channel_managed_raster.set(             # <<<<<<<<<<<<<<
 *                             pixel.xi, pixel.yi, 0)
 *                         continue
 */
            __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_distance_to_channel_managed_raster, __pyx_v_pixel.xi, __pyx_v_pixel.yi, 0.0);

            /* "pygeoprocessing/routing/routing.pyx":2545
 *                         distance_to_channel_managed_raster.set(
 *                             pixel.xi, pixel.yi, 0)
 *                         continue             # <<<<<<<<<<<<<<
 * 
 *                     compressed_flow_dir = (
 */
            goto __pyx_L26_continue;

            /* "pygeoprocessing/routing/routing.pyx":2542
 *                     is_a_channel = (
 *                         channel_managed_raster.get(pixel.xi, pixel.yi) == 1)
 *                     if is_a_channel:             # <<<<<<<<<<<<<<
 *                         distance_to_channel_managed_raster.set(
 *                             pixel.xi, pixel.yi, 0)
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":2548
 * 
 *                     compressed_flow_dir = (
 *                         <int>flow_dir_mfd_managed_raster.get(             # <<<<<<<<<<<<<<
 *                             pixel.xi, pixel.yi))
 * 
 */
          __pyx_v_compressed_flow_dir = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_mfd_managed_raster, __pyx_v_pixel.xi, __pyx_v_pixel.yi));

          /* "pygeoprocessing/routing/routing.pyx":2551
 *                             pixel.xi, pixel.yi))
 * 
 *                     preempted = 0             # <<<<<<<<<<<<<<
 *                     for i_n in range(pixel.last_flow_dir, 8):
 *                         flow_dir_weight = 0xF & (
 */
          __pyx_v_preempted = 0;

          /* "pygeoprocessing/routing/routing.pyx":2552
 * 
 *                     preempted = 0
 *                     for i_n in range(pixel.last_flow_dir, 8):             # <<<<<<<<<<<<<<
 *                         flow_dir_weight = 0xF & (
 *                             compressed_flow_dir >> (i_n * 4))
 */
          for (__pyx_t_30 = __pyx_v_pixel.last_flow_dir; __pyx_t_30 < 8; __pyx_t_30+=1) {
            __pyx_v_i_n = __pyx_t_30;

            /* "pygeoprocessing/routing/routing.pyx":2553
 *                     preempted = 0
 *                     for i_n in range(pixel.last_flow_dir, 8):
 *                         flow_dir_weight = 0xF & (             # <<<<<<<<<<<<<<
 *                             compressed_flow_dir >> (i_n * 4))
 *                         if flow_dir_weight == 0:
 */
            __pyx_v_flow_dir_weight = (0xF & (__pyx_v_compressed_flow_dir >> (__pyx_v_i_n * 4)));

            /* "pygeoprocessing/routing/routing.pyx":2555
 *                         flow_dir_weight = 0xF & (
 *                             compressed_flow_dir >> (i_n * 4))
 *                         if flow_dir_weight == 0:             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_5 = ((__pyx_v_flow_dir_weight == 0) != 0);
            if (__pyx_t_5) {

              /* "pygeoprocessing/routing/routing.pyx":2556
 *                             compressed_flow_dir >> (i_n * 4))
 *                         if flow_dir_weight == 0:
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         xi_n = pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 */
              goto __pyx_L29_continue;

              /* "pygeoprocessing/routing/routing.pyx":2555
 *                         flow_dir_weight = 0xF & (
 *                             compressed_flow_dir >> (i_n * 4))
 *                         if flow_dir_weight == 0:             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2558
 *                             continue
 * 
 *                         xi_n = pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                         yi_n = pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 */
            __pyx_v_xi_n = (__pyx_v_pixel.xi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

            /* "pygeoprocessing/routing/routing.pyx":2559
 * 
 *                         xi_n = pixel.xi+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                         yi_n = pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 */
            __pyx_v_yi_n = (__pyx_v_pixel.yi + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":2561
 *                         yi_n = pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            __pyx_t_4 = ((__pyx_v_xi_n < 0) != 0);
            if (!__pyx_t_4) {
            } else {
              __pyx_t_5 = __pyx_t_4;
              goto __pyx_L33_bool_binop_done;
            }
            __pyx_t_4 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_4) {
            } else {
              __pyx_t_5 = __pyx_t_4;
              goto __pyx_L33_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":2562
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             continue
 * 
 */
            __pyx_t_4 = ((__pyx_v_yi_n < 0) != 0);
            if (!__pyx_t_4) {
            } else {
              __pyx_t_5 = __pyx_t_4;
              goto __pyx_L33_bool_binop_done;
            }
            __pyx_t_4 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
            __pyx_t_5 = __pyx_t_4;
            __pyx_L33_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":2561
 *                         yi_n = pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            if (__pyx_t_5) {

              /* "pygeoprocessing/routing/routing.pyx":2563
 *                         if (xi_n < 0 or xi_n >= raster_x_size or
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue             # <<<<<<<<<<<<<<
 * 
 *                         n_distance = distance_to_channel_managed_raster.get(
 */
              goto __pyx_L29_continue;

              /* "pygeoprocessing/routing/routing.pyx":2561
 *                         yi_n = pixel.yi+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 * 
 *                         if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_n < 0 or yi_n >= raster_y_size):
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2565
 *                             continue
 * 
 *                         n_distance = distance_to_channel_managed_raster.get(             # <<<<<<<<<<<<<<
 *                             xi_n, yi_n)
 * 
 */
            __pyx_v_n_distance = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_distance_to_channel_managed_raster, __pyx_v_xi_n, __pyx_v_yi_n);

            /* "pygeoprocessing/routing/routing.pyx":2568
 *                             xi_n, yi_n)
 * 
 *                         if is_close(n_distance, distance_nodata):             # <<<<<<<<<<<<<<
 *                             preempted = 1
 *                             pixel.last_flow_dir = i_n
 */
            __pyx_t_5 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_n_distance, __pyx_v_distance_nodata) != 0);
            if (__pyx_t_5) {

              /* "pygeoprocessing/routing/routing.pyx":2569
 * 
 *                         if is_close(n_distance, distance_nodata):
 *                             preempted = 1             # <<<<<<<<<<<<<<
 *                             pixel.last_flow_dir = i_n
 *                             distance_to_channel_stack.push(pixel)
 */
              __pyx_v_preempted = 1;

              /* "pygeoprocessing/routing/routing.pyx":2570
 *                         if is_close(n_distance, distance_nodata):
 *                             preempted = 1
 *                             pixel.last_flow_dir = i_n             # <<<<<<<<<<<<<<
 *                             distance_to_channel_stack.push(pixel)
 *                             distance_to_channel_stack.push(
 */
              __pyx_v_pixel.last_flow_dir = __pyx_v_i_n;

              /* "pygeoprocessing/routing/routing.pyx":2571
 *                             preempted = 1
 *                             pixel.last_flow_dir = i_n
 *                             distance_to_channel_stack.push(pixel)             # <<<<<<<<<<<<<<
 *                             distance_to_channel_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, 0.0))
 */
              __pyx_v_distance_to_channel_stack.push(__pyx_v_pixel);

              /* "pygeoprocessing/routing/routing.pyx":2573
 *                             distance_to_channel_stack.push(pixel)
 *                             distance_to_channel_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, 0.0))             # <<<<<<<<<<<<<<
 *                             break
 * 
 */
              __pyx_t_33.xi = __pyx_v_xi_n;
              __pyx_t_33.yi = __pyx_v_yi_n;
              __pyx_t_33.last_flow_dir = 0;
              __pyx_t_33.value = 0.0;

              /* "pygeoprocessing/routing/routing.pyx":2572
 *                             pixel.last_flow_dir = i_n
 *                             distance_to_channel_stack.push(pixel)
 *                             distance_to_channel_stack.push(             # <<<<<<<<<<<<<<
 *                                 FlowPixelType(xi_n, yi_n, 0, 0.0))
 *                             break
 */
              __pyx_v_distance_to_channel_stack.push(__pyx_t_33);

              /* "pygeoprocessing/routing/routing.pyx":2574
 *                             distance_to_channel_stack.push(
 *                                 FlowPixelType(xi_n, yi_n, 0, 0.0))
 *                             break             # <<<<<<<<<<<<<<
 * 
 *                         # if a weight is passed we use it directly and do
 */
              goto __pyx_L30_break;

              /* "pygeoprocessing/routing/routing.pyx":2568
 *                             xi_n, yi_n)
 * 
 *                         if is_close(n_distance, distance_nodata):             # <<<<<<<<<<<<<<
 *                             preempted = 1
 *                             pixel.last_flow_dir = i_n
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2581
 *                         # then "distance" is being calculated and we account
 *                         # for diagonal distance.
 *                         if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                             weight_val = weight_raster.get(xi_n, yi_n)
 *                             if is_close(weight_val, weight_nodata):
 */
            __pyx_t_5 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
            __pyx_t_4 = (__pyx_t_5 != 0);
            if (__pyx_t_4) {

              /* "pygeoprocessing/routing/routing.pyx":2582
 *                         # for diagonal distance.
 *                         if weight_raster is not None:
 *                             weight_val = weight_raster.get(xi_n, yi_n)             # <<<<<<<<<<<<<<
 *                             if is_close(weight_val, weight_nodata):
 *                                 weight_val = 0.0
 */
              __pyx_v_weight_val = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_weight_raster, __pyx_v_xi_n, __pyx_v_yi_n);

              /* "pygeoprocessing/routing/routing.pyx":2583
 *                         if weight_raster is not None:
 *                             weight_val = weight_raster.get(xi_n, yi_n)
 *                             if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                 weight_val = 0.0
 *                         else:
 */
              __pyx_t_4 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_weight_val, __pyx_v_weight_nodata) != 0);
              if (__pyx_t_4) {

                /* "pygeoprocessing/routing/routing.pyx":2584
 *                             weight_val = weight_raster.get(xi_n, yi_n)
 *                             if is_close(weight_val, weight_nodata):
 *                                 weight_val = 0.0             # <<<<<<<<<<<<<<
 *                         else:
 *                             weight_val = (SQRT2 if i_n % 2 else 1)
 */
                __pyx_v_weight_val = 0.0;

                /* "pygeoprocessing/routing/routing.pyx":2583
 *                         if weight_raster is not None:
 *                             weight_val = weight_raster.get(xi_n, yi_n)
 *                             if is_close(weight_val, weight_nodata):             # <<<<<<<<<<<<<<
 *                                 weight_val = 0.0
 *                         else:
 */
              }

              /* "pygeoprocessing/routing/routing.pyx":2581
 *                         # then "distance" is being calculated and we account
 *                         # for diagonal distance.
 *                         if weight_raster is not None:             # <<<<<<<<<<<<<<
 *                             weight_val = weight_raster.get(xi_n, yi_n)
 *                             if is_close(weight_val, weight_nodata):
 */
              goto __pyx_L38;
            }

            /* "pygeoprocessing/routing/routing.pyx":2586
 *                                 weight_val = 0.0
 *                         else:
 *                             weight_val = (SQRT2 if i_n % 2 else 1)             # <<<<<<<<<<<<<<
 * 
 *                         pixel.value += flow_dir_weight * (
 */
            /*else*/ {
              if ((__Pyx_mod_long(__pyx_v_i_n, 2) != 0)) {
                __pyx_t_12 = __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2;
              } else {
                __pyx_t_12 = 1.0;
              }
              __pyx_v_weight_val = __pyx_t_12;
            }
            __pyx_L38:;

            /* "pygeoprocessing/routing/routing.pyx":2588
 *                             weight_val = (SQRT2 if i_n % 2 else 1)
 * 
 *                         pixel.value += flow_dir_weight * (             # <<<<<<<<<<<<<<
 *                             weight_val + n_distance)
 * 
 */
            __pyx_v_pixel.value = (__pyx_v_pixel.value + (__pyx_v_flow_dir_weight * (__pyx_v_weight_val + __pyx_v_n_distance)));
            __pyx_L29_continue:;
          }
          __pyx_L30_break:;

          /* "pygeoprocessing/routing/routing.pyx":2591
 *                             weight_val + n_distance)
 * 
 *                     if preempted:             # <<<<<<<<<<<<<<
 *                         continue
 * 
 */
          __pyx_t_4 = (__pyx_v_preempted != 0);
          if (__pyx_t_4) {

            /* "pygeoprocessing/routing/routing.pyx":2592
 * 
 *                     if preempted:
 *                         continue             # <<<<<<<<<<<<<<
 * 
 *                     sum_of_flow_weights = 0
 */
            goto __pyx_L26_continue;

            /* "pygeoprocessing/routing/routing.pyx":2591
 *                             weight_val + n_distance)
 * 
 *                     if preempted:             # <<<<<<<<<<<<<<
 *                         continue
 * 
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":2594
 *                         continue
 * 
 *                     sum_of_flow_weights = 0             # <<<<<<<<<<<<<<
 *                     for i_n in range(8):
 *                         sum_of_flow_weights += 0xF & (
 */
          __pyx_v_sum_of_flow_weights = 0;

          /* "pygeoprocessing/routing/routing.pyx":2595
 * 
 *                     sum_of_flow_weights = 0
 *                     for i_n in range(8):             # <<<<<<<<<<<<<<
 *                         sum_of_flow_weights += 0xF & (
 *                             compressed_flow_dir >> (i_n * 4))
 */
          for (__pyx_t_30 = 0; __pyx_t_30 < 8; __pyx_t_30+=1) {
            __pyx_v_i_n = __pyx_t_30;

            /* "pygeoprocessing/routing/routing.pyx":2596
 *                     sum_of_flow_weights = 0
 *                     for i_n in range(8):
 *                         sum_of_flow_weights += 0xF & (             # <<<<<<<<<<<<<<
 *                             compressed_flow_dir >> (i_n * 4))
 * 
 */
            __pyx_v_sum_of_flow_weights = (__pyx_v_sum_of_flow_weights + (0xF & (__pyx_v_compressed_flow_dir >> (__pyx_v_i_n * 4))));
          }

          /* "pygeoprocessing/routing/routing.pyx":2599
 *                             compressed_flow_dir >> (i_n * 4))
 * 
 *                     if sum_of_flow_weights != 0:             # <<<<<<<<<<<<<<
 *                         pixel.value = pixel.value / sum_of_flow_weights
 *                     else:
 */
          __pyx_t_4 = ((__pyx_v_sum_of_flow_weights != 0) != 0);
          if (__pyx_t_4) {

            /* "pygeoprocessing/routing/routing.pyx":2600
 * 
 *                     if sum_of_flow_weights != 0:
 *                         pixel.value = pixel.value / sum_of_flow_weights             # <<<<<<<<<<<<<<
 *                     else:
 *                         pixel.value = 0
 */
            if (unlikely(__pyx_v_sum_of_flow_weights == 0)) {
              PyErr_SetString(PyExc_ZeroDivisionError, "float division");
              __PYX_ERR(0, 2600, __pyx_L1_error)
            }
            __pyx_v_pixel.value = (__pyx_v_pixel.value / __pyx_v_sum_of_flow_weights);

            /* "pygeoprocessing/routing/routing.pyx":2599
 *                             compressed_flow_dir >> (i_n * 4))
 * 
 *                     if sum_of_flow_weights != 0:             # <<<<<<<<<<<<<<
 *                         pixel.value = pixel.value / sum_of_flow_weights
 *                     else:
 */
            goto __pyx_L43;
          }

          /* "pygeoprocessing/routing/routing.pyx":2602
 *                         pixel.value = pixel.value / sum_of_flow_weights
 *                     else:
 *                         pixel.value = 0             # <<<<<<<<<<<<<<
 *                     distance_to_channel_managed_raster.set(
 *                         pixel.xi, pixel.yi, pixel.value)
 */
          /*else*/ {
            __pyx_v_pixel.value = 0.0;
          }
          __pyx_L43:;

          /* "pygeoprocessing/routing/routing.pyx":2603
 *                     else:
 *                         pixel.value = 0
 *                     distance_to_channel_managed_raster.set(             # <<<<<<<<<<<<<<
 *                         pixel.xi, pixel.yi, pixel.value)
 * 
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_distance_to_channel_managed_raster, __pyx_v_pixel.xi, __pyx_v_pixel.yi, __pyx_v_pixel.value);
          __pyx_L26_continue:;
        }
        __pyx_L21_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":2479
 * 
 *     # this outer loop searches for undefined channels
 *     for offset_dict in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *         channel_raster_path_band[0], offset_only=True,
 *             largest_block=0):
 */
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2606
 *                         pixel.xi, pixel.yi, pixel.value)
 * 
 *     distance_to_channel_managed_raster.close()             # <<<<<<<<<<<<<<
 *     channel_managed_raster.close()
 *     flow_dir_mfd_managed_raster.close()
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_distance_to_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2606, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_21 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_21)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_21);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_21) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_21); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2606, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2606, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2607
 * 
 *     distance_to_channel_managed_raster.close()
 *     channel_managed_raster.close()             # <<<<<<<<<<<<<<
 *     flow_dir_mfd_managed_raster.close()
 *     if weight_raster is not None:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_channel_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2607, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_21 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_21)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_21);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_21) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_21); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2607, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2607, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2608
 *     distance_to_channel_managed_raster.close()
 *     channel_managed_raster.close()
 *     flow_dir_mfd_managed_raster.close()             # <<<<<<<<<<<<<<
 *     if weight_raster is not None:
 *         weight_raster.close()
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_flow_dir_mfd_managed_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_21 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_21)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_21);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_21) {
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_21); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2608, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
  } else {
    __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2608, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2609
 *     channel_managed_raster.close()
 *     flow_dir_mfd_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  __pyx_t_4 = (((PyObject *)__pyx_v_weight_raster) != Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "pygeoprocessing/routing/routing.pyx":2610
 *     flow_dir_mfd_managed_raster.close()
 *     if weight_raster is not None:
 *         weight_raster.close()             # <<<<<<<<<<<<<<
 *     LOGGER.info('%.1f%% complete', 100.0)
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_weight_raster), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2610, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_21 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_21)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_21);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (__pyx_t_21) {
      __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_21); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2610, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
    } else {
      __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2610, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2609
 *     channel_managed_raster.close()
 *     flow_dir_mfd_managed_raster.close()
 *     if weight_raster is not None:             # <<<<<<<<<<<<<<
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2611
 *     if weight_raster is not None:
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2369
 * 
 * 
 * def distance_to_channel_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path, weight_raster_path_band=None,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  __Pyx_XDECREF(__pyx_t_23);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.distance_to_channel_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_channel_buffer_array.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_flow_dir_buffer_array.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_channel_buffer_array);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_buffer_array);
  __Pyx_XDECREF(__pyx_v_path);
  __Pyx_XDECREF((PyObject *)__pyx_v_distance_to_channel_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_channel_managed_raster);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_mfd_managed_raster);
  __Pyx_XDECREF(__pyx_v_channel_raster);
  __Pyx_XDECREF(__pyx_v_channel_band);
  __Pyx_XDECREF(__pyx_v_flow_dir_mfd_raster);
  __Pyx_XDECREF(__pyx_v_flow_dir_mfd_band);
  __Pyx_XDECREF((PyObject *)__pyx_v_weight_raster);
  __Pyx_XDECREF(__pyx_v_raw_weight_nodata);
  __Pyx_XDECREF(__pyx_v_flow_dir_raster_info);
  __Pyx_XDECREF(__pyx_v_offset_dict);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_xa);
  __Pyx_XDECREF(__pyx_v_xb);
  __Pyx_XDECREF(__pyx_v_ya);
  __Pyx_XDECREF(__pyx_v_yb);
  __Pyx_XDECREF(__pyx_v_modified_offset_dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":2614
 * 
 * 
 * def extract_streams_mfd(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band, flow_dir_mfd_path_band, double flow_threshold,
 *         target_stream_raster_path, double trace_threshold_proportion=1.0,
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_17extract_streams_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_16extract_streams_mfd[] = "Classify a stream raster from MFD flow accumulation.\n\n    This function classifies pixels as streams that have a flow accumulation\n    value >= `flow_threshold` and can trace further upstream with a fuzzy\n    propotion if `trace_threshold_proportion` is set < 1.0\n\n    Parameters:\n        flow_accum_raster_path_band (tuple): a string/integer tuple indicating\n            the flow accumulation raster to use as a basis for thresholding\n            a stream. Values in this raster that are >= flow_threshold will\n            be classified as streams. This raster should be derived from\n            `dem_raster_path_band` using\n            `pygeoprocessing.routing.flow_accumulation_mfd`.\n        flow_dir_mfd_path_band (str): path to multiple flow direction\n            raster, required to join divergent streams.\n        flow_threshold (float): the value in `flow_accum_raster_path_band` to\n            indicate where a stream exists.\n        target_stream_raster_path (str): path to the target stream raster.\n            This raster will be the same dimensions and projection as\n            `dem_raster_path_band` and will contain 1s where a stream is\n            defined, 0 where the flow accumulation layer is defined but no\n            stream exists, and nodata otherwise.\n        trace_threshold_proportion (float): this value indicates what\n            proportion of the flow_threshold is enough to classify a pixel\n            as a stream after the stream has been traced from a\n            `flow_threshold` drain. Setting this value < 1.0 is useful for\n            classifying streams in regions that have highly divergent flow\n            directions.\n        gtiff_creation_options (list): this is an argument list that will be\n            passed to the GTiff driver.  Useful for blocksizes, compression,\n            and more.\n\n    Returns:\n        None.\n    ";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_17extract_streams_mfd = {"extract_streams_mfd", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_17extract_streams_mfd, METH_VARARGS|METH_KEYWORDS, __pyx_doc_15pygeoprocessing_7routing_7routing_16extract_streams_mfd};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_17extract_streams_mfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_flow_accum_raster_path_band = 0;
  PyObject *__pyx_v_flow_dir_mfd_path_band = 0;
  double __pyx_v_flow_threshold;
  PyObject *__pyx_v_target_stream_raster_path = 0;
  double __pyx_v_trace_threshold_proportion;
  PyObject *__pyx_v_gtiff_creation_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("extract_streams_mfd (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_flow_accum_raster_path_band,&__pyx_n_s_flow_dir_mfd_path_band,&__pyx_n_s_flow_threshold,&__pyx_n_s_target_stream_raster_path,&__pyx_n_s_trace_threshold_proportion,&__pyx_n_s_gtiff_creation_options,0};
    PyObject* values[6] = {0,0,0,0,0,0};
    values[5] = __pyx_k__31;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_accum_raster_path_band)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_dir_mfd_path_band)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("extract_streams_mfd", 0, 4, 6, 1); __PYX_ERR(0, 2614, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flow_threshold)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("extract_streams_mfd", 0, 4, 6, 2); __PYX_ERR(0, 2614, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target_stream_raster_path)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("extract_streams_mfd", 0, 4, 6, 3); __PYX_ERR(0, 2614, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_trace_threshold_proportion);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gtiff_creation_options);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "extract_streams_mfd") < 0)) __PYX_ERR(0, 2614, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_flow_accum_raster_path_band = values[0];
    __pyx_v_flow_dir_mfd_path_band = values[1];
    __pyx_v_flow_threshold = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_flow_threshold == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2615, __pyx_L3_error)
    __pyx_v_target_stream_raster_path = values[3];
    if (values[4]) {
      __pyx_v_trace_threshold_proportion = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_trace_threshold_proportion == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2616, __pyx_L3_error)
    } else {
      __pyx_v_trace_threshold_proportion = ((double)1.0);
    }
    __pyx_v_gtiff_creation_options = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("extract_streams_mfd", 0, 4, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2614, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.extract_streams_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_16extract_streams_mfd(__pyx_self, __pyx_v_flow_accum_raster_path_band, __pyx_v_flow_dir_mfd_path_band, __pyx_v_flow_threshold, __pyx_v_target_stream_raster_path, __pyx_v_trace_threshold_proportion, __pyx_v_gtiff_creation_options);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_16extract_streams_mfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_flow_accum_raster_path_band, PyObject *__pyx_v_flow_dir_mfd_path_band, double __pyx_v_flow_threshold, PyObject *__pyx_v_target_stream_raster_path, double __pyx_v_trace_threshold_proportion, PyObject *__pyx_v_gtiff_creation_options) {
  PyObject *__pyx_v_flow_accum_info = NULL;
  double __pyx_v_flow_accum_nodata;
  long __pyx_v_stream_nodata;
  int __pyx_v_raster_x_size;
  int __pyx_v_raster_y_size;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_accum_mr = 0;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_stream_mr = 0;
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *__pyx_v_flow_dir_mfd_mr = 0;
  int __pyx_v_xoff;
  int __pyx_v_yoff;
  int __pyx_v_win_xsize;
  int __pyx_v_win_ysize;
  int __pyx_v_xi;
  int __pyx_v_yi;
  int __pyx_v_xi_root;
  int __pyx_v_yi_root;
  int __pyx_v_i_n;
  int __pyx_v_xi_n;
  int __pyx_v_yi_n;
  int __pyx_v_i_sn;
  int __pyx_v_xi_sn;
  int __pyx_v_yi_sn;
  int __pyx_v_flow_dir_mfd;
  double __pyx_v_flow_accum;
  double __pyx_v_trace_flow_threshold;
  int __pyx_v_n_iterations;
  int __pyx_v_is_outlet;
  int __pyx_v_stream_val;
  int __pyx_v_flow_dir_nodata;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_v_open_set;
  __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateQueueType __pyx_v_backtrace_set;
  int __pyx_v_xi_bn;
  int __pyx_v_yi_bn;
  time_t __pyx_v_last_log_time;
  PyObject *__pyx_v_block_offsets = NULL;
  PyObject *__pyx_v_current_pixel = NULL;
  PyObject *__pyx_v_stream_raster = NULL;
  PyObject *__pyx_v_stream_band = NULL;
  PyObject *__pyx_v_stream_array = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  double __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_t_16;
  int __pyx_t_17;
  int __pyx_t_18;
  int __pyx_t_19;
  struct __pyx_t_15pygeoprocessing_7routing_7routing_CoordinateType __pyx_t_20;
  int __pyx_t_21;
  __Pyx_RefNannySetupContext("extract_streams_mfd", 0);

  /* "pygeoprocessing/routing/routing.pyx":2653
 *         None.
 *     """
 *     if trace_threshold_proportion < 0.or trace_threshold_proportion > 1.0:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "trace_threshold_proportion should be in the range [0.0, 1.0] "
 */
  __pyx_t_2 = ((__pyx_v_trace_threshold_proportion < 0.) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_trace_threshold_proportion > 1.0) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "pygeoprocessing/routing/routing.pyx":2656
 *         raise ValueError(
 *             "trace_threshold_proportion should be in the range [0.0, 1.0] "
 *             "actual value is: %s" % trace_threshold_proportion)             # <<<<<<<<<<<<<<
 * 
 *     flow_accum_info = pygeoprocessing.get_raster_info(
 */
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_trace_threshold_proportion); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2656, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_trace_threshold_proportion_shoul, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2656, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2654
 *     """
 *     if trace_threshold_proportion < 0.or trace_threshold_proportion > 1.0:
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "trace_threshold_proportion should be in the range [0.0, 1.0] "
 *             "actual value is: %s" % trace_threshold_proportion)
 */
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2654, __pyx_L1_error)

    /* "pygeoprocessing/routing/routing.pyx":2653
 *         None.
 *     """
 *     if trace_threshold_proportion < 0.or trace_threshold_proportion > 1.0:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "trace_threshold_proportion should be in the range [0.0, 1.0] "
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2658
 *             "actual value is: %s" % trace_threshold_proportion)
 * 
 *     flow_accum_info = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band[0])
 *     cdef double flow_accum_nodata = flow_accum_info['nodata'][
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2659
 * 
 *     flow_accum_info = pygeoprocessing.get_raster_info(
 *         flow_accum_raster_path_band[0])             # <<<<<<<<<<<<<<
 *     cdef double flow_accum_nodata = flow_accum_info['nodata'][
 *         flow_accum_raster_path_band[1]-1]
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_6) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2658, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_4};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2658, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_4};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2658, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2658, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2658, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_flow_accum_info = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2660
 *     flow_accum_info = pygeoprocessing.get_raster_info(
 *         flow_accum_raster_path_band[0])
 *     cdef double flow_accum_nodata = flow_accum_info['nodata'][             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band[1]-1]
 *     stream_nodata = 255
 */
  __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_accum_info, __pyx_n_s_nodata); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "pygeoprocessing/routing/routing.pyx":2661
 *         flow_accum_raster_path_band[0])
 *     cdef double flow_accum_nodata = flow_accum_info['nodata'][
 *         flow_accum_raster_path_band[1]-1]             # <<<<<<<<<<<<<<
 *     stream_nodata = 255
 * 
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyInt_SubtractObjC(__pyx_t_5, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2661, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2660
 *     flow_accum_info = pygeoprocessing.get_raster_info(
 *         flow_accum_raster_path_band[0])
 *     cdef double flow_accum_nodata = flow_accum_info['nodata'][             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band[1]-1]
 *     stream_nodata = 255
 */
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2660, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_flow_accum_nodata = __pyx_t_8;

  /* "pygeoprocessing/routing/routing.pyx":2662
 *     cdef double flow_accum_nodata = flow_accum_info['nodata'][
 *         flow_accum_raster_path_band[1]-1]
 *     stream_nodata = 255             # <<<<<<<<<<<<<<
 * 
 *     cdef int raster_x_size, raster_y_size
 */
  __pyx_v_stream_nodata = 0xFF;

  /* "pygeoprocessing/routing/routing.pyx":2665
 * 
 *     cdef int raster_x_size, raster_y_size
 *     raster_x_size, raster_y_size = flow_accum_info['raster_size']             # <<<<<<<<<<<<<<
 * 
 *     pygeoprocessing.new_raster_from_base(
 */
  __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_flow_accum_info, __pyx_n_s_raster_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2665, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
    PyObject* sequence = __pyx_t_5;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 2665, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_t_3);
    #else
    __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2665, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_7 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_7);
    index = 1; __pyx_t_3 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_4), 2) < 0) __PYX_ERR(0, 2665, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L7_unpacking_done;
    __pyx_L6_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 2665, __pyx_L1_error)
    __pyx_L7_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2665, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2665, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_raster_x_size = __pyx_t_10;
  __pyx_v_raster_y_size = __pyx_t_11;

  /* "pygeoprocessing/routing/routing.pyx":2667
 *     raster_x_size, raster_y_size = flow_accum_info['raster_size']
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band[0], target_stream_raster_path,
 *         gdal.GDT_Byte, [stream_nodata], fill_value_list=[stream_nodata],
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_new_raster_from_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2668
 * 
 *     pygeoprocessing.new_raster_from_base(
 *         flow_accum_raster_path_band[0], target_stream_raster_path,             # <<<<<<<<<<<<<<
 *         gdal.GDT_Byte, [stream_nodata], fill_value_list=[stream_nodata],
 *         gtiff_creation_options=gtiff_creation_options)
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pygeoprocessing/routing/routing.pyx":2669
 *     pygeoprocessing.new_raster_from_base(
 *         flow_accum_raster_path_band[0], target_stream_raster_path,
 *         gdal.GDT_Byte, [stream_nodata], fill_value_list=[stream_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 * 
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_GDT_Byte); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From_long(__pyx_v_stream_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = PyList_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2667
 *     raster_x_size, raster_y_size = flow_accum_info['raster_size']
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band[0], target_stream_raster_path,
 *         gdal.GDT_Byte, [stream_nodata], fill_value_list=[stream_nodata],
 */
  __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __Pyx_INCREF(__pyx_v_target_stream_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_stream_raster_path);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_target_stream_raster_path);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_6);
  __pyx_t_5 = 0;
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2669
 *     pygeoprocessing.new_raster_from_base(
 *         flow_accum_raster_path_band[0], target_stream_raster_path,
 *         gdal.GDT_Byte, [stream_nodata], fill_value_list=[stream_nodata],             # <<<<<<<<<<<<<<
 *         gtiff_creation_options=gtiff_creation_options)
 * 
 */
  __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_stream_nodata); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_fill_value_list, __pyx_t_5) < 0) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2670
 *         flow_accum_raster_path_band[0], target_stream_raster_path,
 *         gdal.GDT_Byte, [stream_nodata], fill_value_list=[stream_nodata],
 *         gtiff_creation_options=gtiff_creation_options)             # <<<<<<<<<<<<<<
 * 
 *     cdef _ManagedRaster flow_accum_mr = _ManagedRaster(
 */
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_gtiff_creation_options, __pyx_v_gtiff_creation_options) < 0) __PYX_ERR(0, 2669, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2667
 *     raster_x_size, raster_y_size = flow_accum_info['raster_size']
 * 
 *     pygeoprocessing.new_raster_from_base(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band[0], target_stream_raster_path,
 *         gdal.GDT_Byte, [stream_nodata], fill_value_list=[stream_nodata],
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2673
 * 
 *     cdef _ManagedRaster flow_accum_mr = _ManagedRaster(
 *         flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0)             # <<<<<<<<<<<<<<
 *     cdef _ManagedRaster stream_mr = _ManagedRaster(
 *         target_stream_raster_path, 1, 1)
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2673, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_flow_accum_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2673, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "pygeoprocessing/routing/routing.pyx":2672
 *         gtiff_creation_options=gtiff_creation_options)
 * 
 *     cdef _ManagedRaster flow_accum_mr = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0)
 *     cdef _ManagedRaster stream_mr = _ManagedRaster(
 */
  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2672, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_int_0);
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2672, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_flow_accum_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2674
 *     cdef _ManagedRaster flow_accum_mr = _ManagedRaster(
 *         flow_accum_raster_path_band[0], flow_accum_raster_path_band[1], 0)
 *     cdef _ManagedRaster stream_mr = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         target_stream_raster_path, 1, 1)
 *     cdef _ManagedRaster flow_dir_mfd_mr = _ManagedRaster(
 */
  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_v_target_stream_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_stream_raster_path);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_target_stream_raster_path);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_int_1);
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_int_1);
  __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_stream_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2677
 *         target_stream_raster_path, 1, 1)
 *     cdef _ManagedRaster flow_dir_mfd_mr = _ManagedRaster(
 *         flow_dir_mfd_path_band[0], flow_dir_mfd_path_band[1], 0)             # <<<<<<<<<<<<<<
 * 
 *     cdef int xoff, yoff, win_xsize, win_ysize
 */
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "pygeoprocessing/routing/routing.pyx":2676
 *     cdef _ManagedRaster stream_mr = _ManagedRaster(
 *         target_stream_raster_path, 1, 1)
 *     cdef _ManagedRaster flow_dir_mfd_mr = _ManagedRaster(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_path_band[0], flow_dir_mfd_path_band[1], 0)
 * 
 */
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2676, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_int_0);
  __pyx_t_7 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster), __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2676, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_flow_dir_mfd_mr = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2684
 *     cdef double flow_accum
 *     cdef double trace_flow_threshold = (
 *         trace_threshold_proportion * flow_threshold)             # <<<<<<<<<<<<<<
 *     cdef int n_iterations = 0
 *     cdef int is_outlet, stream_val
 */
  __pyx_v_trace_flow_threshold = (__pyx_v_trace_threshold_proportion * __pyx_v_flow_threshold);

  /* "pygeoprocessing/routing/routing.pyx":2685
 *     cdef double trace_flow_threshold = (
 *         trace_threshold_proportion * flow_threshold)
 *     cdef int n_iterations = 0             # <<<<<<<<<<<<<<
 *     cdef int is_outlet, stream_val
 * 
 */
  __pyx_v_n_iterations = 0;

  /* "pygeoprocessing/routing/routing.pyx":2688
 *     cdef int is_outlet, stream_val
 * 
 *     cdef int flow_dir_nodata = pygeoprocessing.get_raster_info(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_path_band[0])['nodata'][flow_dir_mfd_path_band[1]-1]
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2688, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get_raster_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2688, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2689
 * 
 *     cdef int flow_dir_nodata = pygeoprocessing.get_raster_info(
 *         flow_dir_mfd_path_band[0])['nodata'][flow_dir_mfd_path_band[1]-1]             # <<<<<<<<<<<<<<
 * 
 *     # this queue is used to march the front from the stream pixel or the
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2688, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_6);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_5};
      __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2688, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_5};
      __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2688, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2688, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2688, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_t_6, __pyx_n_s_nodata); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_flow_dir_mfd_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_t_6, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2689, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_flow_dir_nodata = __pyx_t_11;

  /* "pygeoprocessing/routing/routing.pyx":2696
 *     cdef int xi_bn, yi_bn # used for backtrace neighbor coordinates
 * 
 *     cdef time_t last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 * 
 *     for block_offsets in pygeoprocessing.iterblocks(
 */
  __pyx_v_last_log_time = time(NULL);

  /* "pygeoprocessing/routing/routing.pyx":2698
 *     cdef time_t last_log_time = ctime(NULL)
 * 
 *     for block_offsets in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             target_stream_raster_path, offset_only=True):
 *         xoff = block_offsets['xoff']
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2699
 * 
 *     for block_offsets in pygeoprocessing.iterblocks(
 *             target_stream_raster_path, offset_only=True):             # <<<<<<<<<<<<<<
 *         xoff = block_offsets['xoff']
 *         yoff = block_offsets['yoff']
 */
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_v_target_stream_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_stream_raster_path);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_target_stream_raster_path);
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2699, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2698
 *     cdef time_t last_log_time = ctime(NULL)
 * 
 *     for block_offsets in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             target_stream_raster_path, offset_only=True):
 *         xoff = block_offsets['xoff']
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
    __pyx_t_7 = __pyx_t_5; __Pyx_INCREF(__pyx_t_7); __pyx_t_12 = 0;
    __pyx_t_13 = NULL;
  } else {
    __pyx_t_12 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_13 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2698, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  for (;;) {
    if (likely(!__pyx_t_13)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2698, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_7, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2698, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_7, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2698, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_13(__pyx_t_7);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2698, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2700
 *     for block_offsets in pygeoprocessing.iterblocks(
 *             target_stream_raster_path, offset_only=True):
 *         xoff = block_offsets['xoff']             # <<<<<<<<<<<<<<
 *         yoff = block_offsets['yoff']
 *         win_xsize = block_offsets['win_xsize']
 */
    __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_s_xoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2700, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2700, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_xoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":2701
 *             target_stream_raster_path, offset_only=True):
 *         xoff = block_offsets['xoff']
 *         yoff = block_offsets['yoff']             # <<<<<<<<<<<<<<
 *         win_xsize = block_offsets['win_xsize']
 *         win_ysize = block_offsets['win_ysize']
 */
    __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_s_yoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2701, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2701, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_yoff = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":2702
 *         xoff = block_offsets['xoff']
 *         yoff = block_offsets['yoff']
 *         win_xsize = block_offsets['win_xsize']             # <<<<<<<<<<<<<<
 *         win_ysize = block_offsets['win_ysize']
 *         for yi in range(win_ysize):
 */
    __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_s_win_xsize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2702, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2702, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_win_xsize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":2703
 *         yoff = block_offsets['yoff']
 *         win_xsize = block_offsets['win_xsize']
 *         win_ysize = block_offsets['win_ysize']             # <<<<<<<<<<<<<<
 *         for yi in range(win_ysize):
 *             yi_root = yi+yoff
 */
    __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_s_win_ysize); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2703, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2703, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_win_ysize = __pyx_t_11;

    /* "pygeoprocessing/routing/routing.pyx":2704
 *         win_xsize = block_offsets['win_xsize']
 *         win_ysize = block_offsets['win_ysize']
 *         for yi in range(win_ysize):             # <<<<<<<<<<<<<<
 *             yi_root = yi+yoff
 *             if ctime(NULL) - last_log_time > 5.0:
 */
    __pyx_t_11 = __pyx_v_win_ysize;
    __pyx_t_10 = __pyx_t_11;
    for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_10; __pyx_t_14+=1) {
      __pyx_v_yi = __pyx_t_14;

      /* "pygeoprocessing/routing/routing.pyx":2705
 *         win_ysize = block_offsets['win_ysize']
 *         for yi in range(win_ysize):
 *             yi_root = yi+yoff             # <<<<<<<<<<<<<<
 *             if ctime(NULL) - last_log_time > 5.0:
 *                 last_log_time = ctime(NULL)
 */
      __pyx_v_yi_root = (__pyx_v_yi + __pyx_v_yoff);

      /* "pygeoprocessing/routing/routing.pyx":2706
 *         for yi in range(win_ysize):
 *             yi_root = yi+yoff
 *             if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *                 last_log_time = ctime(NULL)
 *                 current_pixel = xoff + yoff * raster_x_size
 */
      __pyx_t_1 = (((time(NULL) - __pyx_v_last_log_time) > 5.0) != 0);
      if (__pyx_t_1) {

        /* "pygeoprocessing/routing/routing.pyx":2707
 *             yi_root = yi+yoff
 *             if ctime(NULL) - last_log_time > 5.0:
 *                 last_log_time = ctime(NULL)             # <<<<<<<<<<<<<<
 *                 current_pixel = xoff + yoff * raster_x_size
 *                 LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 */
        __pyx_v_last_log_time = time(NULL);

        /* "pygeoprocessing/routing/routing.pyx":2708
 *             if ctime(NULL) - last_log_time > 5.0:
 *                 last_log_time = ctime(NULL)
 *                 current_pixel = xoff + yoff * raster_x_size             # <<<<<<<<<<<<<<
 *                 LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                     raster_x_size * raster_y_size))
 */
        __pyx_t_5 = __Pyx_PyInt_From_int((__pyx_v_xoff + (__pyx_v_yoff * __pyx_v_raster_x_size))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2708, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_XDECREF_SET(__pyx_v_current_pixel, __pyx_t_5);
        __pyx_t_5 = 0;

        /* "pygeoprocessing/routing/routing.pyx":2709
 *                 last_log_time = ctime(NULL)
 *                 current_pixel = xoff + yoff * raster_x_size
 *                 LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                     raster_x_size * raster_y_size))
 *             for xi in range(win_xsize):
 */
        __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2709, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2709, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = PyNumber_Multiply(__pyx_float_100_0, __pyx_v_current_pixel); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2709, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);

        /* "pygeoprocessing/routing/routing.pyx":2710
 *                 current_pixel = xoff + yoff * raster_x_size
 *                 LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                     raster_x_size * raster_y_size))             # <<<<<<<<<<<<<<
 *             for xi in range(win_xsize):
 *                 xi_root = xi+xoff
 */
        __pyx_t_3 = PyFloat_FromDouble(((float)(__pyx_v_raster_x_size * __pyx_v_raster_y_size))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2709, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);

        /* "pygeoprocessing/routing/routing.pyx":2709
 *                 last_log_time = ctime(NULL)
 *                 current_pixel = xoff + yoff * raster_x_size
 *                 LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(             # <<<<<<<<<<<<<<
 *                     raster_x_size * raster_y_size))
 *             for xi in range(win_xsize):
 */
        __pyx_t_15 = __Pyx_PyNumber_Divide(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2709, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = NULL;
        __pyx_t_16 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
            __pyx_t_16 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_15};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2709, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s_1f_complete, __pyx_t_15};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2709, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2709, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          if (__pyx_t_3) {
            __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
          }
          __Pyx_INCREF(__pyx_kp_s_1f_complete);
          __Pyx_GIVEREF(__pyx_kp_s_1f_complete);
          PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_16, __pyx_kp_s_1f_complete);
          __Pyx_GIVEREF(__pyx_t_15);
          PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_16, __pyx_t_15);
          __pyx_t_15 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2709, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "pygeoprocessing/routing/routing.pyx":2706
 *         for yi in range(win_ysize):
 *             yi_root = yi+yoff
 *             if ctime(NULL) - last_log_time > 5.0:             # <<<<<<<<<<<<<<
 *                 last_log_time = ctime(NULL)
 *                 current_pixel = xoff + yoff * raster_x_size
 */
      }

      /* "pygeoprocessing/routing/routing.pyx":2711
 *                 LOGGER.info('%.1f%% complete', 100.0 * current_pixel / <float>(
 *                     raster_x_size * raster_y_size))
 *             for xi in range(win_xsize):             # <<<<<<<<<<<<<<
 *                 xi_root = xi+xoff
 *                 flow_accum = flow_accum_mr.get(xi_root, yi_root)
 */
      __pyx_t_16 = __pyx_v_win_xsize;
      __pyx_t_17 = __pyx_t_16;
      for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
        __pyx_v_xi = __pyx_t_18;

        /* "pygeoprocessing/routing/routing.pyx":2712
 *                     raster_x_size * raster_y_size))
 *             for xi in range(win_xsize):
 *                 xi_root = xi+xoff             # <<<<<<<<<<<<<<
 *                 flow_accum = flow_accum_mr.get(xi_root, yi_root)
 *                 if is_close(flow_accum, flow_accum_nodata):
 */
        __pyx_v_xi_root = (__pyx_v_xi + __pyx_v_xoff);

        /* "pygeoprocessing/routing/routing.pyx":2713
 *             for xi in range(win_xsize):
 *                 xi_root = xi+xoff
 *                 flow_accum = flow_accum_mr.get(xi_root, yi_root)             # <<<<<<<<<<<<<<
 *                 if is_close(flow_accum, flow_accum_nodata):
 *                     continue
 */
        __pyx_v_flow_accum = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_mr, __pyx_v_xi_root, __pyx_v_yi_root);

        /* "pygeoprocessing/routing/routing.pyx":2714
 *                 xi_root = xi+xoff
 *                 flow_accum = flow_accum_mr.get(xi_root, yi_root)
 *                 if is_close(flow_accum, flow_accum_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 *                 if stream_mr.get(xi_root, yi_root) != stream_nodata:
 */
        __pyx_t_1 = (__pyx_f_15pygeoprocessing_7routing_7routing_is_close(__pyx_v_flow_accum, __pyx_v_flow_accum_nodata) != 0);
        if (__pyx_t_1) {

          /* "pygeoprocessing/routing/routing.pyx":2715
 *                 flow_accum = flow_accum_mr.get(xi_root, yi_root)
 *                 if is_close(flow_accum, flow_accum_nodata):
 *                     continue             # <<<<<<<<<<<<<<
 *                 if stream_mr.get(xi_root, yi_root) != stream_nodata:
 *                     continue
 */
          goto __pyx_L13_continue;

          /* "pygeoprocessing/routing/routing.pyx":2714
 *                 xi_root = xi+xoff
 *                 flow_accum = flow_accum_mr.get(xi_root, yi_root)
 *                 if is_close(flow_accum, flow_accum_nodata):             # <<<<<<<<<<<<<<
 *                     continue
 *                 if stream_mr.get(xi_root, yi_root) != stream_nodata:
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2716
 *                 if is_close(flow_accum, flow_accum_nodata):
 *                     continue
 *                 if stream_mr.get(xi_root, yi_root) != stream_nodata:             # <<<<<<<<<<<<<<
 *                     continue
 *                 stream_mr.set(xi_root, yi_root, 0)
 */
        __pyx_t_1 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_stream_mr, __pyx_v_xi_root, __pyx_v_yi_root) != __pyx_v_stream_nodata) != 0);
        if (__pyx_t_1) {

          /* "pygeoprocessing/routing/routing.pyx":2717
 *                     continue
 *                 if stream_mr.get(xi_root, yi_root) != stream_nodata:
 *                     continue             # <<<<<<<<<<<<<<
 *                 stream_mr.set(xi_root, yi_root, 0)
 *                 if flow_accum < flow_threshold:
 */
          goto __pyx_L13_continue;

          /* "pygeoprocessing/routing/routing.pyx":2716
 *                 if is_close(flow_accum, flow_accum_nodata):
 *                     continue
 *                 if stream_mr.get(xi_root, yi_root) != stream_nodata:             # <<<<<<<<<<<<<<
 *                     continue
 *                 stream_mr.set(xi_root, yi_root, 0)
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2718
 *                 if stream_mr.get(xi_root, yi_root) != stream_nodata:
 *                     continue
 *                 stream_mr.set(xi_root, yi_root, 0)             # <<<<<<<<<<<<<<
 *                 if flow_accum < flow_threshold:
 *                     continue
 */
        __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_stream_mr, __pyx_v_xi_root, __pyx_v_yi_root, 0.0);

        /* "pygeoprocessing/routing/routing.pyx":2719
 *                     continue
 *                 stream_mr.set(xi_root, yi_root, 0)
 *                 if flow_accum < flow_threshold:             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        __pyx_t_1 = ((__pyx_v_flow_accum < __pyx_v_flow_threshold) != 0);
        if (__pyx_t_1) {

          /* "pygeoprocessing/routing/routing.pyx":2720
 *                 stream_mr.set(xi_root, yi_root, 0)
 *                 if flow_accum < flow_threshold:
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *                 flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_root, yi_root)
 */
          goto __pyx_L13_continue;

          /* "pygeoprocessing/routing/routing.pyx":2719
 *                     continue
 *                 stream_mr.set(xi_root, yi_root, 0)
 *                 if flow_accum < flow_threshold:             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2722
 *                     continue
 * 
 *                 flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_root, yi_root)             # <<<<<<<<<<<<<<
 *                 is_outlet = 0
 *                 for i_n in range(8):
 */
        __pyx_v_flow_dir_mfd = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_mfd_mr, __pyx_v_xi_root, __pyx_v_yi_root));

        /* "pygeoprocessing/routing/routing.pyx":2723
 * 
 *                 flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_root, yi_root)
 *                 is_outlet = 0             # <<<<<<<<<<<<<<
 *                 for i_n in range(8):
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:
 */
        __pyx_v_is_outlet = 0;

        /* "pygeoprocessing/routing/routing.pyx":2724
 *                 flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_root, yi_root)
 *                 is_outlet = 0
 *                 for i_n in range(8):             # <<<<<<<<<<<<<<
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:
 *                         # no flow in that direction
 */
        for (__pyx_t_19 = 0; __pyx_t_19 < 8; __pyx_t_19+=1) {
          __pyx_v_i_n = __pyx_t_19;

          /* "pygeoprocessing/routing/routing.pyx":2725
 *                 is_outlet = 0
 *                 for i_n in range(8):
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:             # <<<<<<<<<<<<<<
 *                         # no flow in that direction
 *                         continue
 */
          __pyx_t_1 = ((((__pyx_v_flow_dir_mfd >> (__pyx_v_i_n * 4)) & 0xF) == 0) != 0);
          if (__pyx_t_1) {

            /* "pygeoprocessing/routing/routing.pyx":2727
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:
 *                         # no flow in that direction
 *                         continue             # <<<<<<<<<<<<<<
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 */
            goto __pyx_L18_continue;

            /* "pygeoprocessing/routing/routing.pyx":2725
 *                 is_outlet = 0
 *                 for i_n in range(8):
 *                     if ((flow_dir_mfd >> (i_n * 4)) & 0xF) == 0:             # <<<<<<<<<<<<<<
 *                         # no flow in that direction
 *                         continue
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":2728
 *                         # no flow in that direction
 *                         continue
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]             # <<<<<<<<<<<<<<
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or
 */
          __pyx_v_xi_n = (__pyx_v_xi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_n)]));

          /* "pygeoprocessing/routing/routing.pyx":2729
 *                         continue
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]             # <<<<<<<<<<<<<<
 *                     if (xi_n < 0 or xi_n >= raster_x_size or
 *                             yi_n < 0 or yi_n >= raster_y_size):
 */
          __pyx_v_yi_n = (__pyx_v_yi_root + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_n) + 1)]));

          /* "pygeoprocessing/routing/routing.pyx":2730
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 */
          __pyx_t_2 = ((__pyx_v_xi_n < 0) != 0);
          if (!__pyx_t_2) {
          } else {
            __pyx_t_1 = __pyx_t_2;
            goto __pyx_L22_bool_binop_done;
          }
          __pyx_t_2 = ((__pyx_v_xi_n >= __pyx_v_raster_x_size) != 0);
          if (!__pyx_t_2) {
          } else {
            __pyx_t_1 = __pyx_t_2;
            goto __pyx_L22_bool_binop_done;
          }

          /* "pygeoprocessing/routing/routing.pyx":2731
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or
 *                             yi_n < 0 or yi_n >= raster_y_size):             # <<<<<<<<<<<<<<
 *                         # it'll drain off the edge of the raster
 *                         is_outlet = 1
 */
          __pyx_t_2 = ((__pyx_v_yi_n < 0) != 0);
          if (!__pyx_t_2) {
          } else {
            __pyx_t_1 = __pyx_t_2;
            goto __pyx_L22_bool_binop_done;
          }
          __pyx_t_2 = ((__pyx_v_yi_n >= __pyx_v_raster_y_size) != 0);
          __pyx_t_1 = __pyx_t_2;
          __pyx_L22_bool_binop_done:;

          /* "pygeoprocessing/routing/routing.pyx":2730
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 */
          if (__pyx_t_1) {

            /* "pygeoprocessing/routing/routing.pyx":2733
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 *                         is_outlet = 1             # <<<<<<<<<<<<<<
 *                         break
 *                     if flow_accum_mr.get(xi_n, yi_n) == flow_accum_nodata:
 */
            __pyx_v_is_outlet = 1;

            /* "pygeoprocessing/routing/routing.pyx":2734
 *                         # it'll drain off the edge of the raster
 *                         is_outlet = 1
 *                         break             # <<<<<<<<<<<<<<
 *                     if flow_accum_mr.get(xi_n, yi_n) == flow_accum_nodata:
 *                         is_outlet = 1
 */
            goto __pyx_L19_break;

            /* "pygeoprocessing/routing/routing.pyx":2730
 *                     xi_n = xi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n]
 *                     yi_n = yi_root+NEIGHBOR_OFFSET_ARRAY[2*i_n+1]
 *                     if (xi_n < 0 or xi_n >= raster_x_size or             # <<<<<<<<<<<<<<
 *                             yi_n < 0 or yi_n >= raster_y_size):
 *                         # it'll drain off the edge of the raster
 */
          }

          /* "pygeoprocessing/routing/routing.pyx":2735
 *                         is_outlet = 1
 *                         break
 *                     if flow_accum_mr.get(xi_n, yi_n) == flow_accum_nodata:             # <<<<<<<<<<<<<<
 *                         is_outlet = 1
 *                         break
 */
          __pyx_t_1 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_mr, __pyx_v_xi_n, __pyx_v_yi_n) == __pyx_v_flow_accum_nodata) != 0);
          if (__pyx_t_1) {

            /* "pygeoprocessing/routing/routing.pyx":2736
 *                         break
 *                     if flow_accum_mr.get(xi_n, yi_n) == flow_accum_nodata:
 *                         is_outlet = 1             # <<<<<<<<<<<<<<
 *                         break
 *                 if is_outlet:
 */
            __pyx_v_is_outlet = 1;

            /* "pygeoprocessing/routing/routing.pyx":2737
 *                     if flow_accum_mr.get(xi_n, yi_n) == flow_accum_nodata:
 *                         is_outlet = 1
 *                         break             # <<<<<<<<<<<<<<
 *                 if is_outlet:
 *                     open_set.push(CoordinateType(xi_root, yi_root))
 */
            goto __pyx_L19_break;

            /* "pygeoprocessing/routing/routing.pyx":2735
 *                         is_outlet = 1
 *                         break
 *                     if flow_accum_mr.get(xi_n, yi_n) == flow_accum_nodata:             # <<<<<<<<<<<<<<
 *                         is_outlet = 1
 *                         break
 */
          }
          __pyx_L18_continue:;
        }
        __pyx_L19_break:;

        /* "pygeoprocessing/routing/routing.pyx":2738
 *                         is_outlet = 1
 *                         break
 *                 if is_outlet:             # <<<<<<<<<<<<<<
 *                     open_set.push(CoordinateType(xi_root, yi_root))
 *                     stream_mr.set(xi_root, yi_root, 1)
 */
        __pyx_t_1 = (__pyx_v_is_outlet != 0);
        if (__pyx_t_1) {

          /* "pygeoprocessing/routing/routing.pyx":2739
 *                         break
 *                 if is_outlet:
 *                     open_set.push(CoordinateType(xi_root, yi_root))             # <<<<<<<<<<<<<<
 *                     stream_mr.set(xi_root, yi_root, 1)
 * 
 */
          __pyx_t_20.xi = __pyx_v_xi_root;
          __pyx_t_20.yi = __pyx_v_yi_root;
          __pyx_v_open_set.push(__pyx_t_20);

          /* "pygeoprocessing/routing/routing.pyx":2740
 *                 if is_outlet:
 *                     open_set.push(CoordinateType(xi_root, yi_root))
 *                     stream_mr.set(xi_root, yi_root, 1)             # <<<<<<<<<<<<<<
 * 
 *                 n_iterations = 0
 */
          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_stream_mr, __pyx_v_xi_root, __pyx_v_yi_root, 1.0);

          /* "pygeoprocessing/routing/routing.pyx":2738
 *                         is_outlet = 1
 *                         break
 *                 if is_outlet:             # <<<<<<<<<<<<<<
 *                     open_set.push(CoordinateType(xi_root, yi_root))
 *                     stream_mr.set(xi_root, yi_root, 1)
 */
        }

        /* "pygeoprocessing/routing/routing.pyx":2742
 *                     stream_mr.set(xi_root, yi_root, 1)
 * 
 *                 n_iterations = 0             # <<<<<<<<<<<<<<
 *                 while open_set.size() > 0:
 *                     xi_n = open_set.front().xi
 */
        __pyx_v_n_iterations = 0;

        /* "pygeoprocessing/routing/routing.pyx":2743
 * 
 *                 n_iterations = 0
 *                 while open_set.size() > 0:             # <<<<<<<<<<<<<<
 *                     xi_n = open_set.front().xi
 *                     yi_n = open_set.front().yi
 */
        while (1) {
          __pyx_t_1 = ((__pyx_v_open_set.size() > 0) != 0);
          if (!__pyx_t_1) break;

          /* "pygeoprocessing/routing/routing.pyx":2744
 *                 n_iterations = 0
 *                 while open_set.size() > 0:
 *                     xi_n = open_set.front().xi             # <<<<<<<<<<<<<<
 *                     yi_n = open_set.front().yi
 *                     open_set.pop()
 */
          __pyx_t_19 = __pyx_v_open_set.front().xi;
          __pyx_v_xi_n = __pyx_t_19;

          /* "pygeoprocessing/routing/routing.pyx":2745
 *                 while open_set.size() > 0:
 *                     xi_n = open_set.front().xi
 *                     yi_n = open_set.front().yi             # <<<<<<<<<<<<<<
 *                     open_set.pop()
 *                     n_iterations += 1
 */
          __pyx_t_19 = __pyx_v_open_set.front().yi;
          __pyx_v_yi_n = __pyx_t_19;

          /* "pygeoprocessing/routing/routing.pyx":2746
 *                     xi_n = open_set.front().xi
 *                     yi_n = open_set.front().yi
 *                     open_set.pop()             # <<<<<<<<<<<<<<
 *                     n_iterations += 1
 *                     for i_sn in range(8):
 */
          __pyx_v_open_set.pop();

          /* "pygeoprocessing/routing/routing.pyx":2747
 *                     yi_n = open_set.front().yi
 *                     open_set.pop()
 *                     n_iterations += 1             # <<<<<<<<<<<<<<
 *                     for i_sn in range(8):
 *                         xi_sn = xi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 */
          __pyx_v_n_iterations = (__pyx_v_n_iterations + 1);

          /* "pygeoprocessing/routing/routing.pyx":2748
 *                     open_set.pop()
 *                     n_iterations += 1
 *                     for i_sn in range(8):             # <<<<<<<<<<<<<<
 *                         xi_sn = xi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                         yi_sn = yi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 */
          for (__pyx_t_19 = 0; __pyx_t_19 < 8; __pyx_t_19+=1) {
            __pyx_v_i_sn = __pyx_t_19;

            /* "pygeoprocessing/routing/routing.pyx":2749
 *                     n_iterations += 1
 *                     for i_sn in range(8):
 *                         xi_sn = xi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn]             # <<<<<<<<<<<<<<
 *                         yi_sn = yi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                         if (xi_sn < 0 or xi_sn >= raster_x_size or
 */
            __pyx_v_xi_sn = (__pyx_v_xi_n + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_sn)]));

            /* "pygeoprocessing/routing/routing.pyx":2750
 *                     for i_sn in range(8):
 *                         xi_sn = xi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                         yi_sn = yi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]             # <<<<<<<<<<<<<<
 *                         if (xi_sn < 0 or xi_sn >= raster_x_size or
 *                                 yi_sn < 0 or yi_sn >= raster_y_size):
 */
            __pyx_v_yi_sn = (__pyx_v_yi_n + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_sn) + 1)]));

            /* "pygeoprocessing/routing/routing.pyx":2751
 *                         xi_sn = xi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                         yi_sn = yi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                         if (xi_sn < 0 or xi_sn >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_sn < 0 or yi_sn >= raster_y_size):
 *                             continue
 */
            __pyx_t_2 = ((__pyx_v_xi_sn < 0) != 0);
            if (!__pyx_t_2) {
            } else {
              __pyx_t_1 = __pyx_t_2;
              goto __pyx_L33_bool_binop_done;
            }
            __pyx_t_2 = ((__pyx_v_xi_sn >= __pyx_v_raster_x_size) != 0);
            if (!__pyx_t_2) {
            } else {
              __pyx_t_1 = __pyx_t_2;
              goto __pyx_L33_bool_binop_done;
            }

            /* "pygeoprocessing/routing/routing.pyx":2752
 *                         yi_sn = yi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                         if (xi_sn < 0 or xi_sn >= raster_x_size or
 *                                 yi_sn < 0 or yi_sn >= raster_y_size):             # <<<<<<<<<<<<<<
 *                             continue
 *                         flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_sn, yi_sn)
 */
            __pyx_t_2 = ((__pyx_v_yi_sn < 0) != 0);
            if (!__pyx_t_2) {
            } else {
              __pyx_t_1 = __pyx_t_2;
              goto __pyx_L33_bool_binop_done;
            }
            __pyx_t_2 = ((__pyx_v_yi_sn >= __pyx_v_raster_y_size) != 0);
            __pyx_t_1 = __pyx_t_2;
            __pyx_L33_bool_binop_done:;

            /* "pygeoprocessing/routing/routing.pyx":2751
 *                         xi_sn = xi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                         yi_sn = yi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                         if (xi_sn < 0 or xi_sn >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_sn < 0 or yi_sn >= raster_y_size):
 *                             continue
 */
            if (__pyx_t_1) {

              /* "pygeoprocessing/routing/routing.pyx":2753
 *                         if (xi_sn < 0 or xi_sn >= raster_x_size or
 *                                 yi_sn < 0 or yi_sn >= raster_y_size):
 *                             continue             # <<<<<<<<<<<<<<
 *                         flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_sn, yi_sn)
 *                         if flow_dir_mfd == flow_dir_nodata:
 */
              goto __pyx_L30_continue;

              /* "pygeoprocessing/routing/routing.pyx":2751
 *                         xi_sn = xi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                         yi_sn = yi_n+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                         if (xi_sn < 0 or xi_sn >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                 yi_sn < 0 or yi_sn >= raster_y_size):
 *                             continue
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2754
 *                                 yi_sn < 0 or yi_sn >= raster_y_size):
 *                             continue
 *                         flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_sn, yi_sn)             # <<<<<<<<<<<<<<
 *                         if flow_dir_mfd == flow_dir_nodata:
 *                             continue
 */
            __pyx_v_flow_dir_mfd = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_mfd_mr, __pyx_v_xi_sn, __pyx_v_yi_sn));

            /* "pygeoprocessing/routing/routing.pyx":2755
 *                             continue
 *                         flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_sn, yi_sn)
 *                         if flow_dir_mfd == flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if ((flow_dir_mfd >>
 */
            __pyx_t_1 = ((__pyx_v_flow_dir_mfd == __pyx_v_flow_dir_nodata) != 0);
            if (__pyx_t_1) {

              /* "pygeoprocessing/routing/routing.pyx":2756
 *                         flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_sn, yi_sn)
 *                         if flow_dir_mfd == flow_dir_nodata:
 *                             continue             # <<<<<<<<<<<<<<
 *                         if ((flow_dir_mfd >>
 *                                 (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0:
 */
              goto __pyx_L30_continue;

              /* "pygeoprocessing/routing/routing.pyx":2755
 *                             continue
 *                         flow_dir_mfd = <int>flow_dir_mfd_mr.get(xi_sn, yi_sn)
 *                         if flow_dir_mfd == flow_dir_nodata:             # <<<<<<<<<<<<<<
 *                             continue
 *                         if ((flow_dir_mfd >>
 */
            }

            /* "pygeoprocessing/routing/routing.pyx":2758
 *                             continue
 *                         if ((flow_dir_mfd >>
 *                                 (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0:             # <<<<<<<<<<<<<<
 *                             # upstream pixel flows into this one
 *                             stream_val = <int>stream_mr.get(xi_sn, yi_sn)
 */
            __pyx_t_1 = ((((__pyx_v_flow_dir_mfd >> ((__pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION[__pyx_v_i_sn]) * 4)) & 0xF) > 0) != 0);

            /* "pygeoprocessing/routing/routing.pyx":2757
 *                         if flow_dir_mfd == flow_dir_nodata:
 *                             continue
 *                         if ((flow_dir_mfd >>             # <<<<<<<<<<<<<<
 *                                 (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0:
 *                             # upstream pixel flows into this one
 */
            if (__pyx_t_1) {

              /* "pygeoprocessing/routing/routing.pyx":2760
 *                                 (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0:
 *                             # upstream pixel flows into this one
 *                             stream_val = <int>stream_mr.get(xi_sn, yi_sn)             # <<<<<<<<<<<<<<
 *                             if stream_val != 1 and stream_val != 2:
 *                                 flow_accum = flow_accum_mr.get(
 */
              __pyx_v_stream_val = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_stream_mr, __pyx_v_xi_sn, __pyx_v_yi_sn));

              /* "pygeoprocessing/routing/routing.pyx":2761
 *                             # upstream pixel flows into this one
 *                             stream_val = <int>stream_mr.get(xi_sn, yi_sn)
 *                             if stream_val != 1 and stream_val != 2:             # <<<<<<<<<<<<<<
 *                                 flow_accum = flow_accum_mr.get(
 *                                     xi_sn, yi_sn)
 */
              switch (__pyx_v_stream_val) {
                case 1:
                case 2:
                __pyx_t_1 = 0;
                break;
                default:
                __pyx_t_1 = 1;
                break;
              }
              if (__pyx_t_1) {

                /* "pygeoprocessing/routing/routing.pyx":2762
 *                             stream_val = <int>stream_mr.get(xi_sn, yi_sn)
 *                             if stream_val != 1 and stream_val != 2:
 *                                 flow_accum = flow_accum_mr.get(             # <<<<<<<<<<<<<<
 *                                     xi_sn, yi_sn)
 *                                 if flow_accum >= flow_threshold:
 */
                __pyx_v_flow_accum = __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_accum_mr, __pyx_v_xi_sn, __pyx_v_yi_sn);

                /* "pygeoprocessing/routing/routing.pyx":2764
 *                                 flow_accum = flow_accum_mr.get(
 *                                     xi_sn, yi_sn)
 *                                 if flow_accum >= flow_threshold:             # <<<<<<<<<<<<<<
 *                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                     open_set.push(
 */
                __pyx_t_1 = ((__pyx_v_flow_accum >= __pyx_v_flow_threshold) != 0);
                if (__pyx_t_1) {

                  /* "pygeoprocessing/routing/routing.pyx":2765
 *                                     xi_sn, yi_sn)
 *                                 if flow_accum >= flow_threshold:
 *                                     stream_mr.set(xi_sn, yi_sn, 1)             # <<<<<<<<<<<<<<
 *                                     open_set.push(
 *                                         CoordinateType(xi_sn, yi_sn))
 */
                  __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_stream_mr, __pyx_v_xi_sn, __pyx_v_yi_sn, 1.0);

                  /* "pygeoprocessing/routing/routing.pyx":2767
 *                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                     open_set.push(
 *                                         CoordinateType(xi_sn, yi_sn))             # <<<<<<<<<<<<<<
 *                                     # see if we're in a potential stream and
 *                                     # found a connection
 */
                  __pyx_t_20.xi = __pyx_v_xi_sn;
                  __pyx_t_20.yi = __pyx_v_yi_sn;

                  /* "pygeoprocessing/routing/routing.pyx":2766
 *                                 if flow_accum >= flow_threshold:
 *                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                     open_set.push(             # <<<<<<<<<<<<<<
 *                                         CoordinateType(xi_sn, yi_sn))
 *                                     # see if we're in a potential stream and
 */
                  __pyx_v_open_set.push(__pyx_t_20);

                  /* "pygeoprocessing/routing/routing.pyx":2771
 *                                     # found a connection
 *                                     backtrace_set.push(
 *                                         CoordinateType(xi_sn, yi_sn))             # <<<<<<<<<<<<<<
 *                                     while backtrace_set.size() > 0:
 *                                         xi_bn = backtrace_set.front().xi
 */
                  __pyx_t_20.xi = __pyx_v_xi_sn;
                  __pyx_t_20.yi = __pyx_v_yi_sn;

                  /* "pygeoprocessing/routing/routing.pyx":2770
 *                                     # see if we're in a potential stream and
 *                                     # found a connection
 *                                     backtrace_set.push(             # <<<<<<<<<<<<<<
 *                                         CoordinateType(xi_sn, yi_sn))
 *                                     while backtrace_set.size() > 0:
 */
                  __pyx_v_backtrace_set.push(__pyx_t_20);

                  /* "pygeoprocessing/routing/routing.pyx":2772
 *                                     backtrace_set.push(
 *                                         CoordinateType(xi_sn, yi_sn))
 *                                     while backtrace_set.size() > 0:             # <<<<<<<<<<<<<<
 *                                         xi_bn = backtrace_set.front().xi
 *                                         yi_bn = backtrace_set.front().yi
 */
                  while (1) {
                    __pyx_t_1 = ((__pyx_v_backtrace_set.size() > 0) != 0);
                    if (!__pyx_t_1) break;

                    /* "pygeoprocessing/routing/routing.pyx":2773
 *                                         CoordinateType(xi_sn, yi_sn))
 *                                     while backtrace_set.size() > 0:
 *                                         xi_bn = backtrace_set.front().xi             # <<<<<<<<<<<<<<
 *                                         yi_bn = backtrace_set.front().yi
 *                                         backtrace_set.pop()
 */
                    __pyx_t_21 = __pyx_v_backtrace_set.front().xi;
                    __pyx_v_xi_bn = __pyx_t_21;

                    /* "pygeoprocessing/routing/routing.pyx":2774
 *                                     while backtrace_set.size() > 0:
 *                                         xi_bn = backtrace_set.front().xi
 *                                         yi_bn = backtrace_set.front().yi             # <<<<<<<<<<<<<<
 *                                         backtrace_set.pop()
 *                                         flow_dir_mfd = <int>(
 */
                    __pyx_t_21 = __pyx_v_backtrace_set.front().yi;
                    __pyx_v_yi_bn = __pyx_t_21;

                    /* "pygeoprocessing/routing/routing.pyx":2775
 *                                         xi_bn = backtrace_set.front().xi
 *                                         yi_bn = backtrace_set.front().yi
 *                                         backtrace_set.pop()             # <<<<<<<<<<<<<<
 *                                         flow_dir_mfd = <int>(
 *                                             flow_dir_mfd_mr.get(xi_bn, yi_bn))
 */
                    __pyx_v_backtrace_set.pop();

                    /* "pygeoprocessing/routing/routing.pyx":2776
 *                                         yi_bn = backtrace_set.front().yi
 *                                         backtrace_set.pop()
 *                                         flow_dir_mfd = <int>(             # <<<<<<<<<<<<<<
 *                                             flow_dir_mfd_mr.get(xi_bn, yi_bn))
 *                                         for i_sn in range(8):
 */
                    __pyx_v_flow_dir_mfd = ((int)__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_flow_dir_mfd_mr, __pyx_v_xi_bn, __pyx_v_yi_bn));

                    /* "pygeoprocessing/routing/routing.pyx":2778
 *                                         flow_dir_mfd = <int>(
 *                                             flow_dir_mfd_mr.get(xi_bn, yi_bn))
 *                                         for i_sn in range(8):             # <<<<<<<<<<<<<<
 *                                             if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0:
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 */
                    for (__pyx_t_21 = 0; __pyx_t_21 < 8; __pyx_t_21+=1) {
                      __pyx_v_i_sn = __pyx_t_21;

                      /* "pygeoprocessing/routing/routing.pyx":2779
 *                                             flow_dir_mfd_mr.get(xi_bn, yi_bn))
 *                                         for i_sn in range(8):
 *                                             if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0:             # <<<<<<<<<<<<<<
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 */
                      __pyx_t_1 = ((((__pyx_v_flow_dir_mfd >> (__pyx_v_i_sn * 4)) & 0xF) > 0) != 0);
                      if (__pyx_t_1) {

                        /* "pygeoprocessing/routing/routing.pyx":2780
 *                                         for i_sn in range(8):
 *                                             if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0:
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]             # <<<<<<<<<<<<<<
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                                                 if (xi_sn < 0 or xi_sn >= raster_x_size or
 */
                        __pyx_v_xi_sn = (__pyx_v_xi_bn + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[(2 * __pyx_v_i_sn)]));

                        /* "pygeoprocessing/routing/routing.pyx":2781
 *                                             if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0:
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]             # <<<<<<<<<<<<<<
 *                                                 if (xi_sn < 0 or xi_sn >= raster_x_size or
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):
 */
                        __pyx_v_yi_sn = (__pyx_v_yi_bn + (__pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY[((2 * __pyx_v_i_sn) + 1)]));

                        /* "pygeoprocessing/routing/routing.pyx":2782
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                                                 if (xi_sn < 0 or xi_sn >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):
 *                                                     continue
 */
                        __pyx_t_2 = ((__pyx_v_xi_sn < 0) != 0);
                        if (!__pyx_t_2) {
                        } else {
                          __pyx_t_1 = __pyx_t_2;
                          goto __pyx_L47_bool_binop_done;
                        }
                        __pyx_t_2 = ((__pyx_v_xi_sn >= __pyx_v_raster_x_size) != 0);
                        if (!__pyx_t_2) {
                        } else {
                          __pyx_t_1 = __pyx_t_2;
                          goto __pyx_L47_bool_binop_done;
                        }

                        /* "pygeoprocessing/routing/routing.pyx":2783
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                                                 if (xi_sn < 0 or xi_sn >= raster_x_size or
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):             # <<<<<<<<<<<<<<
 *                                                     continue
 *                                                 if stream_mr.get(xi_sn, yi_sn) == 2:
 */
                        __pyx_t_2 = ((__pyx_v_yi_sn < 0) != 0);
                        if (!__pyx_t_2) {
                        } else {
                          __pyx_t_1 = __pyx_t_2;
                          goto __pyx_L47_bool_binop_done;
                        }
                        __pyx_t_2 = ((__pyx_v_yi_sn >= __pyx_v_raster_y_size) != 0);
                        __pyx_t_1 = __pyx_t_2;
                        __pyx_L47_bool_binop_done:;

                        /* "pygeoprocessing/routing/routing.pyx":2782
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                                                 if (xi_sn < 0 or xi_sn >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):
 *                                                     continue
 */
                        if (__pyx_t_1) {

                          /* "pygeoprocessing/routing/routing.pyx":2784
 *                                                 if (xi_sn < 0 or xi_sn >= raster_x_size or
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):
 *                                                     continue             # <<<<<<<<<<<<<<
 *                                                 if stream_mr.get(xi_sn, yi_sn) == 2:
 *                                                     stream_mr.set(xi_sn, yi_sn, 1)
 */
                          goto __pyx_L43_continue;

                          /* "pygeoprocessing/routing/routing.pyx":2782
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 *                                                 if (xi_sn < 0 or xi_sn >= raster_x_size or             # <<<<<<<<<<<<<<
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):
 *                                                     continue
 */
                        }

                        /* "pygeoprocessing/routing/routing.pyx":2785
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):
 *                                                     continue
 *                                                 if stream_mr.get(xi_sn, yi_sn) == 2:             # <<<<<<<<<<<<<<
 *                                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                                     backtrace_set.push(
 */
                        __pyx_t_1 = ((__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get(__pyx_v_stream_mr, __pyx_v_xi_sn, __pyx_v_yi_sn) == 2.0) != 0);
                        if (__pyx_t_1) {

                          /* "pygeoprocessing/routing/routing.pyx":2786
 *                                                     continue
 *                                                 if stream_mr.get(xi_sn, yi_sn) == 2:
 *                                                     stream_mr.set(xi_sn, yi_sn, 1)             # <<<<<<<<<<<<<<
 *                                                     backtrace_set.push(
 *                                                         CoordinateType(xi_sn, yi_sn))
 */
                          __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_stream_mr, __pyx_v_xi_sn, __pyx_v_yi_sn, 1.0);

                          /* "pygeoprocessing/routing/routing.pyx":2788
 *                                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                                     backtrace_set.push(
 *                                                         CoordinateType(xi_sn, yi_sn))             # <<<<<<<<<<<<<<
 *                                 elif flow_accum >= trace_flow_threshold:
 *                                     stream_mr.set(xi_sn, yi_sn, 2)
 */
                          __pyx_t_20.xi = __pyx_v_xi_sn;
                          __pyx_t_20.yi = __pyx_v_yi_sn;

                          /* "pygeoprocessing/routing/routing.pyx":2787
 *                                                 if stream_mr.get(xi_sn, yi_sn) == 2:
 *                                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                                     backtrace_set.push(             # <<<<<<<<<<<<<<
 *                                                         CoordinateType(xi_sn, yi_sn))
 *                                 elif flow_accum >= trace_flow_threshold:
 */
                          __pyx_v_backtrace_set.push(__pyx_t_20);

                          /* "pygeoprocessing/routing/routing.pyx":2785
 *                                                         yi_sn < 0 or yi_sn >= raster_y_size):
 *                                                     continue
 *                                                 if stream_mr.get(xi_sn, yi_sn) == 2:             # <<<<<<<<<<<<<<
 *                                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                                     backtrace_set.push(
 */
                        }

                        /* "pygeoprocessing/routing/routing.pyx":2779
 *                                             flow_dir_mfd_mr.get(xi_bn, yi_bn))
 *                                         for i_sn in range(8):
 *                                             if (flow_dir_mfd >> (i_sn*4)) & 0xF > 0:             # <<<<<<<<<<<<<<
 *                                                 xi_sn = xi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn]
 *                                                 yi_sn = yi_bn+NEIGHBOR_OFFSET_ARRAY[2*i_sn+1]
 */
                      }
                      __pyx_L43_continue:;
                    }
                  }

                  /* "pygeoprocessing/routing/routing.pyx":2764
 *                                 flow_accum = flow_accum_mr.get(
 *                                     xi_sn, yi_sn)
 *                                 if flow_accum >= flow_threshold:             # <<<<<<<<<<<<<<
 *                                     stream_mr.set(xi_sn, yi_sn, 1)
 *                                     open_set.push(
 */
                  goto __pyx_L40;
                }

                /* "pygeoprocessing/routing/routing.pyx":2789
 *                                                     backtrace_set.push(
 *                                                         CoordinateType(xi_sn, yi_sn))
 *                                 elif flow_accum >= trace_flow_threshold:             # <<<<<<<<<<<<<<
 *                                     stream_mr.set(xi_sn, yi_sn, 2)
 *                                     open_set.push(
 */
                __pyx_t_1 = ((__pyx_v_flow_accum >= __pyx_v_trace_flow_threshold) != 0);
                if (__pyx_t_1) {

                  /* "pygeoprocessing/routing/routing.pyx":2790
 *                                                         CoordinateType(xi_sn, yi_sn))
 *                                 elif flow_accum >= trace_flow_threshold:
 *                                     stream_mr.set(xi_sn, yi_sn, 2)             # <<<<<<<<<<<<<<
 *                                     open_set.push(
 *                                         CoordinateType(xi_sn, yi_sn))
 */
                  __pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set(__pyx_v_stream_mr, __pyx_v_xi_sn, __pyx_v_yi_sn, 2.0);

                  /* "pygeoprocessing/routing/routing.pyx":2792
 *                                     stream_mr.set(xi_sn, yi_sn, 2)
 *                                     open_set.push(
 *                                         CoordinateType(xi_sn, yi_sn))             # <<<<<<<<<<<<<<
 * 
 *     stream_mr.close()
 */
                  __pyx_t_20.xi = __pyx_v_xi_sn;
                  __pyx_t_20.yi = __pyx_v_yi_sn;

                  /* "pygeoprocessing/routing/routing.pyx":2791
 *                                 elif flow_accum >= trace_flow_threshold:
 *                                     stream_mr.set(xi_sn, yi_sn, 2)
 *                                     open_set.push(             # <<<<<<<<<<<<<<
 *                                         CoordinateType(xi_sn, yi_sn))
 * 
 */
                  __pyx_v_open_set.push(__pyx_t_20);

                  /* "pygeoprocessing/routing/routing.pyx":2789
 *                                                     backtrace_set.push(
 *                                                         CoordinateType(xi_sn, yi_sn))
 *                                 elif flow_accum >= trace_flow_threshold:             # <<<<<<<<<<<<<<
 *                                     stream_mr.set(xi_sn, yi_sn, 2)
 *                                     open_set.push(
 */
                }
                __pyx_L40:;

                /* "pygeoprocessing/routing/routing.pyx":2761
 *                             # upstream pixel flows into this one
 *                             stream_val = <int>stream_mr.get(xi_sn, yi_sn)
 *                             if stream_val != 1 and stream_val != 2:             # <<<<<<<<<<<<<<
 *                                 flow_accum = flow_accum_mr.get(
 *                                     xi_sn, yi_sn)
 */
              }

              /* "pygeoprocessing/routing/routing.pyx":2757
 *                         if flow_dir_mfd == flow_dir_nodata:
 *                             continue
 *                         if ((flow_dir_mfd >>             # <<<<<<<<<<<<<<
 *                                 (D8_REVERSE_DIRECTION[i_sn] * 4)) & 0xF) > 0:
 *                             # upstream pixel flows into this one
 */
            }
            __pyx_L30_continue:;
          }
        }
        __pyx_L13_continue:;
      }
    }

    /* "pygeoprocessing/routing/routing.pyx":2698
 *     cdef time_t last_log_time = ctime(NULL)
 * 
 *     for block_offsets in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *             target_stream_raster_path, offset_only=True):
 *         xoff = block_offsets['xoff']
 */
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2794
 *                                         CoordinateType(xi_sn, yi_sn))
 * 
 *     stream_mr.close()             # <<<<<<<<<<<<<<
 *     LOGGER.info('filter out incomplete divergent streams')
 *     stream_raster = gdal.OpenEx(
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_stream_mr), __pyx_n_s_close); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2794, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2794, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2794, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2795
 * 
 *     stream_mr.close()
 *     LOGGER.info('filter out incomplete divergent streams')             # <<<<<<<<<<<<<<
 *     stream_raster = gdal.OpenEx(
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2795, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2795, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2795, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2796
 *     stream_mr.close()
 *     LOGGER.info('filter out incomplete divergent streams')
 *     stream_raster = gdal.OpenEx(             # <<<<<<<<<<<<<<
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 *     stream_band = stream_raster.GetRasterBand(1)
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OpenEx); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2797
 *     LOGGER.info('filter out incomplete divergent streams')
 *     stream_raster = gdal.OpenEx(
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)             # <<<<<<<<<<<<<<
 *     stream_band = stream_raster.GetRasterBand(1)
 *     for block_offsets in pygeoprocessing.iterblocks(
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_OF_RASTER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gdal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_GA_Update); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Or(__pyx_t_6, __pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_15 = NULL;
  __pyx_t_11 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_15)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_15);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_11 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_target_stream_raster_path, __pyx_t_5};
    __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2796, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_target_stream_raster_path, __pyx_t_5};
    __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2796, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2796, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_15) {
      __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_15); __pyx_t_15 = NULL;
    }
    __Pyx_INCREF(__pyx_v_target_stream_raster_path);
    __Pyx_GIVEREF(__pyx_v_target_stream_raster_path);
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_11, __pyx_v_target_stream_raster_path);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_11, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2796, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_stream_raster = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2798
 *     stream_raster = gdal.OpenEx(
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 *     stream_band = stream_raster.GetRasterBand(1)             # <<<<<<<<<<<<<<
 *     for block_offsets in pygeoprocessing.iterblocks(
 *                 target_stream_raster_path, offset_only=True):
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_raster, __pyx_n_s_GetRasterBand); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2798, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2798, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_stream_band = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2799
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 *     stream_band = stream_raster.GetRasterBand(1)
 *     for block_offsets in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *                 target_stream_raster_path, offset_only=True):
 *         stream_array = stream_band.ReadAsArray(**block_offsets)
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pygeoprocessing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_iterblocks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2800
 *     stream_band = stream_raster.GetRasterBand(1)
 *     for block_offsets in pygeoprocessing.iterblocks(
 *                 target_stream_raster_path, offset_only=True):             # <<<<<<<<<<<<<<
 *         stream_array = stream_band.ReadAsArray(**block_offsets)
 *         stream_array[stream_array == 2] = 0
 */
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_target_stream_raster_path);
  __Pyx_GIVEREF(__pyx_v_target_stream_raster_path);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_target_stream_raster_path);
  __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2800, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_offset_only, Py_True) < 0) __PYX_ERR(0, 2800, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2799
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 *     stream_band = stream_raster.GetRasterBand(1)
 *     for block_offsets in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *                 target_stream_raster_path, offset_only=True):
 *         stream_array = stream_band.ReadAsArray(**block_offsets)
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2799, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
    __pyx_t_6 = __pyx_t_5; __Pyx_INCREF(__pyx_t_6); __pyx_t_12 = 0;
    __pyx_t_13 = NULL;
  } else {
    __pyx_t_12 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2799, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_13 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2799, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  for (;;) {
    if (likely(!__pyx_t_13)) {
      if (likely(PyList_CheckExact(__pyx_t_6))) {
        if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_6)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2799, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2799, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2799, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2799, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_13(__pyx_t_6);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2799, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_block_offsets, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2801
 *     for block_offsets in pygeoprocessing.iterblocks(
 *                 target_stream_raster_path, offset_only=True):
 *         stream_array = stream_band.ReadAsArray(**block_offsets)             # <<<<<<<<<<<<<<
 *         stream_array[stream_array == 2] = 0
 *         stream_band.WriteArray(
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_band, __pyx_n_s_ReadAsArray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2801, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__pyx_v_block_offsets == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
      __PYX_ERR(0, 2801, __pyx_L1_error)
    }
    if (likely(PyDict_CheckExact(__pyx_v_block_offsets))) {
      __pyx_t_4 = PyDict_Copy(__pyx_v_block_offsets); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2801, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_4 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_block_offsets, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2801, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
    }
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2801, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_stream_array, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2802
 *                 target_stream_raster_path, offset_only=True):
 *         stream_array = stream_band.ReadAsArray(**block_offsets)
 *         stream_array[stream_array == 2] = 0             # <<<<<<<<<<<<<<
 *         stream_band.WriteArray(
 *             stream_array, xoff=block_offsets['xoff'],
 */
    __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_v_stream_array, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2802, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(PyObject_SetItem(__pyx_v_stream_array, __pyx_t_7, __pyx_int_0) < 0)) __PYX_ERR(0, 2802, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2803
 *         stream_array = stream_band.ReadAsArray(**block_offsets)
 *         stream_array[stream_array == 2] = 0
 *         stream_band.WriteArray(             # <<<<<<<<<<<<<<
 *             stream_array, xoff=block_offsets['xoff'],
 *             yoff=block_offsets['yoff'])
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_stream_band, __pyx_n_s_WriteArray); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2803, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);

    /* "pygeoprocessing/routing/routing.pyx":2804
 *         stream_array[stream_array == 2] = 0
 *         stream_band.WriteArray(
 *             stream_array, xoff=block_offsets['xoff'],             # <<<<<<<<<<<<<<
 *             yoff=block_offsets['yoff'])
 *     stream_band = None
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2803, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_stream_array);
    __Pyx_GIVEREF(__pyx_v_stream_array);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_stream_array);
    __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2804, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_s_xoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2804, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_xoff, __pyx_t_15) < 0) __PYX_ERR(0, 2804, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2805
 *         stream_band.WriteArray(
 *             stream_array, xoff=block_offsets['xoff'],
 *             yoff=block_offsets['yoff'])             # <<<<<<<<<<<<<<
 *     stream_band = None
 *     stream_raster = None
 */
    __pyx_t_15 = __Pyx_PyObject_Dict_GetItem(__pyx_v_block_offsets, __pyx_n_s_yoff); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_yoff, __pyx_t_15) < 0) __PYX_ERR(0, 2804, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2803
 *         stream_array = stream_band.ReadAsArray(**block_offsets)
 *         stream_array[stream_array == 2] = 0
 *         stream_band.WriteArray(             # <<<<<<<<<<<<<<
 *             stream_array, xoff=block_offsets['xoff'],
 *             yoff=block_offsets['yoff'])
 */
    __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2803, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "pygeoprocessing/routing/routing.pyx":2799
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 *     stream_band = stream_raster.GetRasterBand(1)
 *     for block_offsets in pygeoprocessing.iterblocks(             # <<<<<<<<<<<<<<
 *                 target_stream_raster_path, offset_only=True):
 *         stream_array = stream_band.ReadAsArray(**block_offsets)
 */
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2806
 *             stream_array, xoff=block_offsets['xoff'],
 *             yoff=block_offsets['yoff'])
 *     stream_band = None             # <<<<<<<<<<<<<<
 *     stream_raster = None
 *     LOGGER.info('100.0% complete')
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_stream_band, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":2807
 *             yoff=block_offsets['yoff'])
 *     stream_band = None
 *     stream_raster = None             # <<<<<<<<<<<<<<
 *     LOGGER.info('100.0% complete')
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_stream_raster, Py_None);

  /* "pygeoprocessing/routing/routing.pyx":2808
 *     stream_band = None
 *     stream_raster = None
 *     LOGGER.info('100.0% complete')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_info); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2614
 * 
 * 
 * def extract_streams_mfd(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band, flow_dir_mfd_path_band, double flow_threshold,
 *         target_stream_raster_path, double trace_threshold_proportion=1.0,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("pygeoprocessing.routing.routing.extract_streams_mfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_flow_accum_info);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_accum_mr);
  __Pyx_XDECREF((PyObject *)__pyx_v_stream_mr);
  __Pyx_XDECREF((PyObject *)__pyx_v_flow_dir_mfd_mr);
  __Pyx_XDECREF(__pyx_v_block_offsets);
  __Pyx_XDECREF(__pyx_v_current_pixel);
  __Pyx_XDECREF(__pyx_v_stream_raster);
  __Pyx_XDECREF(__pyx_v_stream_band);
  __Pyx_XDECREF(__pyx_v_stream_array);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pygeoprocessing/routing/routing.pyx":2811
 * 
 * 
 * def _is_raster_path_band_formatted(raster_path_band):             # <<<<<<<<<<<<<<
 *     """Return true if raster path band is a (str, int) tuple/list."""
 *     if not isinstance(raster_path_band, (list, tuple)):
 */

/* Python wrapper */
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_19_is_raster_path_band_formatted(PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band); /*proto*/
static char __pyx_doc_15pygeoprocessing_7routing_7routing_18_is_raster_path_band_formatted[] = "Return true if raster path band is a (str, int) tuple/list.";
static PyMethodDef __pyx_mdef_15pygeoprocessing_7routing_7routing_19_is_raster_path_band_formatted = {"_is_raster_path_band_formatted", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_19_is_raster_path_band_formatted, METH_O, __pyx_doc_15pygeoprocessing_7routing_7routing_18_is_raster_path_band_formatted};
static PyObject *__pyx_pw_15pygeoprocessing_7routing_7routing_19_is_raster_path_band_formatted(PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_is_raster_path_band_formatted (wrapper)", 0);
  __pyx_r = __pyx_pf_15pygeoprocessing_7routing_7routing_18_is_raster_path_band_formatted(__pyx_self, ((PyObject *)__pyx_v_raster_path_band));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_15pygeoprocessing_7routing_7routing_18_is_raster_path_band_formatted(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_raster_path_band) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("_is_raster_path_band_formatted", 0);

  /* "pygeoprocessing/routing/routing.pyx":2813
 * def _is_raster_path_band_formatted(raster_path_band):
 *     """Return true if raster path band is a (str, int) tuple/list."""
 *     if not isinstance(raster_path_band, (list, tuple)):             # <<<<<<<<<<<<<<
 *         return False
 *     elif len(raster_path_band) != 2:
 */
  __pyx_t_2 = PyList_Check(__pyx_v_raster_path_band); 
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = PyTuple_Check(__pyx_v_raster_path_band); 
  __pyx_t_2 = (__pyx_t_3 != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
  if (__pyx_t_2) {

    /* "pygeoprocessing/routing/routing.pyx":2814
 *     """Return true if raster path band is a (str, int) tuple/list."""
 *     if not isinstance(raster_path_band, (list, tuple)):
 *         return False             # <<<<<<<<<<<<<<
 *     elif len(raster_path_band) != 2:
 *         return False
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":2813
 * def _is_raster_path_band_formatted(raster_path_band):
 *     """Return true if raster path band is a (str, int) tuple/list."""
 *     if not isinstance(raster_path_band, (list, tuple)):             # <<<<<<<<<<<<<<
 *         return False
 *     elif len(raster_path_band) != 2:
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2815
 *     if not isinstance(raster_path_band, (list, tuple)):
 *         return False
 *     elif len(raster_path_band) != 2:             # <<<<<<<<<<<<<<
 *         return False
 *     elif not isinstance(raster_path_band[0], basestring):
 */
  __pyx_t_4 = PyObject_Length(__pyx_v_raster_path_band); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2815, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_4 != 2) != 0);
  if (__pyx_t_2) {

    /* "pygeoprocessing/routing/routing.pyx":2816
 *         return False
 *     elif len(raster_path_band) != 2:
 *         return False             # <<<<<<<<<<<<<<
 *     elif not isinstance(raster_path_band[0], basestring):
 *         return False
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":2815
 *     if not isinstance(raster_path_band, (list, tuple)):
 *         return False
 *     elif len(raster_path_band) != 2:             # <<<<<<<<<<<<<<
 *         return False
 *     elif not isinstance(raster_path_band[0], basestring):
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2817
 *     elif len(raster_path_band) != 2:
 *         return False
 *     elif not isinstance(raster_path_band[0], basestring):             # <<<<<<<<<<<<<<
 *         return False
 *     elif not isinstance(raster_path_band[1], int):
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_raster_path_band, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2817, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyBaseString_Check(__pyx_t_5); 
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_1) {

    /* "pygeoprocessing/routing/routing.pyx":2818
 *         return False
 *     elif not isinstance(raster_path_band[0], basestring):
 *         return False             # <<<<<<<<<<<<<<
 *     elif not isinstance(raster_path_band[1], int):
 *         return False
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":2817
 *     elif len(raster_path_band) != 2:
 *         return False
 *     elif not isinstance(raster_path_band[0], basestring):             # <<<<<<<<<<<<<<
 *         return False
 *     elif not isinstance(raster_path_band[1], int):
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2819
 *     elif not isinstance(raster_path_band[0], basestring):
 *         return False
 *     elif not isinstance(raster_path_band[1], int):             # <<<<<<<<<<<<<<
 *         return False
 *     else:
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_raster_path_band, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyInt_Check(__pyx_t_5); 
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
  if (__pyx_t_2) {

    /* "pygeoprocessing/routing/routing.pyx":2820
 *         return False
 *     elif not isinstance(raster_path_band[1], int):
 *         return False             # <<<<<<<<<<<<<<
 *     else:
 *         return True
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;

    /* "pygeoprocessing/routing/routing.pyx":2819
 *     elif not isinstance(raster_path_band[0], basestring):
 *         return False
 *     elif not isinstance(raster_path_band[1], int):             # <<<<<<<<<<<<<<
 *         return False
 *     else:
 */
  }

  /* "pygeoprocessing/routing/routing.pyx":2822
 *         return False
 *     else:
 *         return True             # <<<<<<<<<<<<<<
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    goto __pyx_L0;
  }

  /* "pygeoprocessing/routing/routing.pyx":2811
 * 
 * 
 * def _is_raster_path_band_formatted(raster_path_band):             # <<<<<<<<<<<<<<
 *     """Return true if raster path band is a (str, int) tuple/list."""
 *     if not isinstance(raster_path_band, (list, tuple)):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pygeoprocessing.routing.routing._is_raster_path_band_formatted", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":215
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_i;
  int __pyx_v_ndim;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  int __pyx_v_t;
  char *__pyx_v_f;
  PyArray_Descr *__pyx_v_descr = 0;
  int __pyx_v_offset;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  char *__pyx_t_8;
  if (__pyx_v_info == NULL) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":222
 * 
 *             cdef int i, ndim
 *             cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 */
  __pyx_v_endian_detector = 1;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":223
 *             cdef int i, ndim
 *             cdef int endian_detector = 1
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 * 
 *             ndim = PyArray_NDIM(self)
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":225
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 *             ndim = PyArray_NDIM(self)             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 */
  __pyx_v_ndim = PyArray_NDIM(__pyx_v_self);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":227
 *             ndim = PyArray_NDIM(self)
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":228
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 */
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":227
 *             ndim = PyArray_NDIM(self)
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  if (unlikely(__pyx_t_1)) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":229
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 229, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(2, 229, __pyx_L1_error)

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":227
 *             ndim = PyArray_NDIM(self)
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L7_bool_binop_done;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":232
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 */
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L7_bool_binop_done:;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  if (unlikely(__pyx_t_1)) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":233
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 233, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(2, 233, __pyx_L1_error)

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":235
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 *             info.buf = PyArray_DATA(self)             # <<<<<<<<<<<<<<
 *             info.ndim = ndim
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_v_info->buf = PyArray_DATA(__pyx_v_self);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":236
 * 
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 # Allocate new buffer for strides and shape info.
 */
  __pyx_v_info->ndim = __pyx_v_ndim;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":237
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":240
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)             # <<<<<<<<<<<<<<
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 */
    __pyx_v_info->strides = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * 2) * ((size_t)__pyx_v_ndim))));

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":241
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)
 *                 info.shape = info.strides + ndim             # <<<<<<<<<<<<<<
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 */
    __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim);

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":242
 *                 info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):             # <<<<<<<<<<<<<<
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 */
    __pyx_t_4 = __pyx_v_ndim;
    __pyx_t_5 = __pyx_t_4;
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":243
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]             # <<<<<<<<<<<<<<
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 */
      (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]);

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":244
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]             # <<<<<<<<<<<<<<
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 */
      (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]);
    }

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":237
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
    goto __pyx_L9;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":246
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)             # <<<<<<<<<<<<<<
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 */
  /*else*/ {
    __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self));

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":247
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)             # <<<<<<<<<<<<<<
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 */
    __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self));
  }
  __pyx_L9:;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":248
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 */
  __pyx_v_info->suboffsets = NULL;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":249
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)             # <<<<<<<<<<<<<<
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 * 
 */
  __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":250
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)             # <<<<<<<<<<<<<<
 * 
 *             cdef int t
 */
  __pyx_v_info->readonly = (!(PyArray_ISWRITEABLE(__pyx_v_self) != 0));

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":253
 * 
 *             cdef int t
 *             cdef char* f = NULL             # <<<<<<<<<<<<<<
 *             cdef dtype descr = self.descr
 *             cdef int offset
 */
  __pyx_v_f = NULL;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":254
 *             cdef int t
 *             cdef char* f = NULL
 *             cdef dtype descr = self.descr             # <<<<<<<<<<<<<<
 *             cdef int offset
 * 
 */
  __pyx_t_3 = ((PyObject *)__pyx_v_self->descr);
  __Pyx_INCREF(__pyx_t_3);
  __pyx_v_descr = ((PyArray_Descr *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":257
 *             cdef int offset
 * 
 *             info.obj = self             # <<<<<<<<<<<<<<
 * 
 *             if not PyDataType_HASFIELDS(descr):
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":259
 *             info.obj = self
 * 
 *             if not PyDataType_HASFIELDS(descr):             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  __pyx_t_1 = ((!(PyDataType_HASFIELDS(__pyx_v_descr) != 0)) != 0);
  if (__pyx_t_1) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":260
 * 
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num             # <<<<<<<<<<<<<<
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 */
    __pyx_t_4 = __pyx_v_descr->type_num;
    __pyx_v_t = __pyx_t_4;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":261
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '>') != 0);
    if (!__pyx_t_2) {
      goto __pyx_L15_next_or;
    } else {
    }
    __pyx_t_2 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_L15_next_or:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":262
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 */
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '<') != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_2 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L14_bool_binop_done:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":261
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    if (unlikely(__pyx_t_1)) {

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":263
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 263, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(2, 263, __pyx_L1_error)

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":261
 *             if not PyDataType_HASFIELDS(descr):
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":264
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 */
    switch (__pyx_v_t) {
      case NPY_BYTE:
      __pyx_v_f = ((char *)"b");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":265
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 */
      case NPY_UBYTE:
      __pyx_v_f = ((char *)"B");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":266
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 */
      case NPY_SHORT:
      __pyx_v_f = ((char *)"h");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":267
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 */
      case NPY_USHORT:
      __pyx_v_f = ((char *)"H");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":268
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 */
      case NPY_INT:
      __pyx_v_f = ((char *)"i");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":269
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 */
      case NPY_UINT:
      __pyx_v_f = ((char *)"I");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":270
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 */
      case NPY_LONG:
      __pyx_v_f = ((char *)"l");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":271
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 */
      case NPY_ULONG:
      __pyx_v_f = ((char *)"L");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":272
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 */
      case NPY_LONGLONG:
      __pyx_v_f = ((char *)"q");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":273
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 */
      case NPY_ULONGLONG:
      __pyx_v_f = ((char *)"Q");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":274
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 */
      case NPY_FLOAT:
      __pyx_v_f = ((char *)"f");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":275
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 */
      case NPY_DOUBLE:
      __pyx_v_f = ((char *)"d");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":276
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 */
      case NPY_LONGDOUBLE:
      __pyx_v_f = ((char *)"g");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":277
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 */
      case NPY_CFLOAT:
      __pyx_v_f = ((char *)"Zf");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":278
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"
 */
      case NPY_CDOUBLE:
      __pyx_v_f = ((char *)"Zd");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":279
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 */
      case NPY_CLONGDOUBLE:
      __pyx_v_f = ((char *)"Zg");
      break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":280
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      case NPY_OBJECT:
      __pyx_v_f = ((char *)"O");
      break;
      default:

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":282
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *                 info.format = f
 *                 return
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(2, 282, __pyx_L1_error)
      break;
    }

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":283
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
    __pyx_v_info->format = __pyx_v_f;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":284
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":259
 *             info.obj = self
 * 
 *             if not PyDataType_HASFIELDS(descr):             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":286
 *                 return
 *             else:
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)             # <<<<<<<<<<<<<<
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 */
  /*else*/ {
    __pyx_v_info->format = ((char *)PyObject_Malloc(0xFF));

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":287
 *             else:
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment             # <<<<<<<<<<<<<<
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,
 */
    (__pyx_v_info->format[0]) = '^';

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":288
 *                 info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0             # <<<<<<<<<<<<<<
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 */
    __pyx_v_offset = 0;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":289
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,             # <<<<<<<<<<<<<<
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 */
    __pyx_t_8 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 0xFF), (&__pyx_v_offset)); if (unlikely(__pyx_t_8 == ((char *)NULL))) __PYX_ERR(2, 289, __pyx_L1_error)
    __pyx_v_f = __pyx_t_8;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":292
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 *                 f[0] = c'\0' # Terminate format string             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 */
    (__pyx_v_f[0]) = '\x00';
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":215
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("numpy.ndarray.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_descr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":294
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 */

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":295
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_t_1 = (PyArray_HASFIELDS(__pyx_v_self) != 0);
  if (__pyx_t_1) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":296
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 PyObject_Free(info.strides)
 */
    PyObject_Free(__pyx_v_info->format);

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":295
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":297
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":298
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 PyObject_Free(info.strides)             # <<<<<<<<<<<<<<
 *                 # info.shape was stored after info.strides in the same block
 * 
 */
    PyObject_Free(__pyx_v_info->strides);

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":297
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 PyObject_Free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":294
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 PyObject_Free(info.format)
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":775
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":776
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 776, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":775
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":778
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":779
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":778
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":781
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":782
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 782, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":781
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":784
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":785
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 785, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":784
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":787
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":788
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)             # <<<<<<<<<<<<<<
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":787
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":790
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):             # <<<<<<<<<<<<<<
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyDataType_SHAPE(PyArray_Descr *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("PyDataType_SHAPE", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":791
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  __pyx_t_1 = (PyDataType_HASSUBARRAY(__pyx_v_d) != 0);
  if (__pyx_t_1) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":792
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape             # <<<<<<<<<<<<<<
 *     else:
 *         return ()
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject*)__pyx_v_d->subarray->shape));
    __pyx_r = ((PyObject*)__pyx_v_d->subarray->shape);
    goto __pyx_L0;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":791
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):
 *     if PyDataType_HASSUBARRAY(d):             # <<<<<<<<<<<<<<
 *         return <tuple>d.subarray.shape
 *     else:
 */
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":794
 *         return <tuple>d.subarray.shape
 *     else:
 *         return ()             # <<<<<<<<<<<<<<
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_empty_tuple);
    __pyx_r = __pyx_empty_tuple;
    goto __pyx_L0;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":790
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline tuple PyDataType_SHAPE(dtype d):             # <<<<<<<<<<<<<<
 *     if PyDataType_HASSUBARRAY(d):
 *         return <tuple>d.subarray.shape
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":796
 *         return ()
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) {
  PyArray_Descr *__pyx_v_child = 0;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_childname = NULL;
  PyObject *__pyx_v_new_offset = NULL;
  PyObject *__pyx_v_t = NULL;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  long __pyx_t_8;
  char *__pyx_t_9;
  __Pyx_RefNannySetupContext("_util_dtypestring", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":801
 * 
 *     cdef dtype child
 *     cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 *     cdef tuple fields
 */
  __pyx_v_endian_detector = 1;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":802
 *     cdef dtype child
 *     cdef int endian_detector = 1
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 *     cdef tuple fields
 * 
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":805
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  if (unlikely(__pyx_v_descr->names == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(2, 805, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_descr->names; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(2, 805, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_childname, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":806
 * 
 *     for childname in descr.names:
 *         fields = descr.fields[childname]             # <<<<<<<<<<<<<<
 *         child, new_offset = fields
 * 
 */
    if (unlikely(__pyx_v_descr->fields == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(2, 806, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 806, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(2, 806, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":807
 *     for childname in descr.names:
 *         fields = descr.fields[childname]
 *         child, new_offset = fields             # <<<<<<<<<<<<<<
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 */
    if (likely(__pyx_v_fields != Py_None)) {
      PyObject* sequence = __pyx_v_fields;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(2, 807, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 807, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 807, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
    } else {
      __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(2, 807, __pyx_L1_error)
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) __PYX_ERR(2, 807, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_child, ((PyArray_Descr *)__pyx_t_3));
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_new_offset, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":809
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 809, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 809, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 809, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = ((((__pyx_v_end - __pyx_v_f) - ((int)__pyx_t_5)) < 15) != 0);
    if (unlikely(__pyx_t_6)) {

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":810
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 810, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(2, 810, __pyx_L1_error)

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":809
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    }

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":812
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_7 = ((__pyx_v_child->byteorder == '>') != 0);
    if (!__pyx_t_7) {
      goto __pyx_L8_next_or;
    } else {
    }
    __pyx_t_7 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_L8_next_or:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":813
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *             raise ValueError(u"Non-native byte order not supported")
 *             # One could encode it in the format string and have Cython
 */
    __pyx_t_7 = ((__pyx_v_child->byteorder == '<') != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_7 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_6 = __pyx_t_7;
    __pyx_L7_bool_binop_done:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":812
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    if (unlikely(__pyx_t_6)) {

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":814
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(2, 814, __pyx_L1_error)

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":812
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":824
 * 
 *         # Output padding bytes
 *         while offset[0] < new_offset:             # <<<<<<<<<<<<<<
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 */
    while (1) {
      __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 824, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 824, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 824, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!__pyx_t_6) break;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":825
 *         # Output padding bytes
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte             # <<<<<<<<<<<<<<
 *             f += 1
 *             offset[0] += 1
 */
      (__pyx_v_f[0]) = 0x78;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":826
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte
 *             f += 1             # <<<<<<<<<<<<<<
 *             offset[0] += 1
 * 
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":827
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 *             offset[0] += 1             # <<<<<<<<<<<<<<
 * 
 *         offset[0] += child.itemsize
 */
      __pyx_t_8 = 0;
      (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + 1);
    }

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":829
 *             offset[0] += 1
 * 
 *         offset[0] += child.itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not PyDataType_HASFIELDS(child):
 */
    __pyx_t_8 = 0;
    (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + __pyx_v_child->elsize);

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":831
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
    __pyx_t_6 = ((!(PyDataType_HASFIELDS(__pyx_v_child) != 0)) != 0);
    if (__pyx_t_6) {

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":832
 * 
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num             # <<<<<<<<<<<<<<
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")
 */
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_child->type_num); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":833
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      __pyx_t_6 = (((__pyx_v_end - __pyx_v_f) < 5) != 0);
      if (unlikely(__pyx_t_6)) {

        /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":834
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 834, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __PYX_ERR(2, 834, __pyx_L1_error)

        /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":833
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":837
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_BYTE); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 837, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 837, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 837, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 98;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":838
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"             # <<<<<<<<<<<<<<
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UBYTE); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 838, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 838, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 838, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 66;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":839
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"             # <<<<<<<<<<<<<<
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_SHORT); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 839, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 839, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 839, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x68;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":840
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"             # <<<<<<<<<<<<<<
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_USHORT); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 840, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 840, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 840, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 72;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":841
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_INT); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 841, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 841, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 841, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x69;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":842
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UINT); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 842, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 842, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 842, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 73;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":843
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONG); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 843, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 843, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 843, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x6C;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":844
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONG); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 844, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 844, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 844, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 76;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":845
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGLONG); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 845, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 845, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 845, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x71;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":846
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 846, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 846, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 846, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 81;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":847
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"             # <<<<<<<<<<<<<<
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_FLOAT); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 847, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 847, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 847, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x66;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":848
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 848, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 848, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 848, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x64;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":849
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"             # <<<<<<<<<<<<<<
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 849, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 849, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 849, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x67;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":850
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf             # <<<<<<<<<<<<<<
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 850, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 850, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 850, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x66;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":851
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd             # <<<<<<<<<<<<<<
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CDOUBLE); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 851, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 851, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 851, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x64;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":852
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg             # <<<<<<<<<<<<<<
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 852, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 852, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x67;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":853
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_OBJECT); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 853, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 853, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(2, 853, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(__pyx_t_6)) {
        (__pyx_v_f[0]) = 79;
        goto __pyx_L15;
      }

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":855
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *             f += 1
 *         else:
 */
      /*else*/ {
        __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_v_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 855, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 855, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __PYX_ERR(2, 855, __pyx_L1_error)
      }
      __pyx_L15:;

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":856
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *             f += 1             # <<<<<<<<<<<<<<
 *         else:
 *             # Cython ignores struct boundary information ("T{...}"),
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":831
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
      goto __pyx_L13;
    }

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":860
 *             # Cython ignores struct boundary information ("T{...}"),
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)             # <<<<<<<<<<<<<<
 *     return f
 * 
 */
    /*else*/ {
      __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_9 == ((char *)NULL))) __PYX_ERR(2, 860, __pyx_L1_error)
      __pyx_v_f = __pyx_t_9;
    }
    __pyx_L13:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":805
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":861
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)
 *     return f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_f;
  goto __pyx_L0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":796
 *         return ()
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_childname);
  __Pyx_XDECREF(__pyx_v_new_offset);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  PyObject *__pyx_v_baseptr;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("set_array_base", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":979
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
  __pyx_t_1 = (__pyx_v_base == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":980
 *      cdef PyObject* baseptr
 *      if base is None:
 *          baseptr = NULL             # <<<<<<<<<<<<<<
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 */
    __pyx_v_baseptr = NULL;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":979
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
    goto __pyx_L3;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":982
 *          baseptr = NULL
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!             # <<<<<<<<<<<<<<
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 */
  /*else*/ {
    Py_INCREF(__pyx_v_base);

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":983
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base             # <<<<<<<<<<<<<<
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr
 */
    __pyx_v_baseptr = ((PyObject *)__pyx_v_base);
  }
  __pyx_L3:;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":984
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)             # <<<<<<<<<<<<<<
 *      arr.base = baseptr
 * 
 */
  Py_XDECREF(__pyx_v_arr->base);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":985
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __pyx_v_arr->base = __pyx_v_baseptr;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":987
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":988
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_arr->base == NULL) != 0);
  if (__pyx_t_1) {

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":989
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     else:
 *         return <object>arr.base
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":988
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":991
 *         return None
 *     else:
 *         return <object>arr.base             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_arr->base));
    __pyx_r = ((PyObject *)__pyx_v_arr->base);
    goto __pyx_L0;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":987
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":996
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_array()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_array(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("import_array", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":997
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_array()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":998
 * cdef inline int import_array() except -1:
 *     try:
 *         _import_array()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")
 */
      __pyx_t_4 = _import_array(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 998, __pyx_L3_error)

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":997
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_array()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":999
 *     try:
 *         _import_array()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(2, 999, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1000
 *         _import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 1000, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(2, 1000, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":997
 * # Cython code.
 * cdef inline int import_array() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_array()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":996
 * # Versions of the import_* functions which are more suitable for
 * # Cython code.
 * cdef inline int import_array() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_array()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1002
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_umath(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("import_umath", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1003
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1004
 * cdef inline int import_umath() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 1004, __pyx_L3_error)

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1003
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1005
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(2, 1005, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1006
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 1006, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(2, 1006, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1003
 * 
 * cdef inline int import_umath() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1002
 *         raise ImportError("numpy.core.multiarray failed to import")
 * 
 * cdef inline int import_umath() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_umath", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1008
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

static CYTHON_INLINE int __pyx_f_5numpy_import_ufunc(void) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("import_ufunc", 0);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1009
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1010
 * cdef inline int import_ufunc() except -1:
 *     try:
 *         _import_umath()             # <<<<<<<<<<<<<<
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")
 */
      __pyx_t_4 = _import_umath(); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 1010, __pyx_L3_error)

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1009
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1011
 *     try:
 *         _import_umath()
 *     except Exception:             # <<<<<<<<<<<<<<
 *         raise ImportError("numpy.core.umath failed to import")
 */
    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
    if (__pyx_t_4) {
      __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(2, 1011, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1012
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ImportError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 1012, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(2, 1012, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1009
 * 
 * cdef inline int import_ufunc() except -1:
 *     try:             # <<<<<<<<<<<<<<
 *         _import_umath()
 *     except Exception:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1008
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.import_ufunc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_15pygeoprocessing_7routing_7routing__ManagedRaster __pyx_vtable_15pygeoprocessing_7routing_7routing__ManagedRaster;

static PyObject *__pyx_tp_new_15pygeoprocessing_7routing_7routing__ManagedRaster(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)o);
  p->__pyx_vtab = __pyx_vtabptr_15pygeoprocessing_7routing_7routing__ManagedRaster;
  new((void*)&(p->dirty_blocks)) std::set<int> ();
  p->raster_path = ((PyObject*)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_15pygeoprocessing_7routing_7routing__ManagedRaster(PyObject *o) {
  struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *p = (struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  __Pyx_call_destructor(p->dirty_blocks);
  Py_CLEAR(p->raster_path);
  (*Py_TYPE(o)->tp_free)(o);
}

static PyMethodDef __pyx_methods_15pygeoprocessing_7routing_7routing__ManagedRaster[] = {
  {"close", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_5close, METH_NOARGS, __pyx_doc_15pygeoprocessing_7routing_7routing_14_ManagedRaster_4close},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_7__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_15pygeoprocessing_7routing_7routing_14_ManagedRaster_9__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster = {
  PyVarObject_HEAD_INIT(0, 0)
  "pygeoprocessing.routing.routing._ManagedRaster", /*tp_name*/
  sizeof(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_15pygeoprocessing_7routing_7routing__ManagedRaster, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_15pygeoprocessing_7routing_7routing__ManagedRaster, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_15pygeoprocessing_7routing_7routing__ManagedRaster, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_routing(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_routing},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "routing",
    __pyx_k_Provides_PyGeprocessing_Routing, /* m_doc */
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    0, /* m_size */
  #else
    -1, /* m_size */
  #endif
    __pyx_methods /* m_methods */,
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    __pyx_moduledef_slots, /* m_slots */
  #else
    NULL, /* m_reload */
  #endif
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_100_0_complete, __pyx_k_100_0_complete, sizeof(__pyx_k_100_0_complete), 0, 0, 1, 0},
  {&__pyx_kp_s_1f_complete, __pyx_k_1f_complete, sizeof(__pyx_k_1f_complete), 0, 0, 1, 0},
  {&__pyx_kp_s_BIGTIFF_YES, __pyx_k_BIGTIFF_YES, sizeof(__pyx_k_BIGTIFF_YES), 0, 0, 1, 0},
  {&__pyx_kp_s_BLOCKXSIZE_d, __pyx_k_BLOCKXSIZE_d, sizeof(__pyx_k_BLOCKXSIZE_d), 0, 0, 1, 0},
  {&__pyx_kp_s_BLOCKYSIZE_d, __pyx_k_BLOCKYSIZE_d, sizeof(__pyx_k_BLOCKYSIZE_d), 0, 0, 1, 0},
  {&__pyx_kp_s_COMPRESS_LZW, __pyx_k_COMPRESS_LZW, sizeof(__pyx_k_COMPRESS_LZW), 0, 0, 1, 0},
  {&__pyx_n_s_CreateCopy, __pyx_k_CreateCopy, sizeof(__pyx_k_CreateCopy), 0, 0, 1, 1},
  {&__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS, __pyx_k_DEFAULT_GTIFF_CREATION_OPTIONS, sizeof(__pyx_k_DEFAULT_GTIFF_CREATION_OPTIONS), 0, 0, 1, 1},
  {&__pyx_kp_s_Error_Block_size_is_not_a_power, __pyx_k_Error_Block_size_is_not_a_power, sizeof(__pyx_k_Error_Block_size_is_not_a_power), 0, 0, 1, 0},
  {&__pyx_kp_s_Error_band_ID_s_is_not_a_valid_b, __pyx_k_Error_band_ID_s_is_not_a_valid_b, sizeof(__pyx_k_Error_band_ID_s_is_not_a_valid_b), 0, 0, 1, 0},
  {&__pyx_n_s_FlushCache, __pyx_k_FlushCache, sizeof(__pyx_k_FlushCache), 0, 0, 1, 1},
  {&__pyx_kp_u_Format_string_allocated_too_shor, __pyx_k_Format_string_allocated_too_shor, sizeof(__pyx_k_Format_string_allocated_too_shor), 0, 1, 0, 0},
  {&__pyx_kp_u_Format_string_allocated_too_shor_2, __pyx_k_Format_string_allocated_too_shor_2, sizeof(__pyx_k_Format_string_allocated_too_shor_2), 0, 1, 0, 0},
  {&__pyx_n_s_GA_Update, __pyx_k_GA_Update, sizeof(__pyx_k_GA_Update), 0, 0, 1, 1},
  {&__pyx_n_s_GDT_Byte, __pyx_k_GDT_Byte, sizeof(__pyx_k_GDT_Byte), 0, 0, 1, 1},
  {&__pyx_n_s_GDT_Float64, __pyx_k_GDT_Float64, sizeof(__pyx_k_GDT_Float64), 0, 0, 1, 1},
  {&__pyx_n_s_GDT_Int32, __pyx_k_GDT_Int32, sizeof(__pyx_k_GDT_Int32), 0, 0, 1, 1},
  {&__pyx_n_s_GTiff, __pyx_k_GTiff, sizeof(__pyx_k_GTiff), 0, 0, 1, 1},
  {&__pyx_n_s_GetDriverByName, __pyx_k_GetDriverByName, sizeof(__pyx_k_GetDriverByName), 0, 0, 1, 1},
  {&__pyx_n_s_GetRasterBand, __pyx_k_GetRasterBand, sizeof(__pyx_k_GetRasterBand), 0, 0, 1, 1},
  {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
  {&__pyx_n_s_LOGGER, __pyx_k_LOGGER, sizeof(__pyx_k_LOGGER), 0, 0, 1, 1},
  {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0},
  {&__pyx_n_s_NullHandler, __pyx_k_NullHandler, sizeof(__pyx_k_NullHandler), 0, 0, 1, 1},
  {&__pyx_n_s_OF_RASTER, __pyx_k_OF_RASTER, sizeof(__pyx_k_OF_RASTER), 0, 0, 1, 1},
  {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1},
  {&__pyx_n_s_OpenEx, __pyx_k_OpenEx, sizeof(__pyx_k_OpenEx), 0, 0, 1, 1},
  {&__pyx_n_s_ReadAsArray, __pyx_k_ReadAsArray, sizeof(__pyx_k_ReadAsArray), 0, 0, 1, 1},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_kp_s_TILED_YES, __pyx_k_TILED_YES, sizeof(__pyx_k_TILED_YES), 0, 0, 1, 0},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_n_s_WriteArray, __pyx_k_WriteArray, sizeof(__pyx_k_WriteArray), 0, 0, 1, 1},
  {&__pyx_kp_s_Y_m_d__H__M__S, __pyx_k_Y_m_d__H__M__S, sizeof(__pyx_k_Y_m_d__H__M__S), 0, 0, 1, 0},
  {&__pyx_n_s__52, __pyx_k__52, sizeof(__pyx_k__52), 0, 0, 1, 1},
  {&__pyx_n_s_addHandler, __pyx_k_addHandler, sizeof(__pyx_k_addHandler), 0, 0, 1, 1},
  {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1},
  {&__pyx_n_s_backtrace_set, __pyx_k_backtrace_set, sizeof(__pyx_k_backtrace_set), 0, 0, 1, 1},
  {&__pyx_n_s_band_id, __pyx_k_band_id, sizeof(__pyx_k_band_id), 0, 0, 1, 1},
  {&__pyx_n_s_base_dem_raster, __pyx_k_base_dem_raster, sizeof(__pyx_k_base_dem_raster), 0, 0, 1, 1},
  {&__pyx_n_s_base_nodata, __pyx_k_base_nodata, sizeof(__pyx_k_base_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_block_offsets, __pyx_k_block_offsets, sizeof(__pyx_k_block_offsets), 0, 0, 1, 1},
  {&__pyx_n_s_block_size, __pyx_k_block_size, sizeof(__pyx_k_block_size), 0, 0, 1, 1},
  {&__pyx_n_s_center_val, __pyx_k_center_val, sizeof(__pyx_k_center_val), 0, 0, 1, 1},
  {&__pyx_n_s_channel_band, __pyx_k_channel_band, sizeof(__pyx_k_channel_band), 0, 0, 1, 1},
  {&__pyx_n_s_channel_buffer_array, __pyx_k_channel_buffer_array, sizeof(__pyx_k_channel_buffer_array), 0, 0, 1, 1},
  {&__pyx_n_s_channel_managed_raster, __pyx_k_channel_managed_raster, sizeof(__pyx_k_channel_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_channel_raster, __pyx_k_channel_raster, sizeof(__pyx_k_channel_raster), 0, 0, 1, 1},
  {&__pyx_n_s_channel_raster_path_band, __pyx_k_channel_raster_path_band, sizeof(__pyx_k_channel_raster_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_compatable_dem_raster_path_band, __pyx_k_compatable_dem_raster_path_band, sizeof(__pyx_k_compatable_dem_raster_path_band), 0, 0, 1, 1},
  {&__pyx_kp_s_compatable_dem_tif, __pyx_k_compatable_dem_tif, sizeof(__pyx_k_compatable_dem_tif), 0, 0, 1, 0},
  {&__pyx_kp_s_compatible_dem_complete, __pyx_k_compatible_dem_complete, sizeof(__pyx_k_compatible_dem_complete), 0, 0, 1, 0},
  {&__pyx_n_s_compressed_flow_dir, __pyx_k_compressed_flow_dir, sizeof(__pyx_k_compressed_flow_dir), 0, 0, 1, 1},
  {&__pyx_n_s_compressed_integer_slopes, __pyx_k_compressed_integer_slopes, sizeof(__pyx_k_compressed_integer_slopes), 0, 0, 1, 1},
  {&__pyx_n_s_compressed_upstream_flow_dir, __pyx_k_compressed_upstream_flow_dir, sizeof(__pyx_k_compressed_upstream_flow_dir), 0, 0, 1, 1},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_n_s_current_pixel, __pyx_k_current_pixel, sizeof(__pyx_k_current_pixel), 0, 0, 1, 1},
  {&__pyx_n_s_dem_band, __pyx_k_dem_band, sizeof(__pyx_k_dem_band), 0, 0, 1, 1},
  {&__pyx_n_s_dem_block_xsize, __pyx_k_dem_block_xsize, sizeof(__pyx_k_dem_block_xsize), 0, 0, 1, 1},
  {&__pyx_n_s_dem_block_ysize, __pyx_k_dem_block_ysize, sizeof(__pyx_k_dem_block_ysize), 0, 0, 1, 1},
  {&__pyx_n_s_dem_buffer_array, __pyx_k_dem_buffer_array, sizeof(__pyx_k_dem_buffer_array), 0, 0, 1, 1},
  {&__pyx_kp_s_dem_is_not_a_power_of_2_creating, __pyx_k_dem_is_not_a_power_of_2_creating, sizeof(__pyx_k_dem_is_not_a_power_of_2_creating), 0, 0, 1, 0},
  {&__pyx_n_s_dem_managed_raster, __pyx_k_dem_managed_raster, sizeof(__pyx_k_dem_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_dem_nodata, __pyx_k_dem_nodata, sizeof(__pyx_k_dem_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_dem_raster, __pyx_k_dem_raster, sizeof(__pyx_k_dem_raster), 0, 0, 1, 1},
  {&__pyx_n_s_dem_raster_info, __pyx_k_dem_raster_info, sizeof(__pyx_k_dem_raster_info), 0, 0, 1, 1},
  {&__pyx_n_s_dem_raster_path_band, __pyx_k_dem_raster_path_band, sizeof(__pyx_k_dem_raster_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_diagonal_nodata, __pyx_k_diagonal_nodata, sizeof(__pyx_k_diagonal_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_dir, __pyx_k_dir, sizeof(__pyx_k_dir), 0, 0, 1, 1},
  {&__pyx_n_s_direction_drain_queue, __pyx_k_direction_drain_queue, sizeof(__pyx_k_direction_drain_queue), 0, 0, 1, 1},
  {&__pyx_n_s_distance_drain_queue, __pyx_k_distance_drain_queue, sizeof(__pyx_k_distance_drain_queue), 0, 0, 1, 1},
  {&__pyx_n_s_distance_nodata, __pyx_k_distance_nodata, sizeof(__pyx_k_distance_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_distance_to_channel_d8, __pyx_k_distance_to_channel_d8, sizeof(__pyx_k_distance_to_channel_d8), 0, 0, 1, 1},
  {&__pyx_n_s_distance_to_channel_managed_rast, __pyx_k_distance_to_channel_managed_rast, sizeof(__pyx_k_distance_to_channel_managed_rast), 0, 0, 1, 1},
  {&__pyx_n_s_distance_to_channel_mfd, __pyx_k_distance_to_channel_mfd, sizeof(__pyx_k_distance_to_channel_mfd), 0, 0, 1, 1},
  {&__pyx_n_s_distance_to_channel_stack, __pyx_k_distance_to_channel_stack, sizeof(__pyx_k_distance_to_channel_stack), 0, 0, 1, 1},
  {&__pyx_n_s_double, __pyx_k_double, sizeof(__pyx_k_double), 0, 0, 1, 1},
  {&__pyx_n_s_downhill_drain, __pyx_k_downhill_drain, sizeof(__pyx_k_downhill_drain), 0, 0, 1, 1},
  {&__pyx_n_s_downhill_neighbor, __pyx_k_downhill_neighbor, sizeof(__pyx_k_downhill_neighbor), 0, 0, 1, 1},
  {&__pyx_n_s_downhill_slope_array, __pyx_k_downhill_slope_array, sizeof(__pyx_k_downhill_slope_array), 0, 0, 1, 1},
  {&__pyx_n_s_drain_distance, __pyx_k_drain_distance, sizeof(__pyx_k_drain_distance), 0, 0, 1, 1},
  {&__pyx_n_s_drain_queue, __pyx_k_drain_queue, sizeof(__pyx_k_drain_queue), 0, 0, 1, 1},
  {&__pyx_n_s_drain_search_queue, __pyx_k_drain_search_queue, sizeof(__pyx_k_drain_search_queue), 0, 0, 1, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1},
  {&__pyx_n_s_extract_streams_mfd, __pyx_k_extract_streams_mfd, sizeof(__pyx_k_extract_streams_mfd), 0, 0, 1, 1},
  {&__pyx_n_s_feature_id, __pyx_k_feature_id, sizeof(__pyx_k_feature_id), 0, 0, 1, 1},
  {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1},
  {&__pyx_n_s_fill_height, __pyx_k_fill_height, sizeof(__pyx_k_fill_height), 0, 0, 1, 1},
  {&__pyx_n_s_fill_pits, __pyx_k_fill_pits, sizeof(__pyx_k_fill_pits), 0, 0, 1, 1},
  {&__pyx_kp_s_fill_pits__s, __pyx_k_fill_pits__s, sizeof(__pyx_k_fill_pits__s), 0, 0, 1, 0},
  {&__pyx_n_s_fill_queue, __pyx_k_fill_queue, sizeof(__pyx_k_fill_queue), 0, 0, 1, 1},
  {&__pyx_n_s_fill_value_list, __pyx_k_fill_value_list, sizeof(__pyx_k_fill_value_list), 0, 0, 1, 1},
  {&__pyx_n_s_filled_dem_managed_raster, __pyx_k_filled_dem_managed_raster, sizeof(__pyx_k_filled_dem_managed_raster), 0, 0, 1, 1},
  {&__pyx_kp_s_filter_out_incomplete_divergent, __pyx_k_filter_out_incomplete_divergent, sizeof(__pyx_k_filter_out_incomplete_divergent), 0, 0, 1, 0},
  {&__pyx_n_s_flat_region_mask_managed_raster, __pyx_k_flat_region_mask_managed_raster, sizeof(__pyx_k_flat_region_mask_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_flat_region_mask_path, __pyx_k_flat_region_mask_path, sizeof(__pyx_k_flat_region_mask_path), 0, 0, 1, 1},
  {&__pyx_kp_s_flat_region_mask_tif, __pyx_k_flat_region_mask_tif, sizeof(__pyx_k_flat_region_mask_tif), 0, 0, 1, 0},
  {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accum, __pyx_k_flow_accum, sizeof(__pyx_k_flow_accum), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accum_info, __pyx_k_flow_accum_info, sizeof(__pyx_k_flow_accum_info), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accum_managed_raster, __pyx_k_flow_accum_managed_raster, sizeof(__pyx_k_flow_accum_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accum_mr, __pyx_k_flow_accum_mr, sizeof(__pyx_k_flow_accum_mr), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accum_nodata, __pyx_k_flow_accum_nodata, sizeof(__pyx_k_flow_accum_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accum_raster_path_band, __pyx_k_flow_accum_raster_path_band, sizeof(__pyx_k_flow_accum_raster_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accumulation_d8, __pyx_k_flow_accumulation_d8, sizeof(__pyx_k_flow_accumulation_d8), 0, 0, 1, 1},
  {&__pyx_n_s_flow_accumulation_mfd, __pyx_k_flow_accumulation_mfd, sizeof(__pyx_k_flow_accumulation_mfd), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir, __pyx_k_flow_dir, sizeof(__pyx_k_flow_dir), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_band, __pyx_k_flow_dir_band, sizeof(__pyx_k_flow_dir_band), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_buffer_array, __pyx_k_flow_dir_buffer_array, sizeof(__pyx_k_flow_dir_buffer_array), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_d8, __pyx_k_flow_dir_d8, sizeof(__pyx_k_flow_dir_d8), 0, 0, 1, 1},
  {&__pyx_kp_s_flow_dir_d8__s, __pyx_k_flow_dir_d8__s, sizeof(__pyx_k_flow_dir_d8__s), 0, 0, 1, 0},
  {&__pyx_n_s_flow_dir_d8_managed_raster, __pyx_k_flow_dir_d8_managed_raster, sizeof(__pyx_k_flow_dir_d8_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_d8_raster_path_band, __pyx_k_flow_dir_d8_raster_path_band, sizeof(__pyx_k_flow_dir_d8_raster_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_managed_raster, __pyx_k_flow_dir_managed_raster, sizeof(__pyx_k_flow_dir_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd, __pyx_k_flow_dir_mfd, sizeof(__pyx_k_flow_dir_mfd), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd_band, __pyx_k_flow_dir_mfd_band, sizeof(__pyx_k_flow_dir_mfd_band), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd_buffer_array, __pyx_k_flow_dir_mfd_buffer_array, sizeof(__pyx_k_flow_dir_mfd_buffer_array), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd_managed_raster, __pyx_k_flow_dir_mfd_managed_raster, sizeof(__pyx_k_flow_dir_mfd_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd_mr, __pyx_k_flow_dir_mfd_mr, sizeof(__pyx_k_flow_dir_mfd_mr), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd_path_band, __pyx_k_flow_dir_mfd_path_band, sizeof(__pyx_k_flow_dir_mfd_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd_raster, __pyx_k_flow_dir_mfd_raster, sizeof(__pyx_k_flow_dir_mfd_raster), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_mfd_raster_path_band, __pyx_k_flow_dir_mfd_raster_path_band, sizeof(__pyx_k_flow_dir_mfd_raster_path_band), 0, 0, 1, 1},
  {&__pyx_kp_s_flow_dir_multiple_flow_dir__s, __pyx_k_flow_dir_multiple_flow_dir__s, sizeof(__pyx_k_flow_dir_multiple_flow_dir__s), 0, 0, 1, 0},
  {&__pyx_n_s_flow_dir_nodata, __pyx_k_flow_dir_nodata, sizeof(__pyx_k_flow_dir_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_raster, __pyx_k_flow_dir_raster, sizeof(__pyx_k_flow_dir_raster), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_raster_info, __pyx_k_flow_dir_raster_info, sizeof(__pyx_k_flow_dir_raster_info), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_raster_path_band, __pyx_k_flow_dir_raster_path_band, sizeof(__pyx_k_flow_dir_raster_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_flow_dir_weight, __pyx_k_flow_dir_weight, sizeof(__pyx_k_flow_dir_weight), 0, 0, 1, 1},
  {&__pyx_n_s_flow_pixel, __pyx_k_flow_pixel, sizeof(__pyx_k_flow_pixel), 0, 0, 1, 1},
  {&__pyx_n_s_flow_threshold, __pyx_k_flow_threshold, sizeof(__pyx_k_flow_threshold), 0, 0, 1, 1},
  {&__pyx_n_s_gdal, __pyx_k_gdal, sizeof(__pyx_k_gdal), 0, 0, 1, 1},
  {&__pyx_n_s_generate_read_bounds, __pyx_k_generate_read_bounds, sizeof(__pyx_k_generate_read_bounds), 0, 0, 1, 1},
  {&__pyx_n_s_geotiff_driver, __pyx_k_geotiff_driver, sizeof(__pyx_k_geotiff_driver), 0, 0, 1, 1},
  {&__pyx_n_s_getLogger, __pyx_k_getLogger, sizeof(__pyx_k_getLogger), 0, 0, 1, 1},
  {&__pyx_n_s_get_raster_info, __pyx_k_get_raster_info, sizeof(__pyx_k_get_raster_info), 0, 0, 1, 1},
  {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
  {&__pyx_n_s_gmtime, __pyx_k_gmtime, sizeof(__pyx_k_gmtime), 0, 0, 1, 1},
  {&__pyx_n_s_gtiff_creation_options, __pyx_k_gtiff_creation_options, sizeof(__pyx_k_gtiff_creation_options), 0, 0, 1, 1},
  {&__pyx_n_s_i_n, __pyx_k_i_n, sizeof(__pyx_k_i_n), 0, 0, 1, 1},
  {&__pyx_n_s_i_sn, __pyx_k_i_sn, sizeof(__pyx_k_i_sn), 0, 0, 1, 1},
  {&__pyx_n_s_i_upstream_flow, __pyx_k_i_upstream_flow, sizeof(__pyx_k_i_upstream_flow), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1},
  {&__pyx_n_s_int32, __pyx_k_int32, sizeof(__pyx_k_int32), 0, 0, 1, 1},
  {&__pyx_n_s_int8, __pyx_k_int8, sizeof(__pyx_k_int8), 0, 0, 1, 1},
  {&__pyx_n_s_is_a_channel, __pyx_k_is_a_channel, sizeof(__pyx_k_is_a_channel), 0, 0, 1, 1},
  {&__pyx_n_s_is_outlet, __pyx_k_is_outlet, sizeof(__pyx_k_is_outlet), 0, 0, 1, 1},
  {&__pyx_n_s_is_raster_path_band_formatted, __pyx_k_is_raster_path_band_formatted, sizeof(__pyx_k_is_raster_path_band_formatted), 0, 0, 1, 1},
  {&__pyx_n_s_isfile, __pyx_k_isfile, sizeof(__pyx_k_isfile), 0, 0, 1, 1},
  {&__pyx_n_s_iterblocks, __pyx_k_iterblocks, sizeof(__pyx_k_iterblocks), 0, 0, 1, 1},
  {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1},
  {&__pyx_n_s_largest_block, __pyx_k_largest_block, sizeof(__pyx_k_largest_block), 0, 0, 1, 1},
  {&__pyx_n_s_largest_slope, __pyx_k_largest_slope, sizeof(__pyx_k_largest_slope), 0, 0, 1, 1},
  {&__pyx_n_s_largest_slope_dir, __pyx_k_largest_slope_dir, sizeof(__pyx_k_largest_slope_dir), 0, 0, 1, 1},
  {&__pyx_n_s_last_flow_dir, __pyx_k_last_flow_dir, sizeof(__pyx_k_last_flow_dir), 0, 0, 1, 1},
  {&__pyx_n_s_last_log_time, __pyx_k_last_log_time, sizeof(__pyx_k_last_log_time), 0, 0, 1, 1},
  {&__pyx_n_s_log2, __pyx_k_log2, sizeof(__pyx_k_log2), 0, 0, 1, 1},
  {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_makedirs, __pyx_k_makedirs, sizeof(__pyx_k_makedirs), 0, 0, 1, 1},
  {&__pyx_n_s_mask_nodata, __pyx_k_mask_nodata, sizeof(__pyx_k_mask_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_mkdtemp, __pyx_k_mkdtemp, sizeof(__pyx_k_mkdtemp), 0, 0, 1, 1},
  {&__pyx_n_s_modified_offset_dict, __pyx_k_modified_offset_dict, sizeof(__pyx_k_modified_offset_dict), 0, 0, 1, 1},
  {&__pyx_n_s_n_bands, __pyx_k_n_bands, sizeof(__pyx_k_n_bands), 0, 0, 1, 1},
  {&__pyx_n_s_n_distance, __pyx_k_n_distance, sizeof(__pyx_k_n_distance), 0, 0, 1, 1},
  {&__pyx_n_s_n_drain_distance, __pyx_k_n_drain_distance, sizeof(__pyx_k_n_drain_distance), 0, 0, 1, 1},
  {&__pyx_n_s_n_height, __pyx_k_n_height, sizeof(__pyx_k_n_height), 0, 0, 1, 1},
  {&__pyx_n_s_n_iterations, __pyx_k_n_iterations, sizeof(__pyx_k_n_iterations), 0, 0, 1, 1},
  {&__pyx_n_s_n_slope, __pyx_k_n_slope, sizeof(__pyx_k_n_slope), 0, 0, 1, 1},
  {&__pyx_n_s_n_x_blocks, __pyx_k_n_x_blocks, sizeof(__pyx_k_n_x_blocks), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0},
  {&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0},
  {&__pyx_n_s_new_raster_from_base, __pyx_k_new_raster_from_base, sizeof(__pyx_k_new_raster_from_base), 0, 0, 1, 1},
  {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0},
  {&__pyx_n_s_nodata, __pyx_k_nodata, sizeof(__pyx_k_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_nodata_distance_drain_queue, __pyx_k_nodata_distance_drain_queue, sizeof(__pyx_k_nodata_distance_drain_queue), 0, 0, 1, 1},
  {&__pyx_n_s_nodata_downhill_slope_array, __pyx_k_nodata_downhill_slope_array, sizeof(__pyx_k_nodata_downhill_slope_array), 0, 0, 1, 1},
  {&__pyx_n_s_nodata_drain, __pyx_k_nodata_drain, sizeof(__pyx_k_nodata_drain), 0, 0, 1, 1},
  {&__pyx_n_s_nodata_drain_queue, __pyx_k_nodata_drain_queue, sizeof(__pyx_k_nodata_drain_queue), 0, 0, 1, 1},
  {&__pyx_n_s_nodata_flow_dir_queue, __pyx_k_nodata_flow_dir_queue, sizeof(__pyx_k_nodata_flow_dir_queue), 0, 0, 1, 1},
  {&__pyx_n_s_nodata_neighbor, __pyx_k_nodata_neighbor, sizeof(__pyx_k_nodata_neighbor), 0, 0, 1, 1},
  {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
  {&__pyx_kp_s_numpy_core_multiarray_failed_to, __pyx_k_numpy_core_multiarray_failed_to, sizeof(__pyx_k_numpy_core_multiarray_failed_to), 0, 0, 1, 0},
  {&__pyx_kp_s_numpy_core_umath_failed_to_impor, __pyx_k_numpy_core_umath_failed_to_impor, sizeof(__pyx_k_numpy_core_umath_failed_to_impor), 0, 0, 1, 0},
  {&__pyx_n_s_offset_dict, __pyx_k_offset_dict, sizeof(__pyx_k_offset_dict), 0, 0, 1, 1},
  {&__pyx_n_s_offset_only, __pyx_k_offset_only, sizeof(__pyx_k_offset_only), 0, 0, 1, 1},
  {&__pyx_n_s_open_set, __pyx_k_open_set, sizeof(__pyx_k_open_set), 0, 0, 1, 1},
  {&__pyx_n_s_options, __pyx_k_options, sizeof(__pyx_k_options), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_osgeo, __pyx_k_osgeo, sizeof(__pyx_k_osgeo), 0, 0, 1, 1},
  {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1},
  {&__pyx_n_s_pit_mask_managed_raster, __pyx_k_pit_mask_managed_raster, sizeof(__pyx_k_pit_mask_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_pit_mask_path, __pyx_k_pit_mask_path, sizeof(__pyx_k_pit_mask_path), 0, 0, 1, 1},
  {&__pyx_kp_s_pit_mask_tif, __pyx_k_pit_mask_tif, sizeof(__pyx_k_pit_mask_tif), 0, 0, 1, 0},
  {&__pyx_n_s_pit_queue, __pyx_k_pit_queue, sizeof(__pyx_k_pit_queue), 0, 0, 1, 1},
  {&__pyx_n_s_pixel, __pyx_k_pixel, sizeof(__pyx_k_pixel), 0, 0, 1, 1},
  {&__pyx_n_s_pixel_val, __pyx_k_pixel_val, sizeof(__pyx_k_pixel_val), 0, 0, 1, 1},
  {&__pyx_n_s_plateau_distance_managed_raster, __pyx_k_plateau_distance_managed_raster, sizeof(__pyx_k_plateau_distance_managed_raster), 0, 0, 1, 1},
  {&__pyx_n_s_plateau_distance_nodata, __pyx_k_plateau_distance_nodata, sizeof(__pyx_k_plateau_distance_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_plateau_distance_path, __pyx_k_plateau_distance_path, sizeof(__pyx_k_plateau_distance_path), 0, 0, 1, 1},
  {&__pyx_kp_s_plateau_distance_tif, __pyx_k_plateau_distance_tif, sizeof(__pyx_k_plateau_distance_tif), 0, 0, 1, 0},
  {&__pyx_n_s_plateau_drain_mask_managed_raste, __pyx_k_plateau_drain_mask_managed_raste, sizeof(__pyx_k_plateau_drain_mask_managed_raste), 0, 0, 1, 1},
  {&__pyx_n_s_plateu_drain_mask_path, __pyx_k_plateu_drain_mask_path, sizeof(__pyx_k_plateu_drain_mask_path), 0, 0, 1, 1},
  {&__pyx_kp_s_plateu_drain_mask_tif, __pyx_k_plateu_drain_mask_tif, sizeof(__pyx_k_plateu_drain_mask_tif), 0, 0, 1, 0},
  {&__pyx_n_s_pour_point, __pyx_k_pour_point, sizeof(__pyx_k_pour_point), 0, 0, 1, 1},
  {&__pyx_n_s_preempted, __pyx_k_preempted, sizeof(__pyx_k_preempted), 0, 0, 1, 1},
  {&__pyx_n_s_prefix, __pyx_k_prefix, sizeof(__pyx_k_prefix), 0, 0, 1, 1},
  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1},
  {&__pyx_n_s_priority, __pyx_k_priority, sizeof(__pyx_k_priority), 0, 0, 1, 1},
  {&__pyx_n_s_pygeoprocessing, __pyx_k_pygeoprocessing, sizeof(__pyx_k_pygeoprocessing), 0, 0, 1, 1},
  {&__pyx_n_s_pygeoprocessing_routing_routing, __pyx_k_pygeoprocessing_routing_routing, sizeof(__pyx_k_pygeoprocessing_routing_routing), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_raster_path, __pyx_k_raster_path, sizeof(__pyx_k_raster_path), 0, 0, 1, 1},
  {&__pyx_n_s_raster_path_band, __pyx_k_raster_path_band, sizeof(__pyx_k_raster_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_raster_size, __pyx_k_raster_size, sizeof(__pyx_k_raster_size), 0, 0, 1, 1},
  {&__pyx_n_s_raster_x_size, __pyx_k_raster_x_size, sizeof(__pyx_k_raster_x_size), 0, 0, 1, 1},
  {&__pyx_n_s_raster_y_size, __pyx_k_raster_y_size, sizeof(__pyx_k_raster_y_size), 0, 0, 1, 1},
  {&__pyx_n_s_raw_weight_nodata, __pyx_k_raw_weight_nodata, sizeof(__pyx_k_raw_weight_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
  {&__pyx_n_s_rmtree, __pyx_k_rmtree, sizeof(__pyx_k_rmtree), 0, 0, 1, 1},
  {&__pyx_n_s_root_height, __pyx_k_root_height, sizeof(__pyx_k_root_height), 0, 0, 1, 1},
  {&__pyx_kp_s_s_is_not_a_file, __pyx_k_s_is_not_a_file, sizeof(__pyx_k_s_is_not_a_file), 0, 0, 1, 0},
  {&__pyx_kp_s_s_is_supposed_to_be_a_raster_ba, __pyx_k_s_is_supposed_to_be_a_raster_ba, sizeof(__pyx_k_s_is_supposed_to_be_a_raster_ba), 0, 0, 1, 0},
  {&__pyx_n_s_search_queue, __pyx_k_search_queue, sizeof(__pyx_k_search_queue), 0, 0, 1, 1},
  {&__pyx_n_s_search_stack, __pyx_k_search_stack, sizeof(__pyx_k_search_stack), 0, 0, 1, 1},
  {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
  {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
  {&__pyx_n_s_shutil, __pyx_k_shutil, sizeof(__pyx_k_shutil), 0, 0, 1, 1},
  {&__pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_k_src_pygeoprocessing_routing_rout, sizeof(__pyx_k_src_pygeoprocessing_routing_rout), 0, 0, 1, 0},
  {&__pyx_n_s_stream_array, __pyx_k_stream_array, sizeof(__pyx_k_stream_array), 0, 0, 1, 1},
  {&__pyx_n_s_stream_band, __pyx_k_stream_band, sizeof(__pyx_k_stream_band), 0, 0, 1, 1},
  {&__pyx_n_s_stream_mr, __pyx_k_stream_mr, sizeof(__pyx_k_stream_mr), 0, 0, 1, 1},
  {&__pyx_n_s_stream_nodata, __pyx_k_stream_nodata, sizeof(__pyx_k_stream_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_stream_raster, __pyx_k_stream_raster, sizeof(__pyx_k_stream_raster), 0, 0, 1, 1},
  {&__pyx_n_s_stream_val, __pyx_k_stream_val, sizeof(__pyx_k_stream_val), 0, 0, 1, 1},
  {&__pyx_n_s_strftime, __pyx_k_strftime, sizeof(__pyx_k_strftime), 0, 0, 1, 1},
  {&__pyx_n_s_sum_of_downhill_slopes, __pyx_k_sum_of_downhill_slopes, sizeof(__pyx_k_sum_of_downhill_slopes), 0, 0, 1, 1},
  {&__pyx_n_s_sum_of_flow_weights, __pyx_k_sum_of_flow_weights, sizeof(__pyx_k_sum_of_flow_weights), 0, 0, 1, 1},
  {&__pyx_n_s_sum_of_nodata_slope_weights, __pyx_k_sum_of_nodata_slope_weights, sizeof(__pyx_k_sum_of_nodata_slope_weights), 0, 0, 1, 1},
  {&__pyx_n_s_sum_of_slope_weights, __pyx_k_sum_of_slope_weights, sizeof(__pyx_k_sum_of_slope_weights), 0, 0, 1, 1},
  {&__pyx_n_s_target_dem_band, __pyx_k_target_dem_band, sizeof(__pyx_k_target_dem_band), 0, 0, 1, 1},
  {&__pyx_n_s_target_dem_raster, __pyx_k_target_dem_raster, sizeof(__pyx_k_target_dem_raster), 0, 0, 1, 1},
  {&__pyx_n_s_target_distance_to_channel_raste, __pyx_k_target_distance_to_channel_raste, sizeof(__pyx_k_target_distance_to_channel_raste), 0, 0, 1, 1},
  {&__pyx_n_s_target_filled_dem_raster_path, __pyx_k_target_filled_dem_raster_path, sizeof(__pyx_k_target_filled_dem_raster_path), 0, 0, 1, 1},
  {&__pyx_n_s_target_flow_accum_raster_path, __pyx_k_target_flow_accum_raster_path, sizeof(__pyx_k_target_flow_accum_raster_path), 0, 0, 1, 1},
  {&__pyx_n_s_target_flow_dir_path, __pyx_k_target_flow_dir_path, sizeof(__pyx_k_target_flow_dir_path), 0, 0, 1, 1},
  {&__pyx_n_s_target_offset_dict, __pyx_k_target_offset_dict, sizeof(__pyx_k_target_offset_dict), 0, 0, 1, 1},
  {&__pyx_n_s_target_stream_raster_path, __pyx_k_target_stream_raster_path, sizeof(__pyx_k_target_stream_raster_path), 0, 0, 1, 1},
  {&__pyx_n_s_tempfile, __pyx_k_tempfile, sizeof(__pyx_k_tempfile), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
  {&__pyx_n_s_tmp_flow_dir_nodata, __pyx_k_tmp_flow_dir_nodata, sizeof(__pyx_k_tmp_flow_dir_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_trace_flow_threshold, __pyx_k_trace_flow_threshold, sizeof(__pyx_k_trace_flow_threshold), 0, 0, 1, 1},
  {&__pyx_n_s_trace_threshold_proportion, __pyx_k_trace_threshold_proportion, sizeof(__pyx_k_trace_threshold_proportion), 0, 0, 1, 1},
  {&__pyx_kp_s_trace_threshold_proportion_shoul, __pyx_k_trace_threshold_proportion_shoul, sizeof(__pyx_k_trace_threshold_proportion_shoul), 0, 0, 1, 0},
  {&__pyx_n_s_uint8, __pyx_k_uint8, sizeof(__pyx_k_uint8), 0, 0, 1, 1},
  {&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0},
  {&__pyx_n_s_upstream_flow_accum, __pyx_k_upstream_flow_accum, sizeof(__pyx_k_upstream_flow_accum), 0, 0, 1, 1},
  {&__pyx_n_s_upstream_flow_dir, __pyx_k_upstream_flow_dir, sizeof(__pyx_k_upstream_flow_dir), 0, 0, 1, 1},
  {&__pyx_n_s_upstream_flow_dir_sum, __pyx_k_upstream_flow_dir_sum, sizeof(__pyx_k_upstream_flow_dir_sum), 0, 0, 1, 1},
  {&__pyx_n_s_upstream_flow_weight, __pyx_k_upstream_flow_weight, sizeof(__pyx_k_upstream_flow_weight), 0, 0, 1, 1},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_n_s_warning, __pyx_k_warning, sizeof(__pyx_k_warning), 0, 0, 1, 1},
  {&__pyx_n_s_weight_nodata, __pyx_k_weight_nodata, sizeof(__pyx_k_weight_nodata), 0, 0, 1, 1},
  {&__pyx_n_s_weight_raster, __pyx_k_weight_raster, sizeof(__pyx_k_weight_raster), 0, 0, 1, 1},
  {&__pyx_n_s_weight_raster_path_band, __pyx_k_weight_raster_path_band, sizeof(__pyx_k_weight_raster_path_band), 0, 0, 1, 1},
  {&__pyx_n_s_weight_val, __pyx_k_weight_val, sizeof(__pyx_k_weight_val), 0, 0, 1, 1},
  {&__pyx_n_s_win_xsize, __pyx_k_win_xsize, sizeof(__pyx_k_win_xsize), 0, 0, 1, 1},
  {&__pyx_n_s_win_ysize, __pyx_k_win_ysize, sizeof(__pyx_k_win_ysize), 0, 0, 1, 1},
  {&__pyx_n_s_working_dir, __pyx_k_working_dir, sizeof(__pyx_k_working_dir), 0, 0, 1, 1},
  {&__pyx_n_s_working_dir_path, __pyx_k_working_dir_path, sizeof(__pyx_k_working_dir_path), 0, 0, 1, 1},
  {&__pyx_n_s_working_downhill_slope_array, __pyx_k_working_downhill_slope_array, sizeof(__pyx_k_working_downhill_slope_array), 0, 0, 1, 1},
  {&__pyx_n_s_working_downhill_slope_sum, __pyx_k_working_downhill_slope_sum, sizeof(__pyx_k_working_downhill_slope_sum), 0, 0, 1, 1},
  {&__pyx_n_s_write_mode, __pyx_k_write_mode, sizeof(__pyx_k_write_mode), 0, 0, 1, 1},
  {&__pyx_kp_s_x_out_of_bounds_s, __pyx_k_x_out_of_bounds_s, sizeof(__pyx_k_x_out_of_bounds_s), 0, 0, 1, 0},
  {&__pyx_n_s_xa, __pyx_k_xa, sizeof(__pyx_k_xa), 0, 0, 1, 1},
  {&__pyx_n_s_xb, __pyx_k_xb, sizeof(__pyx_k_xb), 0, 0, 1, 1},
  {&__pyx_n_s_xi, __pyx_k_xi, sizeof(__pyx_k_xi), 0, 0, 1, 1},
  {&__pyx_n_s_xi_bn, __pyx_k_xi_bn, sizeof(__pyx_k_xi_bn), 0, 0, 1, 1},
  {&__pyx_n_s_xi_n, __pyx_k_xi_n, sizeof(__pyx_k_xi_n), 0, 0, 1, 1},
  {&__pyx_n_s_xi_q, __pyx_k_xi_q, sizeof(__pyx_k_xi_q), 0, 0, 1, 1},
  {&__pyx_n_s_xi_root, __pyx_k_xi_root, sizeof(__pyx_k_xi_root), 0, 0, 1, 1},
  {&__pyx_n_s_xi_sn, __pyx_k_xi_sn, sizeof(__pyx_k_xi_sn), 0, 0, 1, 1},
  {&__pyx_n_s_xoff, __pyx_k_xoff, sizeof(__pyx_k_xoff), 0, 0, 1, 1},
  {&__pyx_kp_s_y_out_of_bounds_s, __pyx_k_y_out_of_bounds_s, sizeof(__pyx_k_y_out_of_bounds_s), 0, 0, 1, 0},
  {&__pyx_n_s_ya, __pyx_k_ya, sizeof(__pyx_k_ya), 0, 0, 1, 1},
  {&__pyx_n_s_yb, __pyx_k_yb, sizeof(__pyx_k_yb), 0, 0, 1, 1},
  {&__pyx_n_s_yi, __pyx_k_yi, sizeof(__pyx_k_yi), 0, 0, 1, 1},
  {&__pyx_n_s_yi_bn, __pyx_k_yi_bn, sizeof(__pyx_k_yi_bn), 0, 0, 1, 1},
  {&__pyx_n_s_yi_n, __pyx_k_yi_n, sizeof(__pyx_k_yi_n), 0, 0, 1, 1},
  {&__pyx_n_s_yi_q, __pyx_k_yi_q, sizeof(__pyx_k_yi_q), 0, 0, 1, 1},
  {&__pyx_n_s_yi_root, __pyx_k_yi_root, sizeof(__pyx_k_yi_root), 0, 0, 1, 1},
  {&__pyx_n_s_yi_sn, __pyx_k_yi_sn, sizeof(__pyx_k_yi_sn), 0, 0, 1, 1},
  {&__pyx_n_s_yoff, __pyx_k_yoff, sizeof(__pyx_k_yoff), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 208, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 315, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error)
  __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 609, __pyx_L1_error)
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(2, 810, __pyx_L1_error)
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(2, 1000, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple_)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "pygeoprocessing/routing/routing.pyx":641
 * 
 *     # copy the base DEM to the target and set up for writing
 *     geotiff_driver = gdal.GetDriverByName('GTiff')             # <<<<<<<<<<<<<<
 *     base_dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *     geotiff_driver.CreateCopy(
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_n_s_GTiff); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 641, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "pygeoprocessing/routing/routing.pyx":673
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata             # <<<<<<<<<<<<<<
 * 
 *         # attempt to expand read block by a pixel boundary
 */
  __pyx_slice__5 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__5)) __PYX_ERR(0, 673, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__5);
  __Pyx_GIVEREF(__pyx_slice__5);

  /* "pygeoprocessing/routing/routing.pyx":862
 *     flat_region_mask_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__6 = PyTuple_Pack(2, __pyx_kp_s_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 862, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "pygeoprocessing/routing/routing.pyx":1007
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 */
  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_dem_is_not_a_power_of_2_creating); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 1007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "pygeoprocessing/routing/routing.pyx":1011
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')             # <<<<<<<<<<<<<<
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(
 */
  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_n_s_GTiff); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "pygeoprocessing/routing/routing.pyx":1017
 *             options=gtiff_creation_options)
 *         dem_raster = None
 *         LOGGER.info("compatible dem complete")             # <<<<<<<<<<<<<<
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_compatible_dem_complete); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 1017, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pygeoprocessing/routing/routing.pyx":1048
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata             # <<<<<<<<<<<<<<
 * 
 *         # attempt to expand read block by a pixel boundary
 */
  __pyx_slice__11 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__11)) __PYX_ERR(0, 1048, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__11);
  __Pyx_GIVEREF(__pyx_slice__11);

  /* "pygeoprocessing/routing/routing.pyx":1224
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__12 = PyTuple_Pack(2, __pyx_kp_s_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 1224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "pygeoprocessing/routing/routing.pyx":1364
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 *         flow_dir_buffer_array[:] = flow_dir_nodata             # <<<<<<<<<<<<<<
 * 
 *         # attempt to expand read block by a pixel boundary
 */
  __pyx_slice__14 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__14)) __PYX_ERR(0, 1364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__14);
  __Pyx_GIVEREF(__pyx_slice__14);

  /* "pygeoprocessing/routing/routing.pyx":1445
 *     if weight_raster is not None:
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__15 = PyTuple_Pack(2, __pyx_kp_s_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 1445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "pygeoprocessing/routing/routing.pyx":1624
 *     if (dem_block_xsize & (dem_block_xsize - 1) != 0) or (
 *             dem_block_ysize & (dem_block_ysize - 1) != 0):
 *         LOGGER.warning("dem is not a power of 2, creating a copy that is.")             # <<<<<<<<<<<<<<
 *         compatable_dem_raster_path_band = (
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 */
  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_dem_is_not_a_power_of_2_creating); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 1624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "pygeoprocessing/routing/routing.pyx":1628
 *             os.path.join(working_dir_path, 'compatable_dem.tif'),
 *             dem_raster_path_band[1])
 *         geotiff_driver = gdal.GetDriverByName('GTiff')             # <<<<<<<<<<<<<<
 *         dem_raster = gdal.OpenEx(dem_raster_path_band[0], gdal.OF_RASTER)
 *         geotiff_driver.CreateCopy(
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_n_s_GTiff); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 1628, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "pygeoprocessing/routing/routing.pyx":1634
 *             options=gtiff_creation_options)
 *         dem_raster = None
 *         LOGGER.info("compatible dem complete")             # <<<<<<<<<<<<<<
 *     else:
 *         compatable_dem_raster_path_band = dem_raster_path_band
 */
  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_compatible_dem_complete); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 1634, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "pygeoprocessing/routing/routing.pyx":1666
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.float64)
 *         dem_buffer_array[:] = dem_nodata             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
  __pyx_slice__20 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__20)) __PYX_ERR(0, 1666, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__20);
  __Pyx_GIVEREF(__pyx_slice__20);

  /* "pygeoprocessing/routing/routing.pyx":1936
 *     plateau_distance_managed_raster.close()
 *     shutil.rmtree(working_dir_path)
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__21 = PyTuple_Pack(2, __pyx_kp_s_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 1936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "pygeoprocessing/routing/routing.pyx":2078
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 *         flow_dir_mfd_buffer_array[:] = 0  # 0 means no flow at all             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
  __pyx_slice__23 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__23)) __PYX_ERR(0, 2078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__23);
  __Pyx_GIVEREF(__pyx_slice__23);

  /* "pygeoprocessing/routing/routing.pyx":2177
 *     if weight_raster is not None:
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__24 = PyTuple_Pack(2, __pyx_kp_s_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "pygeoprocessing/routing/routing.pyx":2299
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.uint8)
 *         channel_buffer_array[:] = 0  # 0 means no channel             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
  __pyx_slice__26 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__26)) __PYX_ERR(0, 2299, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__26);
  __Pyx_GIVEREF(__pyx_slice__26);

  /* "pygeoprocessing/routing/routing.pyx":2500
 *             (offset_dict['win_ysize']+2, offset_dict['win_xsize']+2),
 *             dtype=numpy.int32)
 *         channel_buffer_array[:] = 0  # 0 means no channel             # <<<<<<<<<<<<<<
 *         flow_dir_buffer_array[:] = 0  # 0 means no flow
 * 
 */
  __pyx_slice__28 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__28)) __PYX_ERR(0, 2500, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__28);
  __Pyx_GIVEREF(__pyx_slice__28);

  /* "pygeoprocessing/routing/routing.pyx":2501
 *             dtype=numpy.int32)
 *         channel_buffer_array[:] = 0  # 0 means no channel
 *         flow_dir_buffer_array[:] = 0  # 0 means no flow             # <<<<<<<<<<<<<<
 * 
 *         # check if we can widen the border to include real data from the
 */
  __pyx_slice__29 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__29)) __PYX_ERR(0, 2501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__29);
  __Pyx_GIVEREF(__pyx_slice__29);

  /* "pygeoprocessing/routing/routing.pyx":2611
 *     if weight_raster is not None:
 *         weight_raster.close()
 *     LOGGER.info('%.1f%% complete', 100.0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__30 = PyTuple_Pack(2, __pyx_kp_s_1f_complete, __pyx_float_100_0); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "pygeoprocessing/routing/routing.pyx":2795
 * 
 *     stream_mr.close()
 *     LOGGER.info('filter out incomplete divergent streams')             # <<<<<<<<<<<<<<
 *     stream_raster = gdal.OpenEx(
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_filter_out_incomplete_divergent); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 2795, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "pygeoprocessing/routing/routing.pyx":2798
 *     stream_raster = gdal.OpenEx(
 *         target_stream_raster_path, gdal.OF_RASTER | gdal.GA_Update)
 *     stream_band = stream_raster.GetRasterBand(1)             # <<<<<<<<<<<<<<
 *     for block_offsets in pygeoprocessing.iterblocks(
 *                 target_stream_raster_path, offset_only=True):
 */
  __pyx_tuple__33 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 2798, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "pygeoprocessing/routing/routing.pyx":2808
 *     stream_band = None
 *     stream_raster = None
 *     LOGGER.info('100.0% complete')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_100_0_complete); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 2808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":229
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(2, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":233
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(2, 233, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":263
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
  __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(2, 263, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":810
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
  __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(2, 810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":814
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
  __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(2, 814, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":834
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(2, 834, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1000
 *         _import_array()
 *     except Exception:
 *         raise ImportError("numpy.core.multiarray failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_umath() except -1:
 */
  __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_numpy_core_multiarray_failed_to); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(2, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1006
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 * 
 * cdef inline int import_ufunc() except -1:
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(2, 1006, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1012
 *         _import_umath()
 *     except Exception:
 *         raise ImportError("numpy.core.umath failed to import")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_numpy_core_umath_failed_to_impor); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(2, 1012, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "pygeoprocessing/routing/routing.pyx":459
 * 
 * 
 * def _generate_read_bounds(offset_dict, raster_x_size, raster_y_size):             # <<<<<<<<<<<<<<
 *     """Helper function to expand GDAL memory block read bound by 1 pixel.
 * 
 */
  __pyx_tuple__44 = PyTuple_Pack(8, __pyx_n_s_offset_dict, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_target_offset_dict); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);
  __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__44, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_generate_read_bounds, 459, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(0, 459, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":503
 * 
 * 
 * def fill_pits(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_filled_dem_raster_path,
 *         working_dir=None,
 */
  __pyx_tuple__46 = PyTuple_Pack(56, __pyx_n_s_dem_raster_path_band, __pyx_n_s_target_filled_dem_raster_path, __pyx_n_s_working_dir, __pyx_n_s_gtiff_creation_options, __pyx_n_s_dem_buffer_array, __pyx_n_s_win_ysize, __pyx_n_s_win_xsize, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_xi_root, __pyx_n_s_yi_root, __pyx_n_s_i_n, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_q, __pyx_n_s_yi_q, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_downhill_neighbor, __pyx_n_s_nodata_neighbor, __pyx_n_s_downhill_drain, __pyx_n_s_nodata_drain, __pyx_n_s_search_queue, __pyx_n_s_fill_queue, __pyx_n_s_pixel, __pyx_n_s_pit_queue, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_n_x_blocks, __pyx_n_s_center_val, __pyx_n_s_dem_nodata, __pyx_n_s_fill_height, __pyx_n_s_feature_id, __pyx_n_s_last_log_time, __pyx_n_s_dem_raster_info, __pyx_n_s_base_nodata, __pyx_n_s_mask_nodata, __pyx_n_s_working_dir_path, __pyx_n_s_flat_region_mask_path, __pyx_n_s_flat_region_mask_managed_raster, __pyx_n_s_pit_mask_path, __pyx_n_s_pit_mask_managed_raster, __pyx_n_s_geotiff_driver, __pyx_n_s_base_dem_raster, __pyx_n_s_target_dem_raster, __pyx_n_s_target_dem_band, __pyx_n_s_filled_dem_managed_raster, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_modified_offset_dict, __pyx_n_s_n_height, __pyx_n_s_pour_point); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);
  __pyx_codeobj__47 = (PyObject*)__Pyx_PyCode_New(4, 0, 56, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__46, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_fill_pits, 503, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__47)) __PYX_ERR(0, 503, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":865
 * 
 * 
 * def flow_dir_d8(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path,
 *         working_dir=None,
 */
  __pyx_tuple__48 = PyTuple_Pack(58, __pyx_n_s_dem_raster_path_band, __pyx_n_s_target_flow_dir_path, __pyx_n_s_working_dir, __pyx_n_s_gtiff_creation_options, __pyx_n_s_dem_buffer_array, __pyx_n_s_win_ysize, __pyx_n_s_win_xsize, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_xi_root, __pyx_n_s_yi_root, __pyx_n_s_i_n, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_q, __pyx_n_s_yi_q, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_root_height, __pyx_n_s_n_height, __pyx_n_s_dem_nodata, __pyx_n_s_drain_distance, __pyx_n_s_n_drain_distance, __pyx_n_s_diagonal_nodata, __pyx_n_s_search_queue, __pyx_n_s_drain_queue, __pyx_n_s_nodata_drain_queue, __pyx_n_s_nodata_flow_dir_queue, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_last_log_time, __pyx_n_s_dem_raster_info, __pyx_n_s_base_nodata, __pyx_n_s_mask_nodata, __pyx_n_s_working_dir_path, __pyx_n_s_flat_region_mask_path, __pyx_n_s_flat_region_mask_managed_raster, __pyx_n_s_flow_dir_nodata, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_plateau_distance_path, __pyx_n_s_plateau_distance_managed_raster, __pyx_n_s_compatable_dem_raster_path_band, __pyx_n_s_dem_block_xsize, __pyx_n_s_dem_block_ysize, __pyx_n_s_geotiff_driver, __pyx_n_s_dem_raster, __pyx_n_s_dem_managed_raster, __pyx_n_s_dem_band, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_modified_offset_dict, __pyx_n_s_largest_slope_dir, __pyx_n_s_largest_slope, __pyx_n_s_n_slope); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 865, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);
  __pyx_codeobj__49 = (PyObject*)__Pyx_PyCode_New(4, 0, 58, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__48, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_dir_d8, 865, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__49)) __PYX_ERR(0, 865, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1227
 * 
 * 
 * def flow_accumulation_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */
  __pyx_tuple__50 = PyTuple_Pack(44, __pyx_n_s_flow_dir_raster_path_band, __pyx_n_s_target_flow_accum_raster_path, __pyx_n_s_weight_raster_path_band, __pyx_n_s_gtiff_creation_options, __pyx_n_s_flow_dir_buffer_array, __pyx_n_s_win_ysize, __pyx_n_s_win_xsize, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_xi_root, __pyx_n_s_yi_root, __pyx_n_s_i_n, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_flow_dir, __pyx_n_s_upstream_flow_dir, __pyx_n_s_flow_dir_nodata, __pyx_n_s_upstream_flow_accum, __pyx_n_s_weight_val, __pyx_n_s_weight_nodata, __pyx_n_s_search_stack, __pyx_n_s_flow_pixel, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_last_log_time, __pyx_n_s_flow_accum_nodata, __pyx_n_s_flow_accum_managed_raster, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_flow_dir_raster, __pyx_n_s_flow_dir_band, __pyx_n_s_weight_raster, __pyx_n_s_raw_weight_nodata, __pyx_n_s_flow_dir_raster_info, __pyx_n_s_tmp_flow_dir_nodata, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_modified_offset_dict, __pyx_n_s_preempted); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 1227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);
  __pyx_codeobj__51 = (PyObject*)__Pyx_PyCode_New(4, 0, 44, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__50, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_accumulation_d8, 1227, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__51)) __PYX_ERR(0, 1227, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1448
 * 
 * 
 * def flow_dir_mfd(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path, working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 */
  __pyx_tuple__53 = PyTuple_Pack(69, __pyx_n_s_dem_raster_path_band, __pyx_n_s_target_flow_dir_path, __pyx_n_s_working_dir, __pyx_n_s_gtiff_creation_options, __pyx_n_s_dem_buffer_array, __pyx_n_s_win_ysize, __pyx_n_s_win_xsize, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_xi_root, __pyx_n_s_yi_root, __pyx_n_s_i_n, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_q, __pyx_n_s_yi_q, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_root_height, __pyx_n_s_n_height, __pyx_n_s_dem_nodata, __pyx_n_s_n_slope, __pyx_n_s_drain_distance, __pyx_n_s_n_drain_distance, __pyx_n_s_drain_search_queue, __pyx_n_s_downhill_slope_array, __pyx_n_s_nodata_downhill_slope_array, __pyx_n_s_working_downhill_slope_array, __pyx_n_s_sum_of_slope_weights, __pyx_n_s_sum_of_nodata_slope_weights, __pyx_n_s_compressed_integer_slopes, __pyx_n_s_distance_drain_queue, __pyx_n_s_nodata_distance_drain_queue, __pyx_n_s_direction_drain_queue, __pyx_n_s_nodata_flow_dir_queue, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_last_log_time, __pyx_n_s_dem_raster_info, __pyx_n_s_base_nodata, __pyx_n_s_mask_nodata, __pyx_n_s_working_dir_path, __pyx_n_s_flat_region_mask_path, __pyx_n_s_flat_region_mask_managed_raster, __pyx_n_s_flow_dir_nodata, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_plateu_drain_mask_path, __pyx_n_s_plateau_drain_mask_managed_raste, __pyx_n_s_plateau_distance_path, __pyx_n_s_plateau_distance_nodata, __pyx_n_s_plateau_distance_managed_raster, __pyx_n_s_compatable_dem_raster_path_band, __pyx_n_s_dem_block_xsize, __pyx_n_s_dem_block_ysize, __pyx_n_s_geotiff_driver, __pyx_n_s_dem_raster, __pyx_n_s_dem_managed_raster, __pyx_n_s_dem_band, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_modified_offset_dict, __pyx_n_s_sum_of_downhill_slopes, __pyx_n_s_working_downhill_slope_sum, __pyx_n_s__52, __pyx_n_s_n_distance); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 1448, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);
  __pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(4, 0, 69, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__53, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_dir_mfd, 1448, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) __PYX_ERR(0, 1448, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":1939
 * 
 * 
 * def flow_accumulation_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */
  __pyx_tuple__55 = PyTuple_Pack(45, __pyx_n_s_flow_dir_mfd_raster_path_band, __pyx_n_s_target_flow_accum_raster_path, __pyx_n_s_weight_raster_path_band, __pyx_n_s_gtiff_creation_options, __pyx_n_s_flow_dir_mfd_buffer_array, __pyx_n_s_win_ysize, __pyx_n_s_win_xsize, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_xi_root, __pyx_n_s_yi_root, __pyx_n_s_i_n, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_i_upstream_flow, __pyx_n_s_flow_dir_mfd, __pyx_n_s_upstream_flow_weight, __pyx_n_s_compressed_upstream_flow_dir, __pyx_n_s_upstream_flow_dir_sum, __pyx_n_s_upstream_flow_accum, __pyx_n_s_flow_accum_nodata, __pyx_n_s_weight_nodata, __pyx_n_s_weight_val, __pyx_n_s_search_stack, __pyx_n_s_flow_pixel, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_last_log_time, __pyx_n_s_flow_accum_managed_raster, __pyx_n_s_flow_dir_managed_raster, __pyx_n_s_flow_dir_raster, __pyx_n_s_flow_dir_band, __pyx_n_s_weight_raster, __pyx_n_s_raw_weight_nodata, __pyx_n_s_flow_dir_raster_info, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_modified_offset_dict, __pyx_n_s_preempted); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 1939, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);
  __pyx_codeobj__56 = (PyObject*)__Pyx_PyCode_New(4, 0, 45, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__55, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_flow_accumulation_mfd, 1939, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__56)) __PYX_ERR(0, 1939, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2180
 * 
 * 
 * def distance_to_channel_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path,
 */
  __pyx_tuple__57 = PyTuple_Pack(41, __pyx_n_s_flow_dir_d8_raster_path_band, __pyx_n_s_channel_raster_path_band, __pyx_n_s_target_distance_to_channel_raste, __pyx_n_s_weight_raster_path_band, __pyx_n_s_gtiff_creation_options, __pyx_n_s_channel_buffer_array, __pyx_n_s_win_ysize, __pyx_n_s_win_xsize, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_i_n, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_q, __pyx_n_s_yi_q, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_distance_to_channel_stack, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_weight_val, __pyx_n_s_pixel_val, __pyx_n_s_weight_nodata, __pyx_n_s_last_log_time, __pyx_n_s_path, __pyx_n_s_distance_nodata, __pyx_n_s_distance_to_channel_managed_rast, __pyx_n_s_weight_raster, __pyx_n_s_raw_weight_nodata, __pyx_n_s_channel_managed_raster, __pyx_n_s_flow_dir_d8_managed_raster, __pyx_n_s_channel_raster, __pyx_n_s_channel_band, __pyx_n_s_flow_dir_raster_info, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_modified_offset_dict); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);
  __pyx_codeobj__58 = (PyObject*)__Pyx_PyCode_New(5, 0, 41, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_distance_to_channel_d8, 2180, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__58)) __PYX_ERR(0, 2180, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2369
 * 
 * 
 * def distance_to_channel_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path, weight_raster_path_band=None,
 */
  __pyx_tuple__59 = PyTuple_Pack(50, __pyx_n_s_flow_dir_mfd_raster_path_band, __pyx_n_s_channel_raster_path_band, __pyx_n_s_target_distance_to_channel_raste, __pyx_n_s_weight_raster_path_band, __pyx_n_s_gtiff_creation_options, __pyx_n_s_channel_buffer_array, __pyx_n_s_flow_dir_buffer_array, __pyx_n_s_win_ysize, __pyx_n_s_win_xsize, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_i_n, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_flow_dir_weight, __pyx_n_s_sum_of_flow_weights, __pyx_n_s_compressed_flow_dir, __pyx_n_s_is_a_channel, __pyx_n_s_distance_to_channel_stack, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_weight_val, __pyx_n_s_weight_nodata, __pyx_n_s_last_log_time, __pyx_n_s_path, __pyx_n_s_distance_nodata, __pyx_n_s_distance_to_channel_managed_rast, __pyx_n_s_channel_managed_raster, __pyx_n_s_flow_dir_mfd_managed_raster, __pyx_n_s_channel_raster, __pyx_n_s_channel_band, __pyx_n_s_flow_dir_mfd_raster, __pyx_n_s_flow_dir_mfd_band, __pyx_n_s_weight_raster, __pyx_n_s_raw_weight_nodata, __pyx_n_s_flow_dir_raster_info, __pyx_n_s_offset_dict, __pyx_n_s_current_pixel, __pyx_n_s_xa, __pyx_n_s_xb, __pyx_n_s_ya, __pyx_n_s_yb, __pyx_n_s_modified_offset_dict, __pyx_n_s_xi_root, __pyx_n_s_yi_root, __pyx_n_s_pixel, __pyx_n_s_preempted, __pyx_n_s_n_distance); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 2369, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);
  __pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(5, 0, 50, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_distance_to_channel_mfd, 2369, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) __PYX_ERR(0, 2369, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2614
 * 
 * 
 * def extract_streams_mfd(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band, flow_dir_mfd_path_band, double flow_threshold,
 *         target_stream_raster_path, double trace_threshold_proportion=1.0,
 */
  __pyx_tuple__61 = PyTuple_Pack(45, __pyx_n_s_flow_accum_raster_path_band, __pyx_n_s_flow_dir_mfd_path_band, __pyx_n_s_flow_threshold, __pyx_n_s_target_stream_raster_path, __pyx_n_s_trace_threshold_proportion, __pyx_n_s_gtiff_creation_options, __pyx_n_s_flow_accum_info, __pyx_n_s_flow_accum_nodata, __pyx_n_s_stream_nodata, __pyx_n_s_raster_x_size, __pyx_n_s_raster_y_size, __pyx_n_s_flow_accum_mr, __pyx_n_s_stream_mr, __pyx_n_s_flow_dir_mfd_mr, __pyx_n_s_xoff, __pyx_n_s_yoff, __pyx_n_s_win_xsize, __pyx_n_s_win_ysize, __pyx_n_s_xi, __pyx_n_s_yi, __pyx_n_s_xi_root, __pyx_n_s_yi_root, __pyx_n_s_i_n, __pyx_n_s_xi_n, __pyx_n_s_yi_n, __pyx_n_s_i_sn, __pyx_n_s_xi_sn, __pyx_n_s_yi_sn, __pyx_n_s_flow_dir_mfd, __pyx_n_s_flow_accum, __pyx_n_s_trace_flow_threshold, __pyx_n_s_n_iterations, __pyx_n_s_is_outlet, __pyx_n_s_stream_val, __pyx_n_s_flow_dir_nodata, __pyx_n_s_open_set, __pyx_n_s_backtrace_set, __pyx_n_s_xi_bn, __pyx_n_s_yi_bn, __pyx_n_s_last_log_time, __pyx_n_s_block_offsets, __pyx_n_s_current_pixel, __pyx_n_s_stream_raster, __pyx_n_s_stream_band, __pyx_n_s_stream_array); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 2614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);
  __pyx_codeobj__62 = (PyObject*)__Pyx_PyCode_New(6, 0, 45, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_extract_streams_mfd, 2614, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__62)) __PYX_ERR(0, 2614, __pyx_L1_error)

  /* "pygeoprocessing/routing/routing.pyx":2811
 * 
 * 
 * def _is_raster_path_band_formatted(raster_path_band):             # <<<<<<<<<<<<<<
 *     """Return true if raster path band is a (str, int) tuple/list."""
 *     if not isinstance(raster_path_band, (list, tuple)):
 */
  __pyx_tuple__63 = PyTuple_Pack(1, __pyx_n_s_raster_path_band); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 2811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);
  __pyx_codeobj__64 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_pygeoprocessing_routing_rout, __pyx_n_s_is_raster_path_band_formatted, 2811, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__64)) __PYX_ERR(0, 2811, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_float_100_0 = PyFloat_FromDouble(100.0); if (unlikely(!__pyx_float_100_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_modinit_global_init_code(void); /*proto*/
static int __Pyx_modinit_variable_export_code(void); /*proto*/
static int __Pyx_modinit_function_export_code(void); /*proto*/
static int __Pyx_modinit_type_init_code(void); /*proto*/
static int __Pyx_modinit_type_import_code(void); /*proto*/
static int __Pyx_modinit_variable_import_code(void); /*proto*/
static int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __pyx_vtabptr_15pygeoprocessing_7routing_7routing__ManagedRaster = &__pyx_vtable_15pygeoprocessing_7routing_7routing__ManagedRaster;
  __pyx_vtable_15pygeoprocessing_7routing_7routing__ManagedRaster.set = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int, double))__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_set;
  __pyx_vtable_15pygeoprocessing_7routing_7routing__ManagedRaster.get = (double (*)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int, int))__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster_get;
  __pyx_vtable_15pygeoprocessing_7routing_7routing__ManagedRaster._load_block = (void (*)(struct __pyx_obj_15pygeoprocessing_7routing_7routing__ManagedRaster *, int))__pyx_f_15pygeoprocessing_7routing_7routing_14_ManagedRaster__load_block;
  if (PyType_Ready(&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 159, __pyx_L1_error)
  __pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster.tp_print = 0;
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster.tp_dictoffset && __pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster.tp_dict, __pyx_vtabptr_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 159, __pyx_L1_error)
  if (PyObject_SetAttrString(__pyx_m, "_ManagedRaster", (PyObject *)&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 159, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster) < 0) __PYX_ERR(0, 159, __pyx_L1_error)
  __pyx_ptype_15pygeoprocessing_7routing_7routing__ManagedRaster = &__pyx_type_15pygeoprocessing_7routing_7routing__ManagedRaster;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(3, 9, __pyx_L1_error)
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) __PYX_ERR(2, 164, __pyx_L1_error)
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) __PYX_ERR(2, 186, __pyx_L1_error)
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) __PYX_ERR(2, 190, __pyx_L1_error)
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) __PYX_ERR(2, 199, __pyx_L1_error)
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) __PYX_ERR(2, 872, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}


#if PY_MAJOR_VERSION < 3
#ifdef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC void
#else
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#endif
#else
#ifdef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#endif
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
    #define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initrouting(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initrouting(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_routing(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_routing(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        result = PyDict_SetItemString(moddict, to_name, value);
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static int __pyx_pymod_exec_routing(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  static int __pyx_t_4[16];
  static int __pyx_t_5[8];
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0;
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  #if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
  PyErr_Clear();
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  if (!__Pyx_RefNanny)
      Py_FatalError("failed to import 'refnanny' module");
}
#endif
  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_routing(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("routing", __pyx_methods, __pyx_k_Provides_PyGeprocessing_Routing, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_pygeoprocessing__routing__routing) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "pygeoprocessing.routing.routing")) {
      if (unlikely(PyDict_SetItemString(modules, "pygeoprocessing.routing.routing", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  (void)__Pyx_modinit_function_export_code();
  if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error;
  if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
  (void)__Pyx_modinit_variable_import_code();
  (void)__Pyx_modinit_function_import_code();
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "pygeoprocessing/routing/routing.pyx":18
 *      567
 * """
 * import time             # <<<<<<<<<<<<<<
 * import os
 * import logging
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":19
 * """
 * import time
 * import os             # <<<<<<<<<<<<<<
 * import logging
 * import shutil
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":20
 * import time
 * import os
 * import logging             # <<<<<<<<<<<<<<
 * import shutil
 * import tempfile
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":21
 * import os
 * import logging
 * import shutil             # <<<<<<<<<<<<<<
 * import tempfile
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_shutil, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_shutil, __pyx_t_1) < 0) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":22
 * import logging
 * import shutil
 * import tempfile             # <<<<<<<<<<<<<<
 * 
 * import numpy
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_tempfile, __pyx_t_1) < 0) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":24
 * import tempfile
 * 
 * import numpy             # <<<<<<<<<<<<<<
 * import pygeoprocessing
 * from osgeo import gdal
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_1) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":25
 * 
 * import numpy
 * import pygeoprocessing             # <<<<<<<<<<<<<<
 * from osgeo import gdal
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_pygeoprocessing, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pygeoprocessing, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":26
 * import numpy
 * import pygeoprocessing
 * from osgeo import gdal             # <<<<<<<<<<<<<<
 * 
 * cimport numpy
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_gdal);
  __Pyx_GIVEREF(__pyx_n_s_gdal);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_gdal);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_osgeo, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_gdal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_gdal, __pyx_t_1) < 0) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pygeoprocessing/routing/routing.pyx":42
 * from libcpp.set cimport set as cset
 * 
 * LOGGER = logging.getLogger(__name__)             # <<<<<<<<<<<<<<
 * LOGGER.addHandler(logging.NullHandler())  # silence logging by default
 * 
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_logging); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_getLogger); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_LOGGER, __pyx_t_3) < 0) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pygeoprocessing/routing/routing.pyx":43
 * 
 * LOGGER = logging.getLogger(__name__)
 * LOGGER.addHandler(logging.NullHandler())  # silence logging by default             # <<<<<<<<<<<<<<
 * 
 * # This module creates rasters with a memory xy block size of 2**BLOCK_BITS
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_LOGGER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_addHandler); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_logging); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_NullHandler); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":46
 * 
 * # This module creates rasters with a memory xy block size of 2**BLOCK_BITS
 * cdef int BLOCK_BITS = 8             # <<<<<<<<<<<<<<
 * 
 * # Number of raster blocks to hold in memory at once per Managed Raster
 */
  __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS = 8;

  /* "pygeoprocessing/routing/routing.pyx":49
 * 
 * # Number of raster blocks to hold in memory at once per Managed Raster
 * cdef int MANAGED_RASTER_N_BLOCKS = 2**6             # <<<<<<<<<<<<<<
 * 
 * # these are the creation options that'll be used for all the rasters
 */
  __pyx_v_15pygeoprocessing_7routing_7routing_MANAGED_RASTER_N_BLOCKS = 64;

  /* "pygeoprocessing/routing/routing.pyx":54
 * DEFAULT_GTIFF_CREATION_OPTIONS = (
 *     'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW',
 *     'BLOCKXSIZE=%d' % (1 << BLOCK_BITS),             # <<<<<<<<<<<<<<
 *     'BLOCKYSIZE=%d' % (1 << BLOCK_BITS))
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_BLOCKXSIZE_d, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":55
 *     'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW',
 *     'BLOCKXSIZE=%d' % (1 << BLOCK_BITS),
 *     'BLOCKYSIZE=%d' % (1 << BLOCK_BITS))             # <<<<<<<<<<<<<<
 * 
 * # if nodata is not defined for a float, it's a difficult choice. this number
 */
  __pyx_t_1 = __Pyx_PyInt_From_long((1 << __pyx_v_15pygeoprocessing_7routing_7routing_BLOCK_BITS)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_BLOCKYSIZE_d, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":53
 * # these are the creation options that'll be used for all the rasters
 * DEFAULT_GTIFF_CREATION_OPTIONS = (
 *     'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW',             # <<<<<<<<<<<<<<
 *     'BLOCKXSIZE=%d' % (1 << BLOCK_BITS),
 *     'BLOCKYSIZE=%d' % (1 << BLOCK_BITS))
 */
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_kp_s_TILED_YES);
  __Pyx_GIVEREF(__pyx_kp_s_TILED_YES);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s_TILED_YES);
  __Pyx_INCREF(__pyx_kp_s_BIGTIFF_YES);
  __Pyx_GIVEREF(__pyx_kp_s_BIGTIFF_YES);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_s_BIGTIFF_YES);
  __Pyx_INCREF(__pyx_kp_s_COMPRESS_LZW);
  __Pyx_GIVEREF(__pyx_kp_s_COMPRESS_LZW);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_s_COMPRESS_LZW);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_2);
  __pyx_t_3 = 0;
  __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS, __pyx_t_1) < 0) __PYX_ERR(0, 52, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":59
 * # if nodata is not defined for a float, it's a difficult choice. this number
 * # probably won't collide with anything ever created by humans
 * cdef double IMPROBABLE_FLOAT_NODATA = -1.23789789e29             # <<<<<<<<<<<<<<
 * 
 * # a pre-computed square root of 2 constant
 */
  __pyx_v_15pygeoprocessing_7routing_7routing_IMPROBABLE_FLOAT_NODATA = -1.23789789e29;

  /* "pygeoprocessing/routing/routing.pyx":62
 * 
 * # a pre-computed square root of 2 constant
 * cdef double SQRT2 = 1.4142135623730951             # <<<<<<<<<<<<<<
 * cdef double SQRT2_INV = 1.0 / 1.4142135623730951
 * 
 */
  __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2 = 1.4142135623730951;

  /* "pygeoprocessing/routing/routing.pyx":63
 * # a pre-computed square root of 2 constant
 * cdef double SQRT2 = 1.4142135623730951
 * cdef double SQRT2_INV = 1.0 / 1.4142135623730951             # <<<<<<<<<<<<<<
 * 
 * # used to loop over neighbors and offset the x/y values as defined below
 */
  __pyx_v_15pygeoprocessing_7routing_7routing_SQRT2_INV = (1.0 / 1.4142135623730951);

  /* "pygeoprocessing/routing/routing.pyx":69
 * #  4x0
 * #  567
 * cdef int* NEIGHBOR_OFFSET_ARRAY = [             # <<<<<<<<<<<<<<
 *     1, 0,  # 0
 *     1, -1,  # 1
 */
  __pyx_t_4[0] = 1;
  __pyx_t_4[1] = 0;
  __pyx_t_4[2] = 1;
  __pyx_t_4[3] = -1;
  __pyx_t_4[4] = 0;
  __pyx_t_4[5] = -1;
  __pyx_t_4[6] = -1;
  __pyx_t_4[7] = -1;
  __pyx_t_4[8] = -1;
  __pyx_t_4[9] = 0;
  __pyx_t_4[10] = -1;
  __pyx_t_4[11] = 1;
  __pyx_t_4[12] = 0;
  __pyx_t_4[13] = 1;
  __pyx_t_4[14] = 1;
  __pyx_t_4[15] = 1;
  __pyx_v_15pygeoprocessing_7routing_7routing_NEIGHBOR_OFFSET_ARRAY = __pyx_t_4;

  /* "pygeoprocessing/routing/routing.pyx":82
 * # this is used to calculate the opposite D8 direction interpreting the index
 * # as a D8 direction
 * cdef int* D8_REVERSE_DIRECTION = [4, 5, 6, 7, 0, 1, 2, 3]             # <<<<<<<<<<<<<<
 * 
 * # exposing stl::priority_queue so we can have all 3 template arguments so
 */
  __pyx_t_5[0] = 4;
  __pyx_t_5[1] = 5;
  __pyx_t_5[2] = 6;
  __pyx_t_5[3] = 7;
  __pyx_t_5[4] = 0;
  __pyx_t_5[5] = 1;
  __pyx_t_5[6] = 2;
  __pyx_t_5[7] = 3;
  __pyx_v_15pygeoprocessing_7routing_7routing_D8_REVERSE_DIRECTION = __pyx_t_5;

  /* "pygeoprocessing/routing/routing.pyx":459
 * 
 * 
 * def _generate_read_bounds(offset_dict, raster_x_size, raster_y_size):             # <<<<<<<<<<<<<<
 *     """Helper function to expand GDAL memory block read bound by 1 pixel.
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_1_generate_read_bounds, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 459, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_generate_read_bounds, __pyx_t_1) < 0) __PYX_ERR(0, 459, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":506
 *         dem_raster_path_band, target_filled_dem_raster_path,
 *         working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """Fill the pits in a DEM.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__3 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":503
 * 
 * 
 * def fill_pits(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_filled_dem_raster_path,
 *         working_dir=None,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_3fill_pits, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fill_pits, __pyx_t_1) < 0) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":868
 *         dem_raster_path_band, target_flow_dir_path,
 *         working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """D8 flow direction.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 868, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__7 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":865
 * 
 * 
 * def flow_dir_d8(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path,
 *         working_dir=None,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_5flow_dir_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 865, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_dir_d8, __pyx_t_1) < 0) __PYX_ERR(0, 865, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1230
 *         flow_dir_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """D8 flow accumulation.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1230, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__13 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1227
 * 
 * 
 * def flow_accumulation_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_7flow_accumulation_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_accumulation_d8, __pyx_t_1) < 0) __PYX_ERR(0, 1227, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1450
 * def flow_dir_mfd(
 *         dem_raster_path_band, target_flow_dir_path, working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """Multiple flow direction.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__16 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1448
 * 
 * 
 * def flow_dir_mfd(             # <<<<<<<<<<<<<<
 *         dem_raster_path_band, target_flow_dir_path, working_dir=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_9flow_dir_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1448, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_dir_mfd, __pyx_t_1) < 0) __PYX_ERR(0, 1448, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1942
 *         flow_dir_mfd_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """Multiple flow direction accumulation.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1942, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__22 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1939
 * 
 * 
 * def flow_accumulation_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, target_flow_accum_raster_path,
 *         weight_raster_path_band=None,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_11flow_accumulation_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1939, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_flow_accumulation_mfd, __pyx_t_1) < 0) __PYX_ERR(0, 1939, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2184
 *         target_distance_to_channel_raster_path,
 *         weight_raster_path_band=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """Calculate distance to channel with D8 flow.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__25 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2180
 * 
 * 
 * def distance_to_channel_d8(             # <<<<<<<<<<<<<<
 *         flow_dir_d8_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_13distance_to_channel_d8, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_to_channel_d8, __pyx_t_1) < 0) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2372
 *         flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path, weight_raster_path_band=None,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """Calculate distance to channel with multiple flow direction.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2372, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__27 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2369
 * 
 * 
 * def distance_to_channel_mfd(             # <<<<<<<<<<<<<<
 *         flow_dir_mfd_raster_path_band, channel_raster_path_band,
 *         target_distance_to_channel_raster_path, weight_raster_path_band=None,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_15distance_to_channel_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2369, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_distance_to_channel_mfd, __pyx_t_1) < 0) __PYX_ERR(0, 2369, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2617
 *         flow_accum_raster_path_band, flow_dir_mfd_path_band, double flow_threshold,
 *         target_stream_raster_path, double trace_threshold_proportion=1.0,
 *         gtiff_creation_options=DEFAULT_GTIFF_CREATION_OPTIONS):             # <<<<<<<<<<<<<<
 *     """Classify a stream raster from MFD flow accumulation.
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DEFAULT_GTIFF_CREATION_OPTIONS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2617, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__31 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2614
 * 
 * 
 * def extract_streams_mfd(             # <<<<<<<<<<<<<<
 *         flow_accum_raster_path_band, flow_dir_mfd_path_band, double flow_threshold,
 *         target_stream_raster_path, double trace_threshold_proportion=1.0,
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_17extract_streams_mfd, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_extract_streams_mfd, __pyx_t_1) < 0) __PYX_ERR(0, 2614, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":2811
 * 
 * 
 * def _is_raster_path_band_formatted(raster_path_band):             # <<<<<<<<<<<<<<
 *     """Return true if raster path band is a (str, int) tuple/list."""
 *     if not isinstance(raster_path_band, (list, tuple)):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15pygeoprocessing_7routing_7routing_19_is_raster_path_band_formatted, NULL, __pyx_n_s_pygeoprocessing_routing_routing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_raster_path_band_formatted, __pyx_t_1) < 0) __PYX_ERR(0, 2811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pygeoprocessing/routing/routing.pyx":1
 * # coding=UTF-8             # <<<<<<<<<<<<<<
 * # distutils: language=c++
 * """
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "../../../../../Python36/lib/site-packages/Cython/Includes/numpy/__init__.pxd":1008
 *         raise ImportError("numpy.core.umath failed to import")
 * 
 * cdef inline int import_ufunc() except -1:             # <<<<<<<<<<<<<<
 *     try:
 *         _import_umath()
 */

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init pygeoprocessing.routing.routing", 0, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pygeoprocessing.routing.routing");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#endif

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* RaiseArgTupleInvalid */
static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* GetModuleGlobalName */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    if (likely(result)) {
        Py_INCREF(result);
    } else if (unlikely(PyErr_Occurred())) {
        result = NULL;
    } else {
#else
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

/* PyCFunctionFastCall */
    #if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs);
    }
}
#endif

/* PyFunctionFastCall */
    #if CYTHON_FAST_PYCALL
#include "frameobject.h"
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = f->f_localsplus;
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* PyObjectCall */
    #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallMethO */
    #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
    #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* DictGetItem */
    #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            PyObject* args = PyTuple_Pack(1, key);
            if (likely(args))
                PyErr_SetObject(PyExc_KeyError, args);
            Py_XDECREF(args);
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* RaiseTooManyValuesToUnpack */
    static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
    static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
    static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
    static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* PyErrFetchRestore */
    #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* RaiseException */
    #if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause) {
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = __Pyx_PyThreadState_Current;
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* None */
    static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* PyObjectCallNoArg */
    #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || __Pyx_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* WriteUnraisableException */
      static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* ExtTypeTest */
      static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(__Pyx_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* IsLittleEndian */
      static CYTHON_INLINE int __Pyx_Is_Little_Endian(void)
{
  union {
    uint32_t u32;
    uint8_t u8[4];
  } S;
  S.u32 = 0x01020304;
  return S.u8[0] == 4;
}

/* BufferFormatCheck */
      static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type) {
  stack[0].field = &ctx->root;
  stack[0].parent_offset = 0;
  ctx->root.type = type;
  ctx->root.name = "buffer dtype";
  ctx->root.offset = 0;
  ctx->head = stack;
  ctx->head->field = &ctx->root;
  ctx->fmt_offset = 0;
  ctx->head->parent_offset = 0;
  ctx->new_packmode = '@';
  ctx->enc_packmode = '@';
  ctx->new_count = 1;
  ctx->enc_count = 0;
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  ctx->is_valid_array = 0;
  ctx->struct_alignment = 0;
  while (type->typegroup == 'S') {
    ++ctx->head;
    ctx->head->field = type->fields;
    ctx->head->parent_offset = 0;
    type = type->fields->type;
  }
}
static int __Pyx_BufFmt_ParseNumber(const char** ts) {
    int count;
    const char* t = *ts;
    if (*t < '0' || *t > '9') {
      return -1;
    } else {
        count = *t++ - '0';
        while (*t >= '0' && *t < '9') {
            count *= 10;
            count += *t++ - '0';
        }
    }
    *ts = t;
    return count;
}
static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
    int number = __Pyx_BufFmt_ParseNumber(ts);
    if (number == -1)
        PyErr_Format(PyExc_ValueError,\
                     "Does not understand character buffer dtype format string ('%c')", **ts);
    return number;
}
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
  PyErr_Format(PyExc_ValueError,
               "Unexpected format string character: '%c'", ch);
}
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
  switch (ch) {
    case 'c': return "'char'";
    case 'b': return "'signed char'";
    case 'B': return "'unsigned char'";
    case 'h': return "'short'";
    case 'H': return "'unsigned short'";
    case 'i': return "'int'";
    case 'I': return "'unsigned int'";
    case 'l': return "'long'";
    case 'L': return "'unsigned long'";
    case 'q': return "'long long'";
    case 'Q': return "'unsigned long long'";
    case 'f': return (is_complex ? "'complex float'" : "'float'");
    case 'd': return (is_complex ? "'complex double'" : "'double'");
    case 'g': return (is_complex ? "'complex long double'" : "'long double'");
    case 'T': return "a struct";
    case 'O': return "Python object";
    case 'P': return "a pointer";
    case 's': case 'p': return "a string";
    case 0: return "end";
    default: return "unparseable format string";
  }
}
static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return 2;
    case 'i': case 'I': case 'l': case 'L': return 4;
    case 'q': case 'Q': return 8;
    case 'f': return (is_complex ? 8 : 4);
    case 'd': return (is_complex ? 16 : 8);
    case 'g': {
      PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g')..");
      return 0;
    }
    case 'O': case 'P': return sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
  switch (ch) {
    case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(short);
    case 'i': case 'I': return sizeof(int);
    case 'l': case 'L': return sizeof(long);
    #ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(PY_LONG_LONG);
    #endif
    case 'f': return sizeof(float) * (is_complex ? 2 : 1);
    case 'd': return sizeof(double) * (is_complex ? 2 : 1);
    case 'g': return sizeof(long double) * (is_complex ? 2 : 1);
    case 'O': case 'P': return sizeof(void*);
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
typedef struct { char c; short x; } __Pyx_st_short;
typedef struct { char c; int x; } __Pyx_st_int;
typedef struct { char c; long x; } __Pyx_st_long;
typedef struct { char c; float x; } __Pyx_st_float;
typedef struct { char c; double x; } __Pyx_st_double;
typedef struct { char c; long double x; } __Pyx_st_longdouble;
typedef struct { char c; void *x; } __Pyx_st_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
/* These are for computing the padding at the end of the struct to align
   on the first member of the struct. This will probably the same as above,
   but we don't have any guarantees.
 */
typedef struct { short x; char c; } __Pyx_pad_short;
typedef struct { int x; char c; } __Pyx_pad_int;
typedef struct { long x; char c; } __Pyx_pad_long;
typedef struct { float x; char c; } __Pyx_pad_float;
typedef struct { double x; char c; } __Pyx_pad_double;
typedef struct { long double x; char c; } __Pyx_pad_longdouble;
typedef struct { void *x; char c; } __Pyx_pad_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_pad_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_pad_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
  switch (ch) {
    case 'c':
        return 'H';
    case 'b': case 'h': case 'i':
    case 'l': case 'q': case 's': case 'p':
        return 'I';
    case 'B': case 'H': case 'I': case 'L': case 'Q':
        return 'U';
    case 'f': case 'd': case 'g':
        return (is_complex ? 'C' : 'R');
    case 'O':
        return 'O';
    case 'P':
        return 'P';
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
  if (ctx->head == NULL || ctx->head->field == &ctx->root) {
    const char* expected;
    const char* quote;
    if (ctx->head == NULL) {
      expected = "end";
      quote = "";
    } else {
      expected = ctx->head->field->type->name;
      quote = "'";
    }
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected %s%s%s but got %s",
                 quote, expected, quote,
                 __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex));
  } else {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_StructField* parent = (ctx->head - 1)->field;
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'",
                 field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex),
                 parent->type->name, field->name);
  }
}
static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
  char group;
  size_t size, offset, arraysize = 1;
  if (ctx->enc_type == 0) return 0;
  if (ctx->head->field->type->arraysize[0]) {
    int i, ndim = 0;
    if (ctx->enc_type == 's' || ctx->enc_type == 'p') {
        ctx->is_valid_array = ctx->head->field->type->ndim == 1;
        ndim = 1;
        if (ctx->enc_count != ctx->head->field->type->arraysize[0]) {
            PyErr_Format(PyExc_ValueError,
                         "Expected a dimension of size %zu, got %zu",
                         ctx->head->field->type->arraysize[0], ctx->enc_count);
            return -1;
        }
    }
    if (!ctx->is_valid_array) {
      PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d",
                   ctx->head->field->type->ndim, ndim);
      return -1;
    }
    for (i = 0; i < ctx->head->field->type->ndim; i++) {
      arraysize *= ctx->head->field->type->arraysize[i];
    }
    ctx->is_valid_array = 0;
    ctx->enc_count = 1;
  }
  group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex);
  do {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_TypeInfo* type = field->type;
    if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') {
      size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex);
    } else {
      size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
    }
    if (ctx->enc_packmode == '@') {
      size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
      size_t align_mod_offset;
      if (align_at == 0) return -1;
      align_mod_offset = ctx->fmt_offset % align_at;
      if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
      if (ctx->struct_alignment == 0)
          ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type,
                                                                 ctx->is_complex);
    }
    if (type->size != size || type->typegroup != group) {
      if (type->typegroup == 'C' && type->fields != NULL) {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        ++ctx->head;
        ctx->head->field = type->fields;
        ctx->head->parent_offset = parent_offset;
        continue;
      }
      if ((type->typegroup == 'H' || group == 'H') && type->size == size) {
      } else {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
      }
    }
    offset = ctx->head->parent_offset + field->offset;
    if (ctx->fmt_offset != offset) {
      PyErr_Format(PyExc_ValueError,
                   "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected",
                   (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
      return -1;
    }
    ctx->fmt_offset += size;
    if (arraysize)
      ctx->fmt_offset += (arraysize - 1) * size;
    --ctx->enc_count;
    while (1) {
      if (field == &ctx->root) {
        ctx->head = NULL;
        if (ctx->enc_count != 0) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
        }
        break;
      }
      ctx->head->field = ++field;
      if (field->type == NULL) {
        --ctx->head;
        field = ctx->head->field;
        continue;
      } else if (field->type->typegroup == 'S') {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        if (field->type->fields->type == NULL) continue;
        field = field->type->fields;
        ++ctx->head;
        ctx->head->field = field;
        ctx->head->parent_offset = parent_offset;
        break;
      } else {
        break;
      }
    }
  } while (ctx->enc_count);
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  return 0;
}
static PyObject *
__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp)
{
    const char *ts = *tsp;
    int i = 0, number;
    int ndim = ctx->head->field->type->ndim;
;
    ++ts;
    if (ctx->new_count != 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Cannot handle repeated arrays in format string");
        return NULL;
    }
    if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
    while (*ts && *ts != ')') {
        switch (*ts) {
            case ' ': case '\f': case '\r': case '\n': case '\t': case '\v':  continue;
            default:  break;
        }
        number = __Pyx_BufFmt_ExpectNumber(&ts);
        if (number == -1) return NULL;
        if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i])
            return PyErr_Format(PyExc_ValueError,
                        "Expected a dimension of size %zu, got %d",
                        ctx->head->field->type->arraysize[i], number);
        if (*ts != ',' && *ts != ')')
            return PyErr_Format(PyExc_ValueError,
                                "Expected a comma in format string, got '%c'", *ts);
        if (*ts == ',') ts++;
        i++;
    }
    if (i != ndim)
        return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d",
                            ctx->head->field->type->ndim, i);
    if (!*ts) {
        PyErr_SetString(PyExc_ValueError,
                        "Unexpected end of format string, expected ')'");
        return NULL;
    }
    ctx->is_valid_array = 1;
    ctx->new_count = 1;
    *tsp = ++ts;
    return Py_None;
}
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) {
  int got_Z = 0;
  while (1) {
    switch(*ts) {
      case 0:
        if (ctx->enc_type != 0 && ctx->head == NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        if (ctx->head != NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        return ts;
      case ' ':
      case '\r':
      case '\n':
        ++ts;
        break;
      case '<':
        if (!__Pyx_Is_Little_Endian()) {
          PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '>':
      case '!':
        if (__Pyx_Is_Little_Endian()) {
          PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '=':
      case '@':
      case '^':
        ctx->new_packmode = *ts++;
        break;
      case 'T':
        {
          const char* ts_after_sub;
          size_t i, struct_count = ctx->new_count;
          size_t struct_alignment = ctx->struct_alignment;
          ctx->new_count = 1;
          ++ts;
          if (*ts != '{') {
            PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'");
            return NULL;
          }
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          ctx->enc_count = 0;
          ctx->struct_alignment = 0;
          ++ts;
          ts_after_sub = ts;
          for (i = 0; i != struct_count; ++i) {
            ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts);
            if (!ts_after_sub) return NULL;
          }
          ts = ts_after_sub;
          if (struct_alignment) ctx->struct_alignment = struct_alignment;
        }
        break;
      case '}':
        {
          size_t alignment = ctx->struct_alignment;
          ++ts;
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          if (alignment && ctx->fmt_offset % alignment) {
            ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment);
          }
        }
        return ts;
      case 'x':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->fmt_offset += ctx->new_count;
        ctx->new_count = 1;
        ctx->enc_count = 0;
        ctx->enc_type = 0;
        ctx->enc_packmode = ctx->new_packmode;
        ++ts;
        break;
      case 'Z':
        got_Z = 1;
        ++ts;
        if (*ts != 'f' && *ts != 'd' && *ts != 'g') {
          __Pyx_BufFmt_RaiseUnexpectedChar('Z');
          return NULL;
        }
        CYTHON_FALLTHROUGH;
      case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
      case 'l': case 'L': case 'q': case 'Q':
      case 'f': case 'd': case 'g':
      case 'O': case 'p':
        if (ctx->enc_type == *ts && got_Z == ctx->is_complex &&
            ctx->enc_packmode == ctx->new_packmode) {
          ctx->enc_count += ctx->new_count;
          ctx->new_count = 1;
          got_Z = 0;
          ++ts;
          break;
        }
        CYTHON_FALLTHROUGH;
      case 's':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->enc_count = ctx->new_count;
        ctx->enc_packmode = ctx->new_packmode;
        ctx->enc_type = *ts;
        ctx->is_complex = got_Z;
        ++ts;
        ctx->new_count = 1;
        got_Z = 0;
        break;
      case ':':
        ++ts;
        while(*ts != ':') ++ts;
        ++ts;
        break;
      case '(':
        if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL;
        break;
      default:
        {
          int number = __Pyx_BufFmt_ExpectNumber(&ts);
          if (number == -1) return NULL;
          ctx->new_count = (size_t)number;
        }
    }
  }
}

/* BufferGetAndValidate */
        static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
  if (unlikely(info->buf == NULL)) return;
  if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
  __Pyx_ReleaseBuffer(info);
}
static void __Pyx_ZeroBuffer(Py_buffer* buf) {
  buf->buf = NULL;
  buf->obj = NULL;
  buf->strides = __Pyx_zeros;
  buf->shape = __Pyx_zeros;
  buf->suboffsets = __Pyx_minusones;
}
static int __Pyx__GetBufferAndValidate(
        Py_buffer* buf, PyObject* obj,  __Pyx_TypeInfo* dtype, int flags,
        int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{
  buf->buf = NULL;
  if (unlikely(__Pyx_GetBuffer(obj, buf, flags) == -1)) {
    __Pyx_ZeroBuffer(buf);
    return -1;
  }
  if (unlikely(buf->ndim != nd)) {
    PyErr_Format(PyExc_ValueError,
                 "Buffer has wrong number of dimensions (expected %d, got %d)",
                 nd, buf->ndim);
    goto fail;
  }
  if (!cast) {
    __Pyx_BufFmt_Context ctx;
    __Pyx_BufFmt_Init(&ctx, stack, dtype);
    if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail;
  }
  if (unlikely((unsigned)buf->itemsize != dtype->size)) {
    PyErr_Format(PyExc_ValueError,
      "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
      buf->itemsize, (buf->itemsize > 1) ? "s" : "",
      dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
    goto fail;
  }
  if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
  return 0;
fail:;
  __Pyx_SafeReleaseBuffer(buf);
  return -1;
}

/* BufferIndexError */
        static void __Pyx_RaiseBufferIndexError(int axis) {
  PyErr_Format(PyExc_IndexError,
     "Out of bounds on buffer access (axis %d)", axis);
}

/* GetItemInt */
        static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* ObjectGetItem */
        #if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
    PyObject *runerr;
    Py_ssize_t key_value;
    PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
    if (unlikely(!(m && m->sq_item))) {
        PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
        return NULL;
    }
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
    PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
    if (likely(m && m->mp_subscript)) {
        return m->mp_subscript(obj, key);
    }
    return __Pyx_PyObject_GetIndex(obj, key);
}
#endif

/* None */
        static CYTHON_INLINE int __Pyx_mod_int(int a, int b) {
    int r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

/* None */
        static CYTHON_INLINE int __Pyx_div_int(int a, int b) {
    int q = a / b;
    int r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* BufferFallbackError */
        static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_SetString(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

/* PyIntBinop */
        #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* PyIntBinop */
        #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* SaveResetException */
        #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    #if PY_VERSION_HEX >= 0x030700A2
    *type = tstate->exc_state.exc_type;
    *value = tstate->exc_state.exc_value;
    *tb = tstate->exc_state.exc_traceback;
    #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    #endif
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if PY_VERSION_HEX >= 0x030700A2
    tmp_type = tstate->exc_state.exc_type;
    tmp_value = tstate->exc_state.exc_value;
    tmp_tb = tstate->exc_state.exc_traceback;
    tstate->exc_state.exc_type = type;
    tstate->exc_state.exc_value = value;
    tstate->exc_state.exc_traceback = tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* PyErrExceptionMatches */
        #if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    if (unlikely(PyTuple_Check(err)))
        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* None */
        static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
    long r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

/* PyIntBinop */
        #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) {
            Py_RETURN_TRUE;
        } else {
            Py_RETURN_FALSE;
        }
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                    CYTHON_FALLTHROUGH;
                #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
                default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ);
                #else
                default: Py_RETURN_FALSE;
                #endif
            }
        }
            if (a == b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            if ((double)a == (double)b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    return PyObject_RichCompare(op1, op2, Py_EQ);
}
#endif

/* RaiseNoneIterError */
        static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* GetException */
        #if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    #if PY_VERSION_HEX >= 0x030700A2
    tmp_type = tstate->exc_state.exc_type;
    tmp_value = tstate->exc_state.exc_value;
    tmp_tb = tstate->exc_state.exc_traceback;
    tstate->exc_state.exc_type = local_type;
    tstate->exc_state.exc_value = local_value;
    tstate->exc_state.exc_traceback = local_tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* PyObject_GenericGetAttrNoDict */
          #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, attr_name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(attr_name));
#endif
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
    PyObject *descr;
    PyTypeObject *tp = Py_TYPE(obj);
    if (unlikely(!PyString_Check(attr_name))) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    assert(!tp->tp_dictoffset);
    descr = _PyType_Lookup(tp, attr_name);
    if (unlikely(!descr)) {
        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
    }
    Py_INCREF(descr);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
    #endif
    {
        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
        if (unlikely(f)) {
            PyObject *res = f(descr, obj, (PyObject *)tp);
            Py_DECREF(descr);
            return res;
        }
    }
    return descr;
}
#endif

/* PyObject_GenericGetAttr */
          #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
}
#endif

/* SetVTable */
          static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

/* SetupReduce */
          static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
  int ret;
  PyObject *name_attr;
  name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name);
  if (likely(name_attr)) {
      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
  } else {
      ret = -1;
  }
  if (unlikely(ret < 0)) {
      PyErr_Clear();
      ret = 0;
  }
  Py_XDECREF(name_attr);
  return ret;
}
static int __Pyx_setup_reduce(PyObject* type_obj) {
    int ret = 0;
    PyObject *object_reduce = NULL;
    PyObject *object_reduce_ex = NULL;
    PyObject *reduce = NULL;
    PyObject *reduce_ex = NULL;
    PyObject *reduce_cython = NULL;
    PyObject *setstate = NULL;
    PyObject *setstate_cython = NULL;
#if CYTHON_USE_PYTYPE_LOOKUP
    if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD;
#else
    if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD;
#endif
#if CYTHON_USE_PYTYPE_LOOKUP
    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD;
#else
    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD;
#endif
    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD;
    if (reduce_ex == object_reduce_ex) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD;
#else
        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD;
#endif
        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD;
        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
            reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD;
            ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD;
            ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD;
            setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
            if (!setstate) PyErr_Clear();
            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
                setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD;
                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD;
                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD;
            }
            PyType_Modified((PyTypeObject*)type_obj);
        }
    }
    goto GOOD;
BAD:
    if (!PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
    ret = -1;
GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP
    Py_XDECREF(object_reduce);
    Py_XDECREF(object_reduce_ex);
#endif
    Py_XDECREF(reduce);
    Py_XDECREF(reduce_ex);
    Py_XDECREF(reduce_cython);
    Py_XDECREF(setstate);
    Py_XDECREF(setstate_cython);
    return ret;
}

/* Import */
          static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
          static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* CLineInTraceback */
          #ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
      use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback);
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (PyObject_Not(use_cline) != 0) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
          static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
          #include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

#if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
    if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
        if (__Pyx_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags);
    PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
    return -1;
}
static void __Pyx_ReleaseBuffer(Py_buffer *view) {
    PyObject *obj = view->obj;
    if (!obj) return;
    if (PyObject_CheckBuffer(obj)) {
        PyBuffer_Release(view);
        return;
    }
    if ((0)) {}
        else if (__Pyx_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) __pyx_pw_5numpy_7ndarray_3__releasebuffer__(obj, view);
    view->obj = NULL;
    Py_DECREF(obj);
}
#endif


          /* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntFromPyVerify */
          #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* Print */
          #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
    int i;
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        PyObject* v;
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                goto error;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            goto error;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0) {
                switch (s[len-1]) {
                    case ' ': break;
                    case '\f': case '\r': case '\n': case '\t': case '\v':
                        PyFile_SoftSpace(f, 0);
                        break;
                    default:  break;
                }
            }
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            goto error;
        PyFile_SoftSpace(f, 0);
    }
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
}
#else
static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (unlikely(!__pyx_print)) {
        __pyx_print = PyObject_GetAttr(__pyx_b, __pyx_n_s_print);
        if (!__pyx_print)
            return -1;
    }
    if (stream) {
        kwargs = PyDict_New();
        if (unlikely(!kwargs))
            return -1;
        if (unlikely(PyDict_SetItem(kwargs, __pyx_n_s_file, stream) < 0))
            goto bad;
        if (!newline) {
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                goto bad;
            if (PyDict_SetItem(kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                goto bad;
            }
            Py_DECREF(end_string);
        }
    } else if (!newline) {
        if (unlikely(!__pyx_print_kwargs)) {
            __pyx_print_kwargs = PyDict_New();
            if (unlikely(!__pyx_print_kwargs))
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                return -1;
            if (PyDict_SetItem(__pyx_print_kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs))
        Py_DECREF(kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
bad:
    if (kwargs != __pyx_print_kwargs)
        Py_XDECREF(kwargs);
    return -1;
}
#endif

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* Declarations */
          #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return ::std::complex< float >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return x + y*(__pyx_t_float_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      __pyx_t_float_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
          #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sum_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_diff_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prod_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabsf(b.real) >= fabsf(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                float r = b.imag / b.real;
                float s = 1.0 / (b.real + b.imag * r);
                return __pyx_t_float_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            float r = b.real / b.imag;
            float s = 1.0 / (b.imag + b.real * r);
            return __pyx_t_float_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quot_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        if (b.imag == 0) {
            return __pyx_t_float_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            float denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_float_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_neg_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_float(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conj_float(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_abs_float(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_pow_float(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(a, a);
                    case 3:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, a);
                    case 4:
                        z = __Pyx_c_prod_float(a, a);
                        return __Pyx_c_prod_float(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                } else if (b.imag == 0) {
                    z.real = powf(a.real, b.real);
                    z.imag = 0;
                    return z;
                } else if (a.real > 0) {
                    r = a.real;
                    theta = 0;
                } else {
                    r = -a.real;
                    theta = atan2f(0, -1);
                }
            } else {
                r = __Pyx_c_abs_float(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

/* Declarations */
          #if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

/* Arithmetic */
          #if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    #if 1
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else if (fabs(b.real) >= fabs(b.imag)) {
            if (b.real == 0 && b.imag == 0) {
                return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.imag);
            } else {
                double r = b.imag / b.real;
                double s = 1.0 / (b.real + b.imag * r);
                return __pyx_t_double_complex_from_parts(
                    (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
            }
        } else {
            double r = b.real / b.imag;
            double s = 1.0 / (b.imag + b.real * r);
            return __pyx_t_double_complex_from_parts(
                (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
        }
    }
    #else
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        if (b.imag == 0) {
            return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
        } else {
            double denom = b.real * b.real + b.imag * b.imag;
            return __pyx_t_double_complex_from_parts(
                (a.real * b.real + a.imag * b.imag) / denom,
                (a.imag * b.real - a.real * b.imag) / denom);
        }
    }
    #endif
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(a, a);
                    case 3:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, a);
                    case 4:
                        z = __Pyx_c_prod_double(a, a);
                        return __Pyx_c_prod_double(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                } else if (b.imag == 0) {
                    z.real = pow(a.real, b.real);
                    z.imag = 0;
                    return z;
                } else if (a.real > 0) {
                    r = a.real;
                    theta = 0;
                } else {
                    r = -a.real;
                    theta = atan2(0, -1);
                }
            } else {
                r = __Pyx_c_abs_double(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

/* CIntToPy */
          static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__NPY_TYPES(enum NPY_TYPES value) {
    const enum NPY_TYPES neg_one = (enum NPY_TYPES) -1, const_zero = (enum NPY_TYPES) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(enum NPY_TYPES) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(enum NPY_TYPES) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(enum NPY_TYPES) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(enum NPY_TYPES),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
          static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* PrintOne */
          #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            goto error;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        goto error;
    if (PyFile_WriteString("\n", f) < 0)
        goto error;
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
    /* the line below is just to avoid C compiler
     * warnings about unused functions */
    return __Pyx_Print(f, NULL, 0);
}
#else
static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_Pack(1, o);
    if (unlikely(!arg_tuple))
        return -1;
    res = __Pyx_Print(stream, arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}
#endif

/* CIntFromPy */
          static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
    const size_t neg_one = (size_t) -1, const_zero = (size_t) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (size_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) {
                            return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) {
                            return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) {
                            return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (size_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(size_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) ((((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            size_t val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to size_t");
    return (size_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to size_t");
    return (size_t) -1;
}

/* CIntFromPy */
          static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* FastTypeChecks */
          #if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = a->tp_base;
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
    if (!res) {
        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
    return res;
}
#endif
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* CheckBinaryVersion */
          static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* ModuleImport */
          #ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

/* TypeImport */
          #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

/* InitStrings */
          static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    char* defenc_c;
    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
    if (!defenc) return NULL;
    defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    {
        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
        char* c;
        for (c = defenc_c; c < end; c++) {
            if ((unsigned char) (*c) >= 128) {
                PyUnicode_AsASCIIString(o);
                return NULL;
            }
        }
    }
#endif
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type %.200s).  "
                "The ability to return an instance of a strict subclass of int "
                "is deprecated, and may be removed in a future version of Python.",
                Py_TYPE(result)->tp_name)) {
            Py_DECREF(result);
            return NULL;
        }
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type %.200s)",
                 type_name, type_name, Py_TYPE(result)->tp_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
